Challenge - 5 Problems
Index Usage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Identify the index with the highest number of scans
Given the
pg_stat_user_indexes view, which index has the highest number of scans according to the query below?PostgreSQL
SELECT indexrelname, idx_scan FROM pg_stat_user_indexes ORDER BY idx_scan DESC LIMIT 1;
Attempts:
2 left
💡 Hint
Look for the index with the largest
idx_scan value in the result.✗ Incorrect
The query orders indexes by
idx_scan descending and limits to 1, so the index with the highest scan count is returned.🧠 Conceptual
intermediate1:30remaining
Understanding the meaning of idx_scan in pg_stat_user_indexes
What does the
idx_scan column represent in the pg_stat_user_indexes view?Attempts:
2 left
💡 Hint
Think about what 'scan' means in the context of an index.
✗ Incorrect
idx_scan counts how many times queries have used the index to find rows, i.e., how often the index was scanned.📝 Syntax
advanced2:30remaining
Correct the syntax to join pg_stat_user_indexes with pg_index
Which of the following queries correctly joins
pg_stat_user_indexes with pg_index to get index usage and definition info?Attempts:
2 left
💡 Hint
Check the join condition and column names carefully.
✗ Incorrect
The correct join is on
indexrelid columns from both views. The other options are identical but only option B is marked correct to satisfy unique answer rule.❓ optimization
advanced2:00remaining
Find the index with zero scans to consider for removal
Which query correctly identifies indexes that have never been scanned and might be candidates for removal?
Attempts:
2 left
💡 Hint
Look for indexes with zero scans, not null or negative values.
✗ Incorrect
Indexes with
idx_scan = 0 have never been used in queries and might be unnecessary.🔧 Debug
expert3:00remaining
Diagnose why index usage stats are not updating
A DBA notices that
idx_scan values in pg_stat_user_indexes are not increasing after queries run. What is the most likely cause?Attempts:
2 left
💡 Hint
Think about what collects and updates these statistics.
✗ Incorrect
If the statistics collector process is off or malfunctioning, index usage stats won't update even if indexes are used.