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 03:45:18
Message-ID: 121cb8239ebfea29f059a263dc2a920f1f3f8604.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2023-02-15 at 10:20 -0600, Ron wrote:
> On 2/15/23 02:46, Laurenz Albe wrote:
> > Which one is best?
> > > CREATE UNIQUE INDEX ix1 ON art (code, etb)
> > > or
> > > CREATE UNIQUE INDEX ix1 ON art (etb, code)
> > >
> > > (or its PRIMARY KEY equivalent)
> > 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.

Look at how many index entries have to be scanned in both cases, and you will see.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Amit Kapila 2023-02-16 04:00:52 Re: Support logical replication of DDLs
Previous Message Zheng Li 2023-02-15 22:16:05 Re: Support logical replication of DDLs