Re: Bad query plan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Дмитрий Васильев <dmitry(dot)vasil(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Bad query plan
Date: 2011-07-24 16:02:24
Message-ID: 12708.1311523344@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

=?KOI8-R?B?5M3J1NLJyiD3wdPJzNjF1w==?= <dmitry(dot)vasil(at)gmail(dot)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

In response to

  • Bad query plan at 2011-07-24 14:06:40 from Дмитрий Васильев

Browse pgsql-performance by date

  From Date Subject
Next Message Gavin Flower 2011-07-24 20:14:43 Re: Bad query plan
Previous Message Дмитрий Васильев 2011-07-24 14:06:40 Bad query plan