Re: best way to fetch next/prev record based on index

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: best way to fetch next/prev record based on index
Дата
Msg-id 29727.1090944038@sss.pgh.pa.us
обсуждение исходный текст
Ответ на best way to fetch next/prev record based on index  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
Список pgsql-performance
I said:
> Oh, wait, you're right --- I'm mis-visualizing the situation.
> Hmm, it sure seems like there ought to be an easy way to do this...

The problem is that a multi-column index doesn't actually have the
semantics you want.  If you are willing to consider adding another
index (or replacing the existing 3-column guy), how about

create index ti on t((array[a,b,c]));

select * from t where array[a,b,c] >= array[a1,b1,c1]
order by array[a,b,c]
limit 1 offset 1;

This seems to do the right thing in 7.4 and later.  It does require that
all three columns have the same datatype though; you weren't specific
about the data model ...

            regards, tom lane

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

Предыдущее
От: "Merlin Moncure"
Дата:
Сообщение: best way to fetch next/prev record based on index
Следующее
От: Markus Schaber
Дата:
Сообщение: Re: best way to fetch next/prev record based on index