0
0
PostgreSQLquery~20 mins

Analyzing index usage with pg_stat in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Usage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
AIndex 'orders_date_idx' with 2300 scans
BIndex 'users_email_idx' with 1500 scans
CIndex 'products_name_idx' with 1800 scans
DIndex 'customers_id_idx' with 1200 scans
Attempts:
2 left
💡 Hint
Look for the index with the largest idx_scan value in the result.
🧠 Conceptual
intermediate
1: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?
AThe number of rows returned by the index scan
BThe total size of the index in bytes
CThe number of times the index was rebuilt
DThe number of times the index was scanned during query execution
Attempts:
2 left
💡 Hint
Think about what 'scan' means in the context of an index.
📝 Syntax
advanced
2: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?
A;dilerxedni.i = dilerxedni.s NO i xedni_gp NIOJ s sexedni_resu_tats_gp MORF euqinusidni.i ,nacs_xdi.s ,emanlerxedni.s TCELES
BSELECT s.indexrelname, s.idx_scan, i.indisunique FROM pg_stat_user_indexes s JOIN pg_index i ON s.indexrelid = i.indexrelid;
CELECT s.indexrelname, s.idx_scan, i.indisunique FROM pg_stat_user_indexes s JOIN pg_index i ON s.indexrelid = i.indexrelid;
DSELECT s.indexrelname, s.idx_scan, i.indisunique FROM pg_stat_user_indexes s JOIN pg_index i ON s.indexrelid = i.indexrelid
Attempts:
2 left
💡 Hint
Check the join condition and column names carefully.
optimization
advanced
2: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?
ASELECT indexrelname FROM pg_stat_user_indexes WHERE idx_scan = 0;
BSELECT indexrelname FROM pg_stat_user_indexes WHERE idx_scan IS NULL;
CSELECT indexrelname FROM pg_stat_user_indexes WHERE idx_scan > 0;
DSELECT indexrelname FROM pg_stat_user_indexes WHERE idx_scan < 0;
Attempts:
2 left
💡 Hint
Look for indexes with zero scans, not null or negative values.
🔧 Debug
expert
3: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?
AThe queries are not using any indexes
BThe indexes are corrupted and unusable
CThe statistics collector is disabled or not running
DThe database is in read-only mode
Attempts:
2 left
💡 Hint
Think about what collects and updates these statistics.