Re: Left Join Question

From: "Ryan Wells" <ryan(dot)wells(at)soapware(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Left Join Question
Date: 2008-11-19 15:30:39
Message-ID: 52F2AD70C422474B857FC9E3F7B62539028DB1F9@exchange.DOCS.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks for the feedback, everyone.

> > FROM tasks
> > LEFT JOIN clients ON tasks.ClientId = clients.ClientId
> > LEFT JOIN iteminfo ON tasks.Id = iteminfo.ItemId
> > LEFT JOIN changelog ON tasks.Id = changelog.ItemId
> > LEFT JOIN ticklers ON tasks.Id = ticklers.RelatedId
> > WHERE tasks.Id = '123456';
> >
> > (I've cleaned it up so it's easier to read.)
>
> Thanks Ryan - that always makes it easier.

It actually looked so much less crazy after the cleaning that I nearly
decided not to ask about it, but my I was really interested in learning
if there was a dramatically better approach. Looks like there probably
isn't, which is fine.

> For the case when you have large numbers of results from iteminfo etc.
> it might well be quicker to do separate queries. That's simple enough
> since you're joining straight to tasks.id, but is obviously more
fiddly
> and when there aren't many rows returned would probably be slower
(you'd
> have 5 lots of query parsing/execute overhead). That might be a
> trade-off that makes sense to you though.

Even though the tables are fairly big, the result-set should be small (a
few dozen maybe), so multiple queries probably wouldn't gain much.

Thanks again!
Ryan

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2008-11-19 18:05:57 Re: VACUUM cannot be executed from multi-command string
Previous Message Sabin Coanda 2008-11-19 15:26:34 VACUUM cannot be executed from multi-command string