How can you identify which indexes are being used in a query?

You identify which indexes a query uses by asking the database's query optimizer to show its execution plan, typically with the EXPLAIN (or EXPLAIN PLAN) command. The plan reveals the access path chosen for each table, including whether an index scan, index seek, or full table scan is used.

Key Points

Example

Running EXPLAIN on a query filtering by an employee's name shows whether the optimizer used an index on the name column or fell back to scanning the whole table, which immediately tells you if an index needs to be added.

EXPLAIN SELECT * FROM employees WHERE name = 'John';

Interview Tip

A concise interview answer is

I run EXPLAIN, or EXPLAIN ANALYZE for actual runtime numbers, on the query to see the optimizer's execution plan. The plan's key/index column tells me exactly which index was chosen, and a full table scan in the type column tells me none was used, which points me toward adding or fixing an index.

Last updated: 16 July 2026

Previous question: What are indexes in SQL?

Next question: Can you have an index on a view? If yes, how?

More SQL interview questions

All SQL questions