Re: Bad query plan - Mailing list pgsql-performance

From Tom Lane
Subject Re: Bad query plan
Date
Msg-id 12708.1311523344@sss.pgh.pa.us
Whole thread Raw
In response to Bad query plan  (Дмитрий Васильев <dmitry.vasil@gmail.com>)
List pgsql-performance
=?KOI8-R?B?5M3J1NLJyiD3wdPJzNjF1w==?= <dmitry.vasil@gmail.com> writes:
> explain analyze insert into large(id) select id from small where id
> not in(select id from large);
> [ crummy plan ]
> explain analyze insert into large(id) select id from small where not
> exists (select id from large l where small.id=l.id);
> [ better plan ]
> Both queries are semantically the same.

No, they are not.  NOT IN is hard to optimize because it has strange
behaviors with nulls in the data.  Use the NOT EXISTS formulation.

            regards, tom lane

pgsql-performance by date:

Previous
From: Дмитрий Васильев
Date:
Subject: Bad query plan
Next
From: Adarsh Sharma
Date:
Subject: Restore database after drop command