@@ -461,7 +461,7 @@ group_keys_reorder_by_pathkeys(List *pathkeys, List **group_pathkeys,
461
461
/*
462
462
* pathkeys_are_duplicate
463
463
* Check if give pathkeys are already contained the list of
464
- * PathKeyInfo 's.
464
+ * GroupByOrdering 's.
465
465
*/
466
466
static bool
467
467
pathkeys_are_duplicate (List * infos , List * pathkeys )
@@ -470,7 +470,7 @@ pathkeys_are_duplicate(List *infos, List *pathkeys)
470
470
471
471
foreach (lc , infos )
472
472
{
473
- PathKeyInfo * info = lfirst_node (PathKeyInfo , lc );
473
+ GroupByOrdering * info = lfirst_node (GroupByOrdering , lc );
474
474
475
475
if (compare_pathkeys (pathkeys , info -> pathkeys ) == PATHKEYS_EQUAL )
476
476
return true;
@@ -482,7 +482,7 @@ pathkeys_are_duplicate(List *infos, List *pathkeys)
482
482
* get_useful_group_keys_orderings
483
483
* Determine which orderings of GROUP BY keys are potentially interesting.
484
484
*
485
- * Returns a list of PathKeyInfo items, each representing an interesting
485
+ * Returns a list of GroupByOrdering items, each representing an interesting
486
486
* ordering of GROUP BY keys. Each item stores pathkeys and clauses in the
487
487
* matching order.
488
488
*
@@ -495,15 +495,15 @@ pathkeys_are_duplicate(List *infos, List *pathkeys)
495
495
List *
496
496
get_useful_group_keys_orderings (PlannerInfo * root , Path * path )
497
497
{
498
- Query * parse = root -> parse ;
499
- List * infos = NIL ;
500
- PathKeyInfo * info ;
498
+ Query * parse = root -> parse ;
499
+ List * infos = NIL ;
500
+ GroupByOrdering * info ;
501
501
502
502
List * pathkeys = root -> group_pathkeys ;
503
503
List * clauses = root -> processed_groupClause ;
504
504
505
505
/* always return at least the original pathkeys/clauses */
506
- info = makeNode (PathKeyInfo );
506
+ info = makeNode (GroupByOrdering );
507
507
info -> pathkeys = pathkeys ;
508
508
info -> clauses = clauses ;
509
509
infos = lappend (infos , info );
@@ -539,7 +539,7 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
539
539
(enable_incremental_sort || n == root -> num_groupby_pathkeys ) &&
540
540
!pathkeys_are_duplicate (infos , pathkeys ))
541
541
{
542
- info = makeNode (PathKeyInfo );
542
+ info = makeNode (GroupByOrdering );
543
543
info -> pathkeys = pathkeys ;
544
544
info -> clauses = clauses ;
545
545
@@ -564,7 +564,7 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
564
564
(enable_incremental_sort || n == list_length (root -> sort_pathkeys )) &&
565
565
!pathkeys_are_duplicate (infos , pathkeys ))
566
566
{
567
- info = makeNode (PathKeyInfo );
567
+ info = makeNode (GroupByOrdering );
568
568
info -> pathkeys = pathkeys ;
569
569
info -> clauses = clauses ;
570
570
@@ -574,18 +574,29 @@ get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
574
574
575
575
#ifdef USE_ASSERT_CHECKING
576
576
{
577
- PathKeyInfo * pinfo = linitial_node (PathKeyInfo , infos );
577
+ GroupByOrdering * pinfo = linitial_node (GroupByOrdering , infos );
578
578
ListCell * lc ;
579
579
580
580
/* Test consistency of info structures */
581
581
for_each_from (lc , infos , 1 )
582
582
{
583
- info = lfirst_node (PathKeyInfo , lc );
583
+ ListCell * lc1 , * lc2 ;
584
+
585
+ info = lfirst_node (GroupByOrdering , lc );
584
586
585
587
Assert (list_length (info -> clauses ) == list_length (pinfo -> clauses ));
586
588
Assert (list_length (info -> pathkeys ) == list_length (pinfo -> pathkeys ));
587
589
Assert (list_difference (info -> clauses , pinfo -> clauses ) == NIL );
588
590
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
+ }
589
600
}
590
601
}
591
602
#endif
0 commit comments