Re: need much better query perfomance

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Andy <andy(at)mixonic(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: need much better query perfomance
Date: 2003-01-29 06:39:57
Message-ID: 20030128223811.K4312-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 24 Jan 2003, Andy wrote:

> I wrote what must be a very naive query to find such tracks. Doing an
> explain on this query gave a huge time estimate. My query is below.
> Would someone please suggest a faster approach?
>
> select t.track_id
> from track t
> where t.deleted = 'Y'
> UNION
> 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
> )

Try converting the in query into EXISTS
something like
select track_id from track where not exists (
select at.track_id from album_track at, album alb where
at.album_id=alb.album_id and alb.deleted is null and
track.track_id=at.track_id;
);

In response to

Browse pgsql-general by date

  From Date Subject
Next Message codeWarrior 2003-01-29 06:46:32 Re: stopping access to a database
Previous Message Tom Lane 2003-01-29 06:30:19 Re: ERROR: ExecEvalAggref