wrong join for index bloat
mrc-mm opened this issue · comments
Hi, There is (IMO) a2 wrong joins in second block.
should be
JOIN btree_index_atts AS ind_atts ON pg_attribute.attrelid = ind_atts.indrelid AND pg_attribute.attnum = ind_atts.attnum
instead of
JOIN btree_index_atts AS ind_atts ON pg_attribute.attrelid = ind_atts.indexrelid AND pg_attribute.attnum = ind_atts.attnum
the following join, Is aso wrong. I use:
LEFT JOIN pg_stats ON pg_stats.schemaname = ind_atts.nspname
-- stats for regular index columns
AND ( (pg_stats.tablename = ind_atts.tablename AND pg_catalog.pg_get_indexdef(ind_atts.indexrelid, pg_attribute.attnum, TRUE) ~ pg_stats.attname)
-- stats for functional indexes
OR (pg_stats.tablename = ind_atts.index_name AND pg_stats.attname = pg_attribute.attname))