Question, how intelligent is optimizer with subplans?

Поиск
Список
Период
Сортировка
Искать
От
Gregory Stark
Тема
Question, how intelligent is optimizer with subplans?
Дата
Msg-id
87iswjvdks.fsf@stark.dyndns.tv
Список
Дерево обсуждения
Question, how intelligent is optimizer with subplans? Gregory Stark <gsstark@mit.edu>
Re: Question, how intelligent is optimizer with subplans? Greg Stark <gsstark@mit.edu>
Re: Question, how intelligent is optimizer with subplans? Tom Lane <tgl@sss.pgh.pa.us>

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
В списке pgsql-general по дате отправления
От: Justin Clift
Дата:
Сообщение: Re: Writing apps for ORDBMS
От: Greg Stark
Дата:
FAQ