Thread: Deciding which index to use

Deciding which index to use

From
Christophe Pettus
Date:
Where in the optimizer code does PostgreSQL decide which of several possibly-matching partial indexes to use?
--
-- Christophe Pettus  xof@thebuild.com




Re: Deciding which index to use

From
Tom Lane
Date:
Christophe Pettus <xof@thebuild.com> writes:
> Where in the optimizer code does PostgreSQL decide which of several possibly-matching partial indexes to use?

It costs them all out and uses the cheapest.

If the cost estimates come out exactly the same, you get an arbitrary
choice (I think probably always the index with smallest OID, but that's
an implementation artifact rather than something that's done explicitly
anywhere).
        regards, tom lane