Repair logic for reordering grouping sets optimization.

Andrew Gierth <rhodiumtoad@postgresql.org>

Commit: da53be23d1c5e529675e958eaee54cfed4e4dbac
Author: Andrew Gierth <rhodiumtoad@postgresql.org>
Date: 2019-06-30T22:49:13Z
Releases: 12.0
Repair logic for reordering grouping sets optimization.

The logic in reorder_grouping_sets to order grouping set elements to
match a pre-specified sort ordering was defective, resulting in
unnecessary sort nodes (though the query output would still be
correct). Repair, simplifying the code a little, and add a test.

Per report from Richard Guo, though I didn't use their patch. Original
bug seems to have been my fault.

Backpatch back to 9.5 where grouping sets were introduced.

Discussion: https://postgr.es/m/CAN_9JTzyjGcUjiBHxLsgqfk7PkdLGXiM=pwM+=ph2LsWw0WO1A@mail.gmail.com

Files

Discussion