Re: Optimize query: time of "single * IN(many)" > time of "many * IN(single)" - Mailing list pgsql-general

From Tom Lane
Subject Re: Optimize query: time of "single * IN(many)" > time of "many * IN(single)"
Date
Msg-id 6191.1073574080@sss.pgh.pa.us
Whole thread Raw
In response to Optimize query: time of "single * IN(many)" > time of "many * IN(single)"  ("Paul Janssen" <postgresuser@hotmail.com>)
List pgsql-general
"Paul Janssen" <postgresuser@hotmail.com> writes:
> Can anyone help me out with the following situation:
>    (a) a single query with 550 id's in the IN-clause resulting into 800+
> seconds;
>    (b) 550 queries with a single id in the IN-clause resulting into overall
> time of <60 seconds;
> The table consists of 950.000 records, and the resultset consists of 205.000
> records.

> Why is there such an extreme difference in time?

Most likely the planner is opting not to use an indexscan in the first
case.  Could we see EXPLAIN ANALYZE results for both cases?  Also, try
"SET enable_seqscan TO OFF" and then repeat EXPLAIN ANALYZE for case (a).

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Compile problem on old Debian Linux with glibc 2.0.7
Next
From: Tom Lane
Date:
Subject: Re: order by is ambiguous