PostgreSQL Redundant Indexes: Is an Index on (a) Redundant When You Have (a, b)?
Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples. TL;DR: A plain b-tree index on (a) is redundant when another b-tree index starts with a , such as (a, b) : PostgreSQL 18.3 served the same lookup from the wider index with the same number of heap reads. Do not drop it on that rule if it is UNIQUE , uses a different operator class or has…
A PostgreSQL b-tree index on a single column, such as (a), can be redundant when another b-tree index starts with that column, like (a, b). In PostgreSQL 18.3, the wider index served the same lookup as the narrower one, requiring the same number of heap reads. Therefore, it is not necessary to maintain both indexes in such cases.
However, there are exceptions where the narrower index has unique characteristics that make it valuable, such as being a UNIQUE index, using a different operator class, or including additional columns that the wider index does not. It is advisable to evaluate each index individually, rather than relying solely on the presence of a wider index with the same leading column.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to