Multi-column index: Which column order

Поиск
Список
Период
Сортировка
От Sebastien Flaesch
Тема Multi-column index: Which column order
Дата
Msg-id DBAP191MB12893BBE46573CA38E0FE921B0A29@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответы Re: Multi-column index: Which column order  (Erik Wienhold <ewie@ewie.name>)
Re: Multi-column index: Which column order  (Laurenz Albe <laurenz.albe@cybertec.at>)
Список pgsql-general
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 with the most various values first, and

For example, if the "code" column contains thousands of various item ids like 'SXZ874', 'ERF345', ... while the "etb" column contains a dozen of values like "L1", "LT" and "BX".

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)

Does it depend on the type of index (Btree, GiST, etc) ?

I could not find that information in the doc.

Seb

В списке pgsql-general по дате отправления:

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: Losing my latin on Ordering...
Следующее
От: Peter
Дата:
Сообщение: [Outcome] Queries running forever, because of wrong rowcount estimate