Reimplement planner's handling of MIN/MAX aggregate optimization (again).
Tom Lane <tgl@sss.pgh.pa.us>
Reimplement planner's handling of MIN/MAX aggregate optimization (again). Instead of playing cute games with pathkeys, just build a direct representation of the intended sub-select, and feed it through query_planner to get a Path for the index access. This is a bit slower than 9.1's previous method, since we'll duplicate most of the overhead of query_planner; but since the whole optimization only applies to rather simple single-table queries, that probably won't be much of a problem in practice. The advantage is that we get to do the right thing when there's a partial index that needs the implicit IS NOT NULL clause to be usable. Also, although this makes planagg.c be a bit more closely tied to the ordering of operations in grouping_planner, we can get rid of some coupling to lower-level parts of the planner. Per complaint from Marti Raudsepp.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/nodes/copyfuncs.c | modified | +0 −19 |
| src/backend/nodes/equalfuncs.c | modified | +0 −14 |
| src/backend/nodes/outfuncs.c | modified | +4 −1 |
| src/backend/optimizer/path/indxpath.c | modified | +13 −1 |
| src/backend/optimizer/path/pathkeys.c | modified | +6 −90 |
| src/backend/optimizer/plan/planagg.c | modified | +218 −367 |
| src/backend/optimizer/plan/planmain.c | modified | +0 −9 |
| src/backend/optimizer/plan/planner.c | modified | +4 −1 |
| src/include/nodes/relation.h | modified | +4 −4 |
| src/include/optimizer/paths.h | modified | +0 −16 |
| src/test/regress/expected/aggregates.out | modified | +11 −19 |
| src/test/regress/sql/aggregates.sql | modified | +3 −4 |