=?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