Teach planner how to propagate pathkeys from sub-SELECTs in FROM up to
Tom Lane <tgl@sss.pgh.pa.us>
Teach planner how to propagate pathkeys from sub-SELECTs in FROM up to the outer query. (The implementation is a bit klugy, but it would take nontrivial restructuring to make it nicer, which this is probably not worth.) This avoids unnecessary sort steps in examples like SELECT foo,count(*) FROM (SELECT ... ORDER BY foo,bar) sub GROUP BY foo which means there is now a reasonable technique for controlling the order of inputs to custom aggregates, even in the grouping case.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/optimizer/path/allpaths.c | modified | +6 −2 |
| src/backend/optimizer/path/pathkeys.c | modified | +138 −3 |
| src/backend/optimizer/plan/planner.c | modified | +15 −2 |
| src/backend/optimizer/util/pathnode.c | modified | +3 −3 |
| src/backend/optimizer/util/relnode.c | modified | +3 −3 |
| src/backend/optimizer/util/tlist.c | modified | +1 −10 |
| src/include/optimizer/pathnode.h | modified | +2 −2 |
| src/include/optimizer/paths.h | modified | +3 −1 |
| src/include/optimizer/tlist.h | modified | +1 −3 |