Range contains element filter not using index of the element column

Поиск
Список
Период
Сортировка
От Lauri Kajan
Тема Range contains element filter not using index of the element column
Дата
Msg-id CAKWoFMJTND5-qt9bKkj7c=j10xUGhsYTSbtK57sSDxBcc=Hu=A@mail.gmail.com
обсуждение исходный текст
Ответы Re: Range contains element filter not using index of the element column  (Игорь Выскорко <vyskorko.igor@yandex.ru>)
Re: Range contains element filter not using index of the element column  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Range contains element filter not using index of the elementcolumn  (Alban Hertroys <haramrae@gmail.com>)
Список pgsql-general
Hi all,
I'm wondering if there are anything to do to utilize a index when doing a range contains element  query. I have tested this with 9.6 and 12.0.

I have a table with a timestamp column that has a btree index.
I would like to do a query:
SELECT * FROM table WHERE ts <@ tsrange($1, $2, '(]');
The index is not used and a seq scan is done instead.

To use the index correctly I have to do the query like this:
SELECT * FROM table WHERE  ($1 IS null OR $1 < ts) AND ($2 IS null OR ts <= $2);
I like the <@ syntax more. Is there something I can do differently? Maybe a different type of index instead?


Thanks,

-Lauri

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

Предыдущее
От: Andrei Zhidenkov
Дата:
Сообщение: Re: Weird seqscan node plan
Следующее
От: Игорь Выскорко
Дата:
Сообщение: Re: Weird seqscan node plan