Deciding which index to use

Lists: pgsql-hackers
From: Christophe Pettus <xof(at)thebuild(dot)com>
To: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Deciding which index to use
Date: 2014-11-11 22:15:38
Message-ID: AF378A51-0E06-45F8-A7F8-9EEA685FF0C9@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Where in the optimizer code does PostgreSQL decide which of several possibly-matching partial indexes to use?
--
-- Christophe Pettus
xof(at)thebuild(dot)com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christophe Pettus <xof(at)thebuild(dot)com>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Deciding which index to use
Date: 2014-11-11 22:31:18
Message-ID: 18555.1415745078@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Christophe Pettus <xof(at)thebuild(dot)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