Implicit v Explicit joins...

From: "ericnielsen(at)pop(dot)ne(dot)mediaone(dot)net" <ericnielsen(at)pop(dot)ne(dot)mediaone(dot)net>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Implicit v Explicit joins...
Date: 2001-09-17 18:41:47
Message-ID: RELAY1tPyOFkXIA5yS700002af2@relay1.softcomca.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

So I wasn't paying enough attention to postgres upgrades and missed that 7.1 actually has outer joins, so I'm currently happily rebuilding, but I had a few questions about the explicit join syntax and preformance issues.

1. Say i have a tables called
"married" (marriedid, husband, wife),
"people" (peopleid, firstname, lastname, townid), and
"towns" (townid, townname)
(not the exact exaple, but should be close enough).
I want to get a list of all couples (fullname of both husband/wife with hometown) where the hometown of one equals 'foo';
Would this be the proper way of setting up the query?
SELECT h.firstname, h.lastname, h.hometown,
w.firstname, w.lastname, w.hometown
FROM married m
JOIN people h ON (m.husband=h.peopleid)
JOIN people w ON (m.wife=w.peopleid)
LEFT OUTER JOIN towns ht (h.townid=ht.townid)
LEFT OUTER JOIN towns wt (w.townid=wt.townid)
WHERE ht.townname='foo' OR wt.townname='foo';

2. In general is explicit outer join more efficient than the old union select syntax? Is the outer join syntax just syntacic sugar (does it decode into the union selects)?
3. I think I saw someone that explicit joins occur in order, giving the planner less room to optimize, is this correct? I've often heard that you want to preform your inner joins before the other joins in order to limit the size of the tables being used. Will the planner consider putting implicit inner joins before the explicit outers or do all explicits occur first?

Thank you.
Eric Nielsen

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .

Browse pgsql-sql by date

  From Date Subject
Next Message Pasha 2001-09-17 18:49:12 Stored prosedure last run
Previous Message Carl van Tast 2001-09-17 18:07:39 Re: group by weirdness