Skip to content

Commit

Permalink
Merge pull request #5 from ongres/fixwrostindex
Browse files Browse the repository at this point in the history
adjust query to skip empty tables
  • Loading branch information
DiegoDAF authored Jun 12, 2023
2 parents 0230ac7 + ab43305 commit 58b8118
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sql/Indexes/worst_index_hits.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-- The hit vs read ratio. The closest to 1, the better.


WITH worst_index_hit_ratio AS (
SELECT
relid::regclass as realted_table,
Expand All @@ -10,14 +9,19 @@ WITH worst_index_hit_ratio AS (
CASE WHEN sum(idx_blks_hit) > 0 THEN
round((sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit),1)
ELSE sum(idx_blks_hit)
END as hit_ratio
END as hit_ratio,
pg_relation_size(schemaname || '.' || quote_ident(relname)) table_size,
pg_size_pretty(pg_relation_size(schemaname || '.' || quote_ident(relname)) ) table_size_human
FROM
pg_statio_user_indexes
GROUP BY indexrelname, relid
WHERE pg_relation_size(schemaname || '.' || quote_ident(relname)) > 100000 /* skip small tables */
GROUP BY indexrelname, relid, pg_relation_size(schemaname || '.' || quote_ident(relname)) ,
pg_size_pretty(pg_relation_size(schemaname || '.' || quote_ident(relname)) )
ORDER BY hit_ratio ASC
)
SELECT * FROM worst_index_hit_ratio
WHERE
-- idx_read = 0 and idx_hit = 0; -- < 0.9;
hit_ratio < 0.8;


0 comments on commit 58b8118

Please sign in to comment.