@@ -79,22 +79,22 @@ with unused as (
7979 join pg_stat_user_indexes as s on s .indexrelid = i2 .indexrelid
8080 where
8181 not i1 .indisprimary -- index 1 is not primary
82- and not ( -- skip if index1 is primary or uniq and index2 is primary or unique
82+ and not ( -- skip if index1 is ( primary or uniq) and is NOT ( primary and uniq)
8383 (i1 .indisprimary or i1 .indisunique )
8484 and (not i2 .indisprimary or not i2 .indisunique )
8585 )
8686 and am1 .amname = am2 .amname -- same access type
8787 and (
88- i2 .columns like (i1 .columns || ' %' ) -- index 2 include all columns from index 1
89- or i1 .columns = i2 .columns -- index1 and index 2 include same columns
88+ i2 .columns like (i1 .columns || ' %' ) -- index 2 includes all columns from index 1
89+ or i1 .columns = i2 .columns -- index1 and index 2 includes same columns
9090 )
9191 and (
9292 i2 .opclasses like (i1 .opclasses || ' %' )
9393 or i1 .opclasses = i2 .opclasses
9494 )
95- -- index expressions is same
95+ -- index expressions are same
9696 and pg_get_expr(i1 .indexprs , i1 .indrelid ) is not distinct from pg_get_expr(i2 .indexprs , i2 .indrelid )
97- -- index predicates is same
97+ -- index predicates are same
9898 and pg_get_expr(i1 .indpred , i1 .indrelid ) is not distinct from pg_get_expr(i2 .indpred , i2 .indrelid )
9999), together as (
100100 select reason, table_name, index_name, index_size, index_def, null as main_index_def, indexrelid
@@ -103,12 +103,11 @@ with unused as (
103103 select reason, table_name, index_name, index_size, index_def, main_index_def, indexrelid
104104 from redundant
105105 where index_usage = 0
106- order by table_name asc , index_name
107106), droplines as (
108107 select format(' DROP INDEX CONCURRENTLY %s; -- %s, %s, table %s' , max (index_name), max (index_size), string_agg(reason, ' , ' ), table_name) as line
109108 from together t1
110- group by table_name, indexrelid
111- order by table_name, indexrelid
109+ group by table_name, index_name
110+ order by table_name, index_name
112111), createlines as (
113112 select
114113 replace(
@@ -117,8 +116,8 @@ with unused as (
117116 ' CREATE INDEX CONCURRENTLY'
118117 )as line
119118 from together t2
120- group by table_name, indexrelid
121- order by table_name, indexrelid
119+ group by table_name, index_name
120+ order by table_name, index_name
122121)
123122select ' -- Do migration: --' as run_in_separate_transactions
124123union all
0 commit comments