Re: Using a compound primary key

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Using a compound primary key
Дата
Msg-id 27209.1059371154@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Using a compound primary key  ("David Witham" <davidw@unidial.com.au>)
Список pgsql-sql
"David Witham" <davidw@unidial.com.au> writes:
> select * from tariff
> where tariff_type = 'UIA'
> and prefix in ('44','441','4412','44123','441234','4412345','44123456')
> order by prefix desc limit 1;

> The query doesn't use the primary key index as I might expect:

Flip the index column order --- this should do what you want if prefix
is the first column in the index.  (Improving that is on the wish-list,
but it seems to require a wholesale rethink of the way the planner
searches for indexes matching OR-clauses.)  You may also need to phrase
the ORDER BY as "prefix desc, tariff_type desc" to make it perfectly
clear to the planner that you don't need a separate sort step ... not
quite sure whether that will be needed or not.
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Can a table have a reference to itself?
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Problem using Subselect results