pgsql: Fix generation of MergeAppend plans for optimized min/max on exp

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix generation of MergeAppend plans for optimized min/max on exp
Дата
Msg-id E1VeU6K-0006VA-HG@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix generation of MergeAppend plans for optimized min/max on expressions.

Before jamming a desired targetlist into a plan node, one really ought to
make sure the plan node can handle projections, and insert a buffering
Result plan node if not.  planagg.c forgot to do this, which is a hangover
from the days when it only dealt with IndexScan plan types.  MergeAppend
doesn't project though, not to mention that it gets unhappy if you remove
its possibly-resjunk sort columns.  The code accidentally failed to fail
for cases in which the min/max argument was a simple Var, because the new
targetlist would be equivalent to the original "flat" tlist anyway.
For any more complex case, it's been broken since 9.1 where we introduced
the ability to optimize min/max using MergeAppend, as reported by Raphael
Bauduin.  Fix by duplicating the logic from grouping_planner that decides
whether we need a Result node.

In 9.2 and 9.1, this requires back-porting the tlist_same_exprs() function
introduced in commit 4387cf956b9eb13aad569634e0c4df081d76e2e3, else we'd
uselessly add a Result node in cases that worked before.  It's rather
tempting to back-patch that whole commit so that we can avoid extra Result
nodes in mainline cases too; but I'll refrain, since that code hasn't
really seen all that much field testing yet.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/aa8a2c3a612a867fc5348bd6ff68f619212e3c1b

Modified Files
--------------
src/backend/optimizer/plan/planagg.c  |   23 ++++++++++++-
src/backend/optimizer/util/tlist.c    |   37 +++++++++++++++++++++
src/include/optimizer/tlist.h         |    3 ++
src/test/regress/expected/inherit.out |   58 +++++++++++++++++++++++++++++++++
src/test/regress/sql/inherit.sql      |    4 +++
5 files changed, 124 insertions(+), 1 deletion(-)


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix generation of MergeAppend plans for optimized min/max on exp
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix generation of MergeAppend plans for optimized min/max on exp