Re: optimisation of outer join

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Nicholas Piper <nick(at)nickpiper(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: optimisation of outer join
Date: 2001-08-09 11:50:02
Message-ID: Pine.BSF.4.21.0108090442280.44608-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Thu, 9 Aug 2001, Nicholas Piper wrote:

> Hi everyone again ! You've been so useful that I've got more questions
> :-)
>
> Sorry about the width of my posts by the way, I'm presuming it is
> preferred to have wide tables than try and wrap them.
>
> I'm trying to select all rows from a join, and then also some other
> rows from a third join if the rows exist. If they don't, then return
> blank entries.
>
> My normal query which only returns full rows and the one I've tried to
> alter to do exactly what I want is below. The question I have is why
> my new one is so slow, and doesn't appear to be using indexes again.
>
> (The new attempt is first)
>
> depos=# explain select cdtitles.title, cdtitles.artist, song,
> fk_products_id, p.title, p.artist from cdsongs, cdtitles left join
> products p on (cdtitles.fk_products_id = p.id) where cdtitles.cdid =
> cdsongs.cdid and song like 'mushroom festi%';
> NOTICE: QUERY PLAN:

You're forcng the cdtitles cross products join first I believe here.
I think you may want to force the other join first, so maybe...

explain select s.title, s.artist, song, fk_products_id, p.title, p.artist
from (cdsongs inner join cdtitles on (cdtitles.cdid=cdsongs.cdid)) s
left join products p on (s.fk_products_id = p.id) where song like
'mushroom festi%';

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nicholas Piper 2001-08-09 11:56:54 Re: optimisation of outer join
Previous Message Justin Clift 2001-08-09 10:27:16 Re: Looking for an Apache log to pgsql module