From 41b16cbb28408674ac9e63d252e40b4089fad770 Mon Sep 17 00:00:00 2001 From: derkv Date: Wed, 15 Dec 2021 13:38:49 +0100 Subject: [PATCH] Fix incorrect join condition. We want to join all columns of the index, no matter the column order in the table --- bloat/index_bloat_check.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bloat/index_bloat_check.sql b/bloat/index_bloat_check.sql index ba1e990..bb8540c 100644 --- a/bloat/index_bloat_check.sql +++ b/bloat/index_bloat_check.sql @@ -8,7 +8,6 @@ WITH btree_index_atts AS ( indrelid, indexrelid, indexclass.relam, tableclass.relname as tablename, - regexp_split_to_table(indkey::text, ' ')::smallint AS attnum, indexrelid as index_oid FROM pg_index JOIN pg_class AS indexclass ON pg_index.indexrelid = indexclass.oid @@ -32,7 +31,7 @@ index_item_sizes AS ( END AS index_tuple_hdr, sum( (1-coalesce(pg_stats.null_frac, 0)) * coalesce(pg_stats.avg_width, 1024) ) AS nulldatawidth FROM pg_attribute - JOIN btree_index_atts AS ind_atts ON pg_attribute.attrelid = ind_atts.indexrelid AND pg_attribute.attnum = ind_atts.attnum + JOIN btree_index_atts AS ind_atts ON pg_attribute.attrelid = ind_atts.indexrelid JOIN pg_stats ON pg_stats.schemaname = ind_atts.nspname -- stats for regular index columns AND ( (pg_stats.tablename = ind_atts.tablename AND pg_stats.attname = pg_catalog.pg_get_indexdef(pg_attribute.attrelid, pg_attribute.attnum, TRUE))