Postgres8: subselect and optimizer/planner

From: Erwin Moller <erwin(at)darwine(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Subject: Postgres8: subselect and optimizer/planner
Date: 2007-10-04 09:52:36
Message-ID: 4704B7E4.20402@darwine.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I am fairly new to EXPLAIN, butl working on it. ;-)
I have a few slow running queries I am trying to optimize.

First thing I wonder: I sometimes (lazy) add a subselect to queries.
A stupid example to clearify what I mean:

SELECT U.userid, U.username,
(SELECT G.groupname FROM tblgroup WHERE (G.userid=U.userid)) AS ingroup
FROM tbluser WHERE (bla..bla...);

Will this approach be slower than a regular join?

I mean, will this construct 'force' a repetitive query for each result,
or will Postgres8 see my clumpsy construct, and make a join of it
internally?

Or is my question too general and is the answer 'it depends'?

I found a lot of queries I wrote like that in earlier projects, and I
wonder if I should fix them.
Thanks for any insights!

Regards,
Erwin Moller

--

-------------------
Erwin Moller
Darwine BV

Groenendaal 25f
3011 SK Rotterdam
tel 010-2133996
-------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Erwin Moller 2007-10-04 10:01:47 Re: Postgres8: subselect and optimizer/planner
Previous Message Jorge Godoy 2007-10-04 09:34:01 Re: Design Question (Time Series Data)