Re: Multi-column index: Which column order

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Ron <ronljohnsonjr(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Multi-column index: Which column order
Date: 2023-02-16 10:22:12
Message-ID: 94894e20a8e9d2b7fad6d70b55854a1978d70815.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2023-02-15 at 22:08 -0600, Ron wrote:
> On 2/15/23 21:45, Laurenz Albe wrote:
> > On Wed, 2023-02-15 at 10:20 -0600, Ron wrote:
> > > On 2/15/23 02:46, Laurenz Albe wrote:
> > > > Both are the same.
> > > > There is an old myth that says that you should use the more selective column first
> > > > (which would be "code"), but that is just a myth.
> > >
> > > Only on Postgresql?
> >
> > No, on all relational databases that use B-tree indexes.
>
> Not only is "all" is a very absolute word (I know of a counter-example), but
> querying on the second segment means that you have to scan the whole tree
> instead of isolating one sub-branch.

The question was about a multi-column index where all columns are compared
with "equal" in the WHERE condition. For other cases, order matters.

I am aware of the danger of absolute claims, but as far as I can tell, this
is in the nature of B-tree indexes.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message houzj.fnst@fujitsu.com 2023-02-16 13:15:28 RE: Support logical replication of DDLs
Previous Message Simon Elbaz 2023-02-16 09:58:56 Aggressive vacuum frequency on a table