Is there a way to tell what index is used for a GlideRecord query?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2025 07:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2025 07:22 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2025 08:12 AM
There is the 'sys_index_suggestion' table, I have no idea what creates records there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2025 08:18 AM
That's interesting - nothing showing in there on my dev system - but can ask client to check this - thanks for the suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2025 08:35 AM
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.
