@@ -461,7 +461,7 @@ group_keys_reorder_by_pathkeys(List *pathkeys, List **group_pathkeys,
461461/*
462462 * pathkeys_are_duplicate
463463 * Check if give pathkeys are already contained the list of
464- * PathKeyInfo 's.
464+ * GroupByOrdering 's.
465465 */
466466static bool
467467pathkeys_are_duplicate (List * infos , List * pathkeys )
@@ -470,7 +470,7 @@ pathkeys_are_duplicate(List *infos, List *pathkeys)
470470
471471 foreach (lc , infos )
472472 {
473- PathKeyInfo * info = lfirst_node (PathKeyInfo , lc );
473+ GroupByOrdering * info = lfirst_node (GroupByOrdering , lc );
474474
475475 if (compare_pathkeys (pathkeys , info -> pathkeys ) == PATHKEYS_EQUAL )
476476 return true;
@@ -482,7 +482,7 @@ pathkeys_are_duplicate(List *infos, List *pathkeys)
482482 * get_useful_group_keys_orderings
483483 * Determine which orderings of GROUP BY keys are potentially interesting.
484484 *
485- * Returns a list of PathKeyInfo items, each representing an interesting
485+ * Returns a list of GroupByOrdering items, each representing an interesting
486486 * ordering of GROUP BY keys. Each item stores pathkeys and clauses in the
487487 * matching order.
488488 *
@@ -495,15 +495,15 @@ pathkeys_are_duplicate(List *infos, List *pathkeys)
495495List *
496496get_useful_group_keys_orderings (PlannerInfo * root , Path * path )
497497{
498- Query * parse = root -> parse ;
499- List * infos = NIL ;
500- PathKeyInfo * info ;
498+ Query * parse = root -> parse ;
499+ List * infos = NIL ;
500+ GroupByOrdering * info ;
501501
502502 List * pathkeys = root -> group_pathkeys ;
503503 List * clauses = root -> processed_groupClause ;
504504
505505 /* always return at least the original pathkeys/clauses */
506- info = makeNode (PathKeyInfo );
506+ info = makeNode (GroupByOrdering );
507507 info -> pathkeys = pathkeys ;
508508 info -> clauses = clauses ;
509509 infos = lappend (infos , info );
@@ -539,7 +539,7 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
539539 (enable_incremental_sort || n == root -> num_groupby_pathkeys ) &&
540540 !pathkeys_are_duplicate (infos , pathkeys ))
541541 {
542- info = makeNode (PathKeyInfo );
542+ info = makeNode (GroupByOrdering );
543543 info -> pathkeys = pathkeys ;
544544 info -> clauses = clauses ;
545545
@@ -564,7 +564,7 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
564564 (enable_incremental_sort || n == list_length (root -> sort_pathkeys )) &&
565565 !pathkeys_are_duplicate (infos , pathkeys ))
566566 {
567- info = makeNode (PathKeyInfo );
567+ info = makeNode (GroupByOrdering );
568568 info -> pathkeys = pathkeys ;
569569 info -> clauses = clauses ;
570570
@@ -574,18 +574,29 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
574574
575575#ifdef USE_ASSERT_CHECKING
576576 {
577- PathKeyInfo * pinfo = linitial_node (PathKeyInfo , infos );
577+ GroupByOrdering * pinfo = linitial_node (GroupByOrdering , infos );
578578 ListCell * lc ;
579579
580580 /* Test consistency of info structures */
581581 for_each_from (lc , infos , 1 )
582582 {
583- info = lfirst_node (PathKeyInfo , lc );
583+ ListCell * lc1 , * lc2 ;
584+
585+ info = lfirst_node (GroupByOrdering , lc );
584586
585587 Assert (list_length (info -> clauses ) == list_length (pinfo -> clauses ));
586588 Assert (list_length (info -> pathkeys ) == list_length (pinfo -> pathkeys ));
587589 Assert (list_difference (info -> clauses , pinfo -> clauses ) == NIL );
588590 Assert (list_difference_ptr (info -> pathkeys , pinfo -> pathkeys ) == NIL );
591+
592+ forboth (lc1 , info -> clauses , lc2 , info -> pathkeys )
593+ {
594+ SortGroupClause * sgc = lfirst_node (SortGroupClause , lc1 );
595+ PathKey * pk = lfirst_node (PathKey , lc2 );
596+
597+ if (pk -> pk_eclass -> ec_sortref != sgc -> tleSortGroupRef )
598+ elog (ERROR , "Order of group-by clauses doesn't correspond incoming sort order" );
599+ }
589600 }
590601 }
591602#endif
0 commit comments