OK, here is a version that I think addresses all of the recent comments:
* I refactored the grouping-sets stuff as suggested by Robert and David.
The GroupingSetsPath code is now used *only* when there are grouping sets,
otherwise what you get is a plain AGG_SORTED AggPath. This allowed
removal of a boatload of weird corner cases in the GroupingSets code path,
so it was a good change. (Fundamentally, that's cleaning up some
questionable coding in the grouping sets patch rather than fixing anything
directly related to pathification, but I like the code better now.)
* I refactored the handling of targetlists in createplan.c. After some
reflection I decided that the disuse_physical_tlist callers fell into
three separate categories: those that actually needed the exact requested
tlist to be returned, those that wanted non-bloated tuples because they
were going to put them into sort or hash storage, and those that needed
grouping columns to be properly labeled. The new approach is to pass down
a "flags" word that specifies which if any of these cases apply at a
specific plan level. use_physical_tlist now always makes the right
decision to start with, and disuse_physical_tlist is gone entirely, which
should make things a bit faster since we won't uselessly construct and
discard physical tlists. The missing logic from make_subplanTargetList
and locate_grouping_columns is reincarnated in the physical-tlist code.
* Added explicit limit/offset fields to LimitPath, as requested by Teodor.
* Removed SortPath.sortgroupclauses.
* Fixed handling of parallel-query fields in new path node types.
(BTW, I found what seemed to be a couple of pre-existing bugs of
the same kind, eg create_mergejoin_path was different from the
other two kinds of join as to setting parallel_degree.)
What remains to be done, IMV:
* Performance testing as per yesterday's discussion.
* Debug support in outfuncs.c and print_path() for new node types.
* Clean up unfinished work on function header comments.
* Write some documentation about how FDWs might use this.
I'll work on the performance testing next. Barring unsatisfactory
results from that, I think this could be committable in a couple
of days.
regards, tom lane