Skip to content

Incorrect where clause on btree_index_atts and pg_attribute join  #20

@Abhishek1804

Description

@Abhishek1804

This condition pg_attribute.attnum = ind_atts.attnum is filtering out majority of the bloated indexes.
Ref - JOIN btree_index_atts AS ind_atts ON pg_attribute.attrelid = ind_atts.indexrelid AND pg_attribute.attnum = ind_atts.attnum

This is because attnum of indexes in pg_attribute table will not always match with indkey of index in pg_index table. It will usually match for primary key or initial columns. Thus, pg_attribute.attnum = ind_atts.attnum condition has to be removed.

This condition : pg_stats.attname = pg_catalog.pg_get_indexdef(pg_attribute.attrelid, pg_attribute.attnum, TRUE) while joining with pg_stats will take care of the rest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions