From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | andy(at)mixonic(dot)com (Andy) |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: need much better query perfomance |
Date: | 2003-01-29 07:14:16 |
Message-ID: | 20472.1043824456@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
andy(at)mixonic(dot)com (Andy) writes:
> select track_id from track where track_id not in (
> select at.track_id from album_track at, album alb
> where at.album_id = alb.album_id and alb.deleted is null
> )
> The above query should work, but it takes too long to execute.
The performance of NOT IN pretty much sucks :-(. (7.4 will be
better, but that doesn't help you today.) I'd suggest rewriting
to avoid that. Perhaps
CREATE TEMP TABLE keepers AS
select at.track_id from album_track at, album alb
where at.album_id = alb.album_id and alb.deleted is null;
CREATE TEMP TABLE zappers AS
SELECT track_id FROM track EXCEPT SELECT track_id FROM keepers;
DELETE FROM track WHERE track_id = zappers.track_id;
Untested, use at your own risk, etc.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 2003-01-29 07:15:46 | Re: *****SPAM***** ecpg help with 7.3 |
Previous Message | Stephan Szabo | 2003-01-29 07:02:59 | Re: What happens when you run out of transaction ID's ??? |