Very slow queries w/ NOT IN preparation (seems like a bug, test case)

Поиск
Список
Период
Сортировка
От Sergey Konoplev
Тема Very slow queries w/ NOT IN preparation (seems like a bug, test case)
Дата
Msg-id c3a7de1f0811110227n61721b0dx74dea958b99fe9a5@mail.gmail.com
обсуждение исходный текст
Ответы Re: Very slow queries w/ NOT IN preparation (seems like a bug, test case)  (Richard Huxton <dev@archonet.com>)
Re: Very slow queries w/ NOT IN preparation (seems like a bug, test case)  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hi all,

Here is my environment information:

# select version();
                                            version
------------------------------------------------------------------------------------------------
 PostgreSQL 8.3.4 on i686-pc-linux-gnu, compiled by GCC gcc (GCC)
4.2.4 (Ubuntu 4.2.4-1ubuntu3)
(1 row)

I've faced strange parser (or may be planner) behaviour. When I do
"EXPLAIN SELECT 1 FROM table1 WHERE table1_id IN (...~2000 ids
here...);" it works as fast as I expect (50 ms). But when I rewrite it
using NOT IN "EXPLAIN SELECT 1 FROM table1 WHERE table1_id NOT IN
(...~2000 ids here...);" it gets much more slower (34537 ms).

I've done a test case (see attachement) so you can reproduce the
situation (correct PSQL parameter in the begining of the script).

Another thing is that I set my statement_timeout to 20s and it seems
like postgres just ignore this.

Is it a bug and why it happens if not?
Could someone explain what can I do now to make my NOT IN queries work
fast, please?

--
Regards,
Sergey Konoplev
--
PostgreSQL articles in english & russian
http://gray-hemp.blogspot.com/search/label/postgresql/

Вложения

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

Предыдущее
От: WaGathoni
Дата:
Сообщение: Re: Chart of Accounts
Следующее
От: Yasuo Ohgaki
Дата:
Сообщение: Re: SQL injection, php and queueing multiple statement