pgsql: Reimplement planner's handling of MIN/MAX aggregate optimization

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Reimplement planner's handling of MIN/MAX aggregate optimization
Date: 2010-11-04 16:02:26
Message-ID: E1PE2Gg-0003wq-5k@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Reimplement planner's handling of MIN/MAX aggregate optimization.

Per my recent proposal, get rid of all the direct inspection of indexes
and manual generation of paths in planagg.c. Instead, set up
EquivalenceClasses for the aggregate argument expressions, and let the
regular path generation logic deal with creating paths that can satisfy
those sort orders. This makes planagg.c a bit more visible to the rest
of the planner than it was originally, but the approach is basically a lot
cleaner than before. A major advantage of doing it this way is that we get
MIN/MAX optimization on inheritance trees (using MergeAppend of indexscans)
practically for free, whereas in the old way we'd have had to add a whole
lot more duplicative logic.

One small disadvantage of this approach is that MIN/MAX aggregates can no
longer exploit partial indexes having an "x IS NOT NULL" predicate, unless
that restriction or something that implies it is specified in the query.
The previous implementation was able to use the added "x IS NOT NULL"
condition as an extra predicate proof condition, but in this version we
rely entirely on indexes that are considered usable by the main planning
process. That seems a fair tradeoff for the simplicity and functionality
gained.

Branch
------
master

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=034967bdcbb0c7be61d0500955226e1234ec5f04

Modified Files
--------------
src/backend/nodes/copyfuncs.c | 19 +
src/backend/nodes/equalfuncs.c | 14 +
src/backend/nodes/outfuncs.c | 15 +
src/backend/optimizer/path/pathkeys.c | 100 ++++-
src/backend/optimizer/plan/createplan.c | 5 +-
src/backend/optimizer/plan/planagg.c | 766 ++++++++++++++---------------
src/backend/optimizer/plan/planmain.c | 59 ++-
src/backend/optimizer/plan/planner.c | 41 +-
src/backend/optimizer/prep/prepjointree.c | 1 +
src/backend/optimizer/prep/prepunion.c | 1 +
src/backend/optimizer/util/var.c | 1 +
src/backend/rewrite/rewriteManip.c | 3 +
src/include/nodes/nodes.h | 1 +
src/include/nodes/relation.h | 19 +
src/include/optimizer/paths.h | 7 +-
src/include/optimizer/planmain.h | 2 +-
src/test/regress/expected/aggregates.out | 232 +++++++++-
src/test/regress/sql/aggregates.sql | 58 ++-
18 files changed, 873 insertions(+), 471 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2010-11-04 19:29:13 pgsql: Use appendStringInfoString() where appropriate in elog.c.
Previous Message Tom Lane 2010-11-03 17:43:00 pgsql: Reduce recursion depth in recently-added regression test.