Question, how intelligent is optimizer with subplans?

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Question, how intelligent is optimizer with subplans?
Дата
Msg-id 87iswjvdks.fsf@stark.dyndns.tv
обсуждение исходный текст
Ответы Re: Question, how intelligent is optimizer with subplans?  (Greg Stark <gsstark@mit.edu>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Justin Clift
Дата:
Сообщение: Re: Writing apps for ORDBMS
Следующее
От: Greg Stark
Дата:
Сообщение: Re: Question, how intelligent is optimizer with subplans?