]> granicus.if.org Git - postgresql/commit
Fix generation of MergeAppend plans for optimized min/max on expressions.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Nov 2013 18:13:15 +0000 (13:13 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Nov 2013 18:13:15 +0000 (13:13 -0500)
commit5d0731da521f090f80ea39529fe274ac6d6bffa1
treefbc3d82864ce140821864ce60b9ea18cac29b9f7
parent66e6daa3e1a0c94f2fcf3463757d478c76c38b3a
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.
src/backend/optimizer/plan/planagg.c
src/test/regress/expected/inherit.out
src/test/regress/sql/inherit.sql