@@ -57,7 +57,7 @@ index 340db2bac4..b55896bb89 100644
57
57
if (es->format == EXPLAIN_FORMAT_TEXT)
58
58
appendStringInfoChar(es->str, '\n');
59
59
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
60
- index 9d4893c504..1261be3494 100644
60
+ index 29020c908e..f7e673e75d 100644
61
61
--- a/src/backend/nodes/copyfuncs.c
62
62
+++ b/src/backend/nodes/copyfuncs.c
63
63
@@ -129,6 +129,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
@@ -69,7 +69,7 @@ index 9d4893c504..1261be3494 100644
69
69
70
70
/*
71
71
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
72
- index e73be21bd6..2457b54c39 100644
72
+ index 48202d2232..ac24b8edf4 100644
73
73
--- a/src/backend/nodes/outfuncs.c
74
74
+++ b/src/backend/nodes/outfuncs.c
75
75
@@ -342,6 +342,7 @@ _outPlanInfo(StringInfo str, const Plan *node)
@@ -393,15 +393,15 @@ index d3f8639a40..f18e1c1a54 100644
393
393
394
394
/*
395
395
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
396
- index 1868c4eff4..397e78c2ef 100644
396
+ index 1868c4eff4..100b0051a2 100644
397
397
--- a/src/backend/optimizer/plan/planner.c
398
398
+++ b/src/backend/optimizer/plan/planner.c
399
399
@@ -143,7 +143,8 @@ static List *extract_rollup_sets(List *groupingSets);
400
400
static List *reorder_grouping_sets(List *groupingSets, List *sortclause);
401
401
static void standard_qp_callback(PlannerInfo *root, void *extra);
402
402
static double get_number_of_groups(PlannerInfo *root,
403
403
- double path_rows,
404
- + RelOptInfo *rel ,
404
+ + Path *subpath ,
405
405
+ RelOptInfo *grouped_rel,
406
406
grouping_sets_data *gd,
407
407
List *target_list);
@@ -411,89 +411,64 @@ index 1868c4eff4..397e78c2ef 100644
411
411
static double
412
412
get_number_of_groups(PlannerInfo *root,
413
413
- double path_rows,
414
- + RelOptInfo *rel ,
414
+ + Path *subpath ,
415
415
+ RelOptInfo *grouped_rel,
416
416
grouping_sets_data *gd,
417
417
List *target_list)
418
418
{
419
- @@ -3185,9 +3187,10 @@ get_number_of_groups(PlannerInfo *root,
420
- {
421
- List *gset = (List *) lfirst(lc);
419
+ @@ -3187,7 +3189,7 @@ get_number_of_groups(PlannerInfo *root,
422
420
GroupingSetData *gs = lfirst_node(GroupingSetData, lc2);
423
- - double numGroups = estimate_num_groups(root,
424
- + double numGroups = estimate_num_groups_ext(root,
421
+ double numGroups = estimate_num_groups(root,
425
422
groupExprs,
426
423
- path_rows,
427
- + rel,
428
- + grouped_rel,
424
+ + subpath->rows,
429
425
&gset,
430
426
NULL);
431
427
432
- @@ -3211,9 +3214,10 @@ get_number_of_groups(PlannerInfo *root,
433
- {
434
- List *gset = (List *) lfirst(lc);
428
+ @@ -3213,7 +3215,7 @@ get_number_of_groups(PlannerInfo *root,
435
429
GroupingSetData *gs = lfirst_node(GroupingSetData, lc2);
436
- - double numGroups = estimate_num_groups(root,
437
- + double numGroups = estimate_num_groups_ext(root,
430
+ double numGroups = estimate_num_groups(root,
438
431
groupExprs,
439
432
- path_rows,
440
- + rel,
441
- + grouped_rel,
433
+ + subpath->rows,
442
434
&gset,
443
435
NULL);
444
436
445
- @@ -3230,8 +3234 ,8 @@ get_number_of_groups(PlannerInfo *root,
437
+ @@ -3230,8 +3232 ,8 @@ get_number_of_groups(PlannerInfo *root,
446
438
groupExprs = get_sortgrouplist_exprs(parse->groupClause,
447
439
target_list);
448
440
449
441
- dNumGroups = estimate_num_groups(root, groupExprs, path_rows,
450
442
- NULL, NULL);
451
- + dNumGroups = estimate_num_groups_ext(root, groupExprs, rel ,
443
+ + dNumGroups = estimate_num_groups_ext(root, groupExprs, subpath ,
452
444
+ grouped_rel, NULL, NULL);
453
445
}
454
446
}
455
447
else if (parse->groupingSets)
456
- @@ -3403,7 +3407,7 @@ make_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
457
- * NULL. (This could be changed, but might require adjustments
458
- * elsewhere.)
459
- */
460
- - grouped_rel = fetch_upper_rel(root, UPPERREL_GROUP_AGG, NULL);
461
- + grouped_rel = fetch_upper_rel(root, UPPERREL_GROUP_AGG, input_rel->relids);
462
- }
463
-
464
- /* Set target. */
465
- @@ -3529,7 +3533,6 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
466
- GroupPathExtraData *extra,
467
- RelOptInfo **partially_grouped_rel_p)
468
- {
469
- - Path *cheapest_path = input_rel->cheapest_total_path;
470
- RelOptInfo *partially_grouped_rel = NULL;
471
- double dNumGroups;
472
- PartitionwiseAggregateType patype = PARTITIONWISE_AGGREGATE_NONE;
473
- @@ -3618,7 +3621,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
448
+ @@ -3618,7 +3620,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
474
449
* Estimate number of groups.
475
450
*/
476
451
dNumGroups = get_number_of_groups(root,
477
452
- cheapest_path->rows,
478
- + input_rel ,
453
+ + cheapest_path ,
479
454
+ grouped_rel,
480
455
gd,
481
456
extra->targetList);
482
457
483
- @@ -6424,13 +6428 ,15 @@ create_partial_grouping_paths(PlannerInfo *root,
458
+ @@ -6424,13 +6427 ,15 @@ create_partial_grouping_paths(PlannerInfo *root,
484
459
if (cheapest_total_path != NULL)
485
460
dNumPartialGroups =
486
461
get_number_of_groups(root,
487
462
- cheapest_total_path->rows,
488
- + input_rel ,
463
+ + cheapest_total_path ,
489
464
+ partially_grouped_rel,
490
465
gd,
491
466
extra->targetList);
492
467
if (cheapest_partial_path != NULL)
493
468
dNumPartialPartialGroups =
494
469
get_number_of_groups(root,
495
470
- cheapest_partial_path->rows,
496
- + input_rel ,
471
+ + cheapest_partial_path ,
497
472
+ partially_grouped_rel,
498
473
gd,
499
474
extra->targetList);
@@ -565,7 +540,7 @@ index e105a4d5f1..d821ea63bd 100644
565
540
566
541
return ppi;
567
542
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
568
- index 0c8c05f6c2..0ddc3fc46c 100644
543
+ index 0c8c05f6c2..eba4d982b9 100644
569
544
--- a/src/backend/utils/adt/selfuncs.c
570
545
+++ b/src/backend/utils/adt/selfuncs.c
571
546
@@ -143,6 +143,7 @@
@@ -581,14 +556,14 @@ index 0c8c05f6c2..0ddc3fc46c 100644
581
556
}
582
557
583
558
+ double
584
- + estimate_num_groups_ext(PlannerInfo *root, List *groupExprs, RelOptInfo *rel ,
559
+ + estimate_num_groups_ext(PlannerInfo *root, List *groupExprs, Path *subpath ,
585
560
+ RelOptInfo *grouped_rel, List **pgset,
586
561
+ EstimationInfo *estinfo)
587
562
+ {
588
- + double input_rows = rel->cheapest_total_path ->rows;
563
+ + double input_rows = subpath ->rows;
589
564
+
590
565
+ if (estimate_num_groups_hook != NULL)
591
- + return (*estimate_num_groups_hook)(root, groupExprs, rel , grouped_rel,
566
+ + return (*estimate_num_groups_hook)(root, groupExprs, subpath , grouped_rel,
592
567
+ pgset, estinfo);
593
568
+
594
569
+ return estimate_num_groups(root, groupExprs, input_rows, pgset, estinfo);
@@ -621,7 +596,7 @@ index e94d9e49cf..49236ced77 100644
621
596
extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
622
597
ParamListInfo params, DestReceiver *dest);
623
598
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
624
- index a692bcfb53..74aed4b1fb 100644
599
+ index e20c245f98..a2ba24aada 100644
625
600
--- a/src/include/nodes/pathnodes.h
626
601
+++ b/src/include/nodes/pathnodes.h
627
602
@@ -751,6 +751,10 @@ typedef struct RelOptInfo
@@ -788,7 +763,7 @@ index bf1adfc52a..9c78e0f4e0 100644
788
763
* prototypes for plan/planmain.c
789
764
*/
790
765
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h
791
- index 9dd444e1ff..2c0f942250 100644
766
+ index 9dd444e1ff..b0b5a65618 100644
792
767
--- a/src/include/utils/selfuncs.h
793
768
+++ b/src/include/utils/selfuncs.h
794
769
@@ -144,6 +144,13 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,
@@ -797,7 +772,7 @@ index 9dd444e1ff..2c0f942250 100644
797
772
extern PGDLLIMPORT get_index_stats_hook_type get_index_stats_hook;
798
773
+ typedef double (*estimate_num_groups_hook_type) (PlannerInfo *root,
799
774
+ List *groupExprs,
800
- + RelOptInfo *rel ,
775
+ + Path *subpath ,
801
776
+ RelOptInfo *grouped_rel,
802
777
+ List **pgset,
803
778
+ EstimationInfo *estinfo);
@@ -810,7 +785,7 @@ index 9dd444e1ff..2c0f942250 100644
810
785
Selectivity *rightstart
6377
, Selectivity *rightend);
811
786
812
787
+ extern double estimate_num_groups_ext(PlannerInfo *root, List *groupExprs,
813
- + RelOptInfo *rel , RelOptInfo *grouped_rel,
788
+ + Path *subpath , RelOptInfo *grouped_rel,
814
789
+ List **pgset, EstimationInfo *estinfo);
815
790
extern double estimate_num_groups(PlannerInfo *root, List *groupExprs,
816
791
double input_rows, List **pgset,
0 commit comments