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

From: "Sergey Konoplev" <gray(dot)ru(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Very slow queries w/ NOT IN preparation (seems like a bug, test case)
Date: 2008-11-11 10:27:07
Message-ID: c3a7de1f0811110227n61721b0dx74dea958b99fe9a5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

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/

Attachment Content-Type Size
max_id_count_in_query_test.sh application/x-sh 2.0 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joao Ferreira gmail 2008-11-11 10:49:32 merge 2 dumps
Previous Message WaGathoni 2008-11-11 10:14:35 Change of Identity

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Huxton 2008-11-11 11:03:20 Re: Very slow queries w/ NOT IN preparation (seems like a bug, test case)
Previous Message Jaime Casanova 2008-11-11 07:09:18 Hot standby v5d, fails to build on windows