Re: Multi-column index: Which column order

2023-02-16 Thread Laurenz Albe
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 > > > > colum

Re: Multi-column index: Which column order

2023-02-15 Thread Ron
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: [snip] 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 Pos

Re: Multi-column index: Which column order

2023-02-15 Thread Laurenz Albe
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

Re: Multi-column index: Which column order

2023-02-15 Thread Ron
On 2/15/23 02:46, Laurenz Albe wrote: [snip] 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 moew selective column first (whic

Re: Multi-column index: Which column order

2023-02-15 Thread Laurenz Albe
On Tue, 2023-02-14 at 17:53 +, Sebastien Flaesch wrote: > When creating an index on multiple columns, does the order of the columns > matter? > (I guess so) It does, but not in your case. > It's mostly for SELECT statements using a condition that include ALL columns > of the index (pkey): >

Re: Multi-column index: Which column order

2023-02-14 Thread Erik Wienhold
> On 14/02/2023 18:53 CET Sebastien Flaesch wrote: > > Hello! > > When creating an index on multiple columns, does the order of the columns > matter? (I guess so) Maybe, depending on the queries. > It's mostly for SELECT statements using a condition that include ALL > columns of the index (pkey)

Multi-column index: Which column order

2023-02-14 Thread Sebastien Flaesch
Hello! When creating an index on multiple columns, does the order of the columns matter? (I guess so) It's mostly for SELECT statements using a condition that include ALL columns of the index (pkey): SELECT * FROM art WHERE etb='L1' and code='ART345' I would naturally put the columns wit