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-0006V4-Cg@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
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/5e900bc00f77da8d5c28812c49f48858755fba44

Modified Files
--------------
src/backend/optimizer/plan/planagg.c  |   23 ++++++++++++-
src/test/regress/expected/inherit.out |   58 +++++++++++++++++++++++++++++++++
src/test/regress/sql/inherit.sql      |    4 +++
3 files changed, 84 insertions(+), 1 deletion(-)


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

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: pgsql: Fix setting of right bound at GIN page split.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix generation of MergeAppend plans for optimized min/max on exp