Skip to content

Commit 3b874bf

Browse files
XofGabrielle Roth
authored andcommitted
Fix bug involving attribute indexes that were prefixes of each other.
1 parent e63a976 commit 3b874bf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

duplicate_indexes/duplicate_indexes.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ SELECT ni.nspname || '.' || ct.relname AS "table",
33
pg_get_indexdef(i.indexrelid) AS "dup index definition",
44
i.indkey AS "dup index attributes",
55
cii.relname AS "encompassing index",
6-
pg_get_indexdef(ii.indexrelid) AS "encompassing index definition"
7-
ii.indkey AS "enc index attributes",
6+
pg_get_indexdef(ii.indexrelid) AS "encompassing index definition",
7+
ii.indkey AS "enc index attributes"
88
FROM pg_index i
99
JOIN pg_class ct ON i.indrelid=ct.oid
1010
JOIN pg_class ci ON i.indexrelid=ci.oid
1111
JOIN pg_namespace ni ON ci.relnamespace=ni.oid
1212
JOIN pg_index ii ON ii.indrelid=i.indrelid AND
1313
ii.indexrelid != i.indexrelid AND
14-
array_to_string(ii.indkey, ' ') like (array_to_string(i.indkey, ' ') || '%') AND
15-
array_to_string(ii.indcollation, ' ') like (array_to_string(i.indcollation, ' ') || '%') AND
16-
array_to_string(ii.indclass, ' ') like (array_to_string(i.indclass, ' ') || '%') AND
14+
(array_to_string(ii.indkey, ' ') || ' ') like (array_to_string(i.indkey, ' ') || ' %') AND
15+
(array_to_string(ii.indcollation, ' ') || ' ') like (array_to_string(i.indcollation, ' ') || ' %') AND
16+
(array_to_string(ii.indclass, ' ') || ' ') like (array_to_string(i.indclass, ' ') || ' %') AND
1717
NOT (ii.indkey::integer[] @> ARRAY[0]) AND
1818
NOT (i.indkey::integer[] @> ARRAY[0]) AND
1919
CASE WHEN i.indisunique THEN ii.indisunique ELSE true END

0 commit comments

Comments
 (0)