NikolayS / postgres_dba

The missing set of useful tools for Postgres DBAs and all engineers
BSD 3-Clause "New" or "Revised" License
1.03k stars 113 forks source link

Fix i2 (redundant indexes) for wide (10+ columns) tables #55

Closed NikolayS closed 2 years ago

NikolayS commented 2 years ago

Derived from:

The method of redundant index detection is based on the analysis of pg_index.indkey::text.

For tables with 10+ columns, straightforward LIKE can be wrong – for example, "1 23" will match the line "1 2", which is incorrect.

The solution is to lpad all the numbers and work with 3-digit number sequences: "010 023" and "001 002" for the example above (this pair won't match, as expected).

(In this PR, the code for this check was back-ported from postgres-checkup)