Question, how intelligent is optimizer with subplans?

From: Gregory Stark <gsstark(at)mit(dot)edu>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Question, how intelligent is optimizer with subplans?
Date: 2003-01-20 19:14:11
Message-ID: 87iswjvdks.fsf@stark.dyndns.tv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


In general if I have a query like

SELECT a,
FROM (SELECT foo, (select count(*) from anothertable where a=t.a) AS n FROM x) AS t
WHERE foo = 0

Is the optimizer clever enough not to run the "select count(*)" for every
record in x but only the ones where foo=0?

I can play with explain, but I won't know if I'm asking it to do the
impossible or not.

In case it's not obvious, the actual query is much more complex and involves a
DISTINCT ON() and a sort and the "select count(*)" is part of the sort so I
don't want to push it out manually and duplicate the expression.

--
greg

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2003-01-20 19:28:29 Re: Question, how intelligent is optimizer with subplans?
Previous Message Justin Clift 2003-01-20 19:03:24 Re: Writing apps for ORDBMS