Hi Henson, > Thanks for v6. I read it again in planning order: where a sorted > path is kept, how eager aggregation below the join uses it, which > GROUP BY orders become candidates, which orders the parallel paths > are sorted in, and what turning the GUC off does. Please correct > me if I got any of it wrong.
Thanks for the walkthrough. That matches what the patches do, for each of the four functions and for the GUC turned off. > I don't think they are dead code. I turned both into Asserts on a > cassert build, and each fails on one of the attached queries, while > v6 as posted runs them fine: > ... > So I'd keep them as runtime checks. Thanks for the queries. I ran guards-repro.sql on v7 with a NOTICE at each guard. The first query reaches the guard in group_keys_reorder_by_pathkeys() and the second the one in adjust_group_pathkeys_to_input(), and both run without error. So both guards stay as they are. > How about updating it along these lines? > > Controls if the query planner will produce a plan which will > provide GROUP BY keys sorted in the order of keys of a child > node of the plan, such as an index scan, in either sort > direction, or in the order required by window functions. Done, using your wording. I split it between the two patches, so that each patch documents what it adds: 0001 adds "in either sort direction", and 0002 adds "or in the order required by window functions". Attached is v7. Apart from the docs, it is v6 rebased onto the current master (f03a0f87963), with no code changes. Regression tests pass with 0001 alone and with both patches. Regards, Zhenglong
v7-0001-Ignore-sort-direction-when-matching-GROUP-BY-keys.patch
Description: Binary data
v7-0002-Consider-window-functions-when-reordering-GROUP-B.patch
Description: Binary data
