@ -3997,7 +3997,28 @@ consider_groupingsets_paths(PlannerInfo *root,
Assert ( can_hash ) ;
Assert ( can_hash ) ;
if ( pathkeys_contained_in ( root - > group_pathkeys , path - > pathkeys ) )
/*
* If the input is coincidentally sorted usefully ( which can happen
* even if is_sorted is false , since that only means that our caller
* has set up the sorting for us ) , then save some hashtable space by
* making use of that . But we need to watch out for degenerate cases :
*
* 1 ) If there are any empty grouping sets , then group_pathkeys might
* be NIL if all non - empty grouping sets are unsortable . In this case ,
* there will be a rollup containing only empty groups , and the
* pathkeys_contained_in test is vacuously true ; this is ok .
*
* XXX : the above relies on the fact that group_pathkeys is generated
* from the first rollup . If we add the ability to consider multiple
* sort orders for grouping input , this assumption might fail .
*
* 2 ) If there are no empty sets and only unsortable sets , then the
* rollups list will be empty ( and thus l_start = = NULL ) , and
* group_pathkeys will be NIL ; we must ensure that the vacuously - true
* pathkeys_contain_in test doesn ' t cause us to crash .
*/
if ( l_start ! = NULL & &
pathkeys_contained_in ( root - > group_pathkeys , path - > pathkeys ) )
{
{
unhashed_rollup = lfirst_node ( RollupData , l_start ) ;
unhashed_rollup = lfirst_node ( RollupData , l_start ) ;
exclude_groups = unhashed_rollup - > numGroups ;
exclude_groups = unhashed_rollup - > numGroups ;