1
1
diff --git a/contrib/Makefile b/contrib/Makefile
2
- index f27e458482e..0c621919045 100644
2
+ index f27e458482..0c62191904 100644
3
3
--- a/contrib/Makefile
4
4
+++ b/contrib/Makefile
5
5
@@ -7,6 +7,7 @@ include $(top_builddir)/src/Makefile.global
@@ -11,17 +11,17 @@ index f27e458482e..0c621919045 100644
11
11
auto_explain \
12
12
bloom \
13
13
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
14
- index 70551522dac..d9cca82fe84 100644
14
+ index 70551522da..958529fbab 100644
15
15
--- a/src/backend/commands/explain.c
16
16
+++ b/src/backend/commands/explain.c
17
- @@ -25,6 +25,7 @@
17
+ @@ -24,6 +24,7 @@
18
+ #include "nodes/extensible.h"
18
19
#include "nodes/makefuncs.h"
19
20
#include "nodes/nodeFuncs.h"
20
- #include "parser/analyze.h"
21
21
+ #include "optimizer/cost.h"
22
+ #include "parser/analyze.h"
22
23
#include "parser/parsetree.h"
23
24
#include "rewrite/rewriteHandler.h"
24
- #include "storage/bufmgr.h"
25
25
@@ -47,6 +48,12 @@ ExplainOneQuery_hook_type ExplainOneQuery_hook = NULL;
26
26
/* Hook for plugins to get control in explain_get_index_name() */
27
27
explain_get_index_name_hook_type explain_get_index_name_hook = NULL;
@@ -57,7 +57,7 @@ index 70551522dac..d9cca82fe84 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 4d9746d54a0..6fa85d1c71f 100644
60
+ index 4d9746d54a..6fa85d1c71 100644
61
61
--- a/src/backend/nodes/copyfuncs.c
62
62
+++ b/src/backend/nodes/copyfuncs.c
63
63
@@ -132,6 +132,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
@@ -69,7 +69,7 @@ index 4d9746d54a0..6fa85d1c71f 100644
69
69
70
70
/*
71
71
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
72
- index 58c2590698c..1e06738a137 100644
72
+ index 58c2590698..1e06738a13 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)
@@ -81,7 +81,7 @@ index 58c2590698c..1e06738a137 100644
81
81
82
82
/*
83
83
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
84
- index eaa51c5c062..6ad8b78c7d5 100644
84
+ index eaa51c5c06..6ad8b78c7d 100644
85
85
--- a/src/backend/nodes/readfuncs.c
86
86
+++ b/src/backend/nodes/readfuncs.c
87
87
@@ -1628,6 +1628,11 @@ ReadCommonPlan(Plan *local_node)
@@ -97,7 +97,7 @@ index eaa51c5c062..6ad8b78c7d5 100644
97
97
98
98
/*
99
99
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
100
- index 006f91f0a87..ef9c8ec5817 100644
100
+ index 006f91f0a8..ef9c8ec581 100644
101
101
--- a/src/backend/optimizer/path/costsize.c
102
102
+++ b/src/backend/optimizer/path/costsize.c
103
103
@@ -98,6 +98,11 @@
@@ -362,7 +362,7 @@ index 006f91f0a87..ef9c8ec5817 100644
362
362
{
363
363
double parallel_divisor = path->parallel_workers;
364
364
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
365
- index 0ed858f305a..9d4a6c59030 100644
365
+ index 0ed858f305..9d4a6c5903 100644
366
366
--- a/src/backend/optimizer/plan/createplan.c
367
367
+++ b/src/backend/optimizer/plan/createplan.c
368
368
@@ -71,6 +71,7 @@
@@ -393,7 +393,7 @@ index 0ed858f305a..9d4a6c59030 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 70899e5430e..dac6132af54 100644
396
+ index 70899e5430..34075cc87b 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);
@@ -441,7 +441,7 @@ index 70899e5430e..dac6132af54 100644
441
441
- dNumGroups = estimate_num_groups(root, groupExprs, path_rows,
442
442
- NULL, NULL);
443
443
+ dNumGroups = estimate_num_groups_ext(root, groupExprs, subpath,
444
- + grouped_rel, NULL);
444
+ + grouped_rel, NULL, NULL );
445
445
}
446
446
}
447
447
else if (parse->groupingSets)
@@ -474,7 +474,7 @@ index 70899e5430e..dac6132af54 100644
474
474
extra->targetList);
475
475
476
476
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
477
- index e105a4d5f1d..c5bcc9d1d15 100644
477
+ index e105a4d5f1..c5bcc9d1d1 100644
478
478
--- a/src/backend/optimizer/util/relnode.c
479
479
+++ b/src/backend/optimizer/util/relnode.c
480
480
@@ -258,6 +258,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
@@ -540,15 +540,9 @@ index e105a4d5f1d..c5bcc9d1d15 100644
540
540
541
541
return ppi;
542
542
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
543
- index 962dec6d504..899ee2bf4c5 100644
543
+ index 87879c9ddc..1aad8c43d9 100644
544
544
--- a/src/backend/utils/adt/selfuncs.c
545
545
+++ b/src/backend/utils/adt/selfuncs.c
546
- @@ -1,4 +1,4 @@
547
- - /*-------------------------------------------------------------------------
548
- + /*-------------------------------------------------------------------------
549
- *
550
- * selfuncs.c
551
- * Selectivity functions and index cost estimation functions for
552
546
@@ -143,6 +143,7 @@
553
547
/* Hooks for plugins to get control when we ask for stats */
554
548
get_relation_stats_hook_type get_relation_stats_hook = NULL;
@@ -557,28 +551,29 @@ index 962dec6d504..899ee2bf4c5 100644
557
551
558
552
static double eqsel_internal(PG_FUNCTION_ARGS, bool negate);
559
553
static double eqjoinsel_inner(Oid opfuncoid, Oid collation,
560
- @@ -3293,6 +3294,19 @@ add_unique_group_var(PlannerInfo *root, List *varinfos,
554
+ @@ -3293,6 +3294,20 @@ add_unique_group_var(PlannerInfo *root, List *varinfos,
561
555
return varinfos;
562
556
}
563
557
564
558
+ double
565
559
+ estimate_num_groups_ext(PlannerInfo *root, List *groupExprs, Path *subpath,
566
- + RelOptInfo *grouped_rel, List **pgset)
560
+ + RelOptInfo *grouped_rel, List **pgset,
561
+ + EstimationInfo *estinfo)
567
562
+ {
568
563
+ double input_rows = subpath->rows;
569
564
+
570
565
+ if (estimate_num_groups_hook != NULL)
571
- + return (*estimate_num_groups_hook)(root, groupExprs, subpath,
572
- + grouped_rel, pgset );
566
+ + return (*estimate_num_groups_hook)(root, groupExprs, subpath, grouped_rel,
567
+ + pgset, estinfo );
573
568
+
574
- + return estimate_num_groups(root, groupExprs, input_rows, pgset, NULL );
569
+ + return estimate_num_groups(root, groupExprs, input_rows, pgset, estinfo );
575
570
+ }
576
571
+
577
572
/*
578
573
* estimate_num_groups - Estimate number of groups in a grouped query
579
574
*
580
575
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
581
- index e94d9e49cf6..49236ced77c 100644
576
+ index e94d9e49cf..49236ced77 100644
582
577
--- a/src/include/commands/explain.h
583
578
+++ b/src/include/commands/explain.h
584
579
@@ -75,6 +75,18 @@ extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
@@ -601,7 +596,7 @@ index e94d9e49cf6..49236ced77c 100644
601
596
extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
602
597
ParamListInfo params, DestReceiver *dest);
603
598
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
604
- index f16466a0df1..8f0ed706817 100644
599
+ index e370a01141..9f2f1628f5 100644
605
600
--- a/src/include/nodes/pathnodes.h
606
601
+++ b/src/include/nodes/pathnodes.h
607
602
@@ -756,6 +756,10 @@ typedef struct RelOptInfo
@@ -640,24 +635,21 @@ index f16466a0df1..8f0ed706817 100644
640
635
641
636
642
637
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
643
- index 2308c80ddee..dc74cf85bd2 100644
638
+ index 2308c80dde..a933afa483 100644
644
639
--- a/src/include/nodes/plannodes.h
645
640
+++ b/src/include/nodes/plannodes.h
646
- @@ -158,6 +158,12 @@ typedef struct Plan
641
+ @@ -158,6 +158,9 @@ typedef struct Plan
647
642
*/
648
643
Bitmapset *extParam;
649
644
Bitmapset *allParam;
650
645
+
651
- + /*
652
- + * Additional fields for an extension purposes.
653
- + * TODO: allow to serialize/deserialize this list.
654
- + */
646
+ + /* Additional field for an extension purposes. */
655
647
+ List *ext_nodes;
656
648
} Plan;
657
649
658
650
/* ----------------
659
651
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
660
- index 2113bc82de0..bcc2520cec5 100644
652
+ index 2113bc82de..bcc2520cec 100644
661
653
--- a/src/include/optimizer/cost.h
662
654
+++ b/src/include/optimizer/cost.h
663
655
@@ -39,6 +39,37 @@ typedef enum
@@ -741,7 +733,7 @@ index 2113bc82de0..bcc2520cec5 100644
741
733
742
734
#endif /* COST_H */
743
735
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
744
- index 2922c0cdc14..c59dce6989e 100644
736
+ index 2922c0cdc1..c59dce6989 100644
745
737
--- a/src/include/optimizer/pathnode.h
746
738
+++ b/src/include/optimizer/pathnode.h
747
739
@@ -18,6 +18,10 @@
@@ -756,7 +748,7 @@ index 2922c0cdc14..c59dce6989e 100644
756
748
* s for pathnode.c
757
749
*/
758
750
diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h
759
- index bf1adfc52ac..9c78e0f4e02 100644
751
+ index bf1adfc52a..9c78e0f4e0 100644
760
752
--- a/src/include/optimizer/planmain.h
761
753
+++ b/src/include/optimizer/planmain.h
762
754
@@ -24,6 +24,12 @@ extern double cursor_tuple_fraction;
@@ -773,29 +765,30 @@ index bf1adfc52ac..9c78e0f4e02 100644
773
765
* s for plan/planmain.c
774
766
*/
775
767
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h
776
- index 9dd444e1ff5..37133340d84 100644
768
+ index 9dd444e1ff..cfaae98aa2 100644
777
769
--- a/src/include/utils/selfuncs.h
778
770
+++ b/src/include/utils/selfuncs.h
779
- @@ -144,6 +144,12 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,
771
+ @@ -144,6 +144,13 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,
780
772
AttrNumber indexattnum,
781
773
VariableStatData *vardata);
782
774
extern PGDLLIMPORT get_index_stats_hook_type get_index_stats_hook;
783
775
+ typedef double (*estimate_num_groups_hook_type) (PlannerInfo *root,
784
776
+ List *groupExprs,
785
777
+ Path *subpath,
786
778
+ RelOptInfo *grouped_rel,
787
- + List **pgset);
779
+ + List **pgset,
780
+ + EstimationInfo *estinfo);
788
781
+ extern PGDLLIMPORT estimate_num_groups_hook_type estimate_num_groups_hook;
789
782
790
783
/* Functions in selfuncs.c */
791
784
792
- @@ -213,6 +219 ,9 @@ extern void mergejoinscansel(PlannerInfo *root, Node *clause,
785
+ @@ -213,6 +220 ,9 @@ extern void mergejoinscansel(PlannerInfo *root, Node *clause,
793
786
extern double estimate_num_groups(PlannerInfo *root, List *groupExprs,
794
787
double input_rows, List **pgset,
795
788
EstimationInfo *estinfo);
796
789
+ extern double estimate_num_groups_ext(PlannerInfo *root, List *groupExprs,
797
790
+ Path *subpath, RelOptInfo *grouped_rel,
798
- + List **pgset);
791
+ + List **pgset, EstimationInfo *estinfo );
799
792
800
793
extern void estimate_hash_bucket_stats(PlannerInfo *root,
801
794
Node *hashkey, double nbuckets,
0 commit comments