The CreatorCon Call for Content is officially open! Get started here.

AddQuery vs AddEncodedQuery

Anubhav24
Mega Sage

Hi All,

 

Is there a difference between addquery and addencodedquery. Is there a performance difference between these two considering 2 scenarios : a) When only column value is being matched b)When multiple column values are being matched?

Eventually the query gets converted to "Select *" format right ?

 

11 REPLIES 11

So far zero responses regarding any performance difference.

 

Personally would also not expect so, than that would already be known.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Amit Gujarathi
Giga Sage
Giga Sage

HI @Anubhav24 ,
I trust you are doing great.

Performance Difference:

a) When only column value is being matched: There's no significant performance difference between addQuery and addEncodedQuery when filtering by a single column value. Both methods will generate efficient SQL queries behind the scenes.

b) When multiple column values are being matched: Again, there's no substantial performance difference between the two methods. However, addEncodedQuery might be more concise for complex queries with multiple conditions.

SQL Conversion:

Yes, behind the scenes, ServiceNow translates these GlideRecord queries into SQL queries. For instance, a GlideRecord query on the 'incident' table might be translated to something like:

 

SELECT * FROM incident WHERE priority = 1 AND state = 2;

 

However, it's worth noting that ServiceNow abstracts this SQL layer for security and efficiency reasons, so developers work with the GlideRecord API instead of direct SQL.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi