From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | "Magnus Naeslund(f)" <mag(at)fbab(dot)net> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Damn slow query |
Date: | 2002-10-09 22:08:47 |
Message-ID: | 3DA4A8EF.3040004@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Magnus Naeslund(f) wrote:
> Hello, i've got this query that's really slow...
> Figure this:
>
> testdb=> select now() ; select gid from bs where gid not in ( select x
> from z2test ); select now();
"IN (subselect)" is notoriously slow (in fact it is an FAQ). Can you rewrite
this as:
select b.gid from bs b where not exists (select 1 from z2test z where z.x =
b.gid);
or possibly:
select b.gid from bs b left join z2test z on z.x = b.gid where z.x IS NULL;
HTH,
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Naeslund(f) | 2002-10-09 22:30:08 | Re: Damn slow query |
Previous Message | Stephan Szabo | 2002-10-09 22:08:33 | Re: Damn slow query |