Is there a way to tell what index is used for a GlideRecord query?

David Hubbard
Tera Guru

We have a table with several indexes on it - in some client usage they are seeing slow performance - so, I am wondering if there is a way to tell - either directly from GlideRecord (or Meta) what indexes are used for the query? 

 

I am aware of the "Slow Queries" list,  but don't see any index available there to view.

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@David Hubbard 

no direct way available for this using GlideRecord.

To analyze slow performance

-> check slow queries table

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Bert_c1
Kilo Patron

There is the 'sys_index_suggestion' table, I have no idea what creates records there.

That's interesting - nothing showing in there on my dev system - but can ask client to check this - thanks for the suggestion

 

Rafael Batistot
Kilo Patron

Hi @David Hubbard 

 

Unfortunately, GlideRecord itself doesn’t expose which index was used. It only lets you build and execute queries.

You can check what indexes exist for the table by querying the metadata:

 

var gr = new GlideRecord('sys_db_index');
gr.addQuery('table', 'your_table_name');
gr.query();
while (gr.next()) {
gs.info("Index: " + gr.name + " | Columns: " + gr.columns);
}

But this only shows what indexes exist, not which one was actually chosen by the DB engine for a given query.