GlideAggregate, vs GlideRecord getRowCount, which is faster?

tahnalos
Kilo Sage

Hello.  We are looking to determine counts of a particular criteria of tickets.  Our system currently has 7M tickets, and we are trying to create reports that look at counts of these tickets.  Our typical ideas usually involve GlideRecord coding and using getRowCount, but want to know if GlideAggregate will result in faster performance.

Thanks

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Yes, GlideAggregate will be faster. Suggest you to check link that talks about difference with execution time for both as a difference.

find_real_file.png

So even with only one aggregate value being pulled up, it is still faster than getRowCount?

Yes, gliderecord goes through each and every record to get you the result, whereas glideaggregate are optimized and efficient with these queries
Best Regards
Aman Kumar

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi tahnalos,

I don't know the internal of ServiceNow but I think ServiceNow is using jdbc to connect to the database.

.getRowCount() is probably doing a .getRow() on the resultset. That is, it's getting all the query records into a resultset and counting how many rows there are.

https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html#getRow--

GlideAggregate() is probably doing a "SELECT COUNT" sql query.

https://www.w3schools.com/sql/sql_count_avg_sum.asp

Since .getRow() is executed on the Java application side while SELECT COUNT on the database, SELECT COUNT would be faster. Thus, GlideAggregate() would be faster.