Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a3e8286

Browse files
author
Daniil Anisimov
committed
Fix testing with WRITE_READ_PARSE_PLAN_TREES.
Change RestrictInfo to AQOClause. Add AQOConstNode to use it instead of useless nodes. Serialize/deserialize all AQOPlanNode and AQOConstNode fields.
1 parent 52d586e commit a3e8286

File tree

6 files changed

+430
-141
lines changed

6 files changed

+430
-141
lines changed

aqo_pg13.patch

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/contrib/Makefile b/contrib/Makefile
2-
index 1846d415b6..95519ac11d 100644
2+
index 1846d415b6f..95519ac11de 100644
33
--- a/contrib/Makefile
44
+++ b/contrib/Makefile
55
@@ -7,6 +7,7 @@ include $(top_builddir)/src/Makefile.global
@@ -11,7 +11,7 @@ index 1846d415b6..95519ac11d 100644
1111
auto_explain \
1212
bloom \
1313
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
14-
index bc05c96b4c..b6a3abe0d2 100644
14+
index bc05c96b4ce..b6a3abe0d2b 100644
1515
--- a/src/backend/commands/explain.c
1616
+++ b/src/backend/commands/explain.c
1717
@@ -24,6 +24,7 @@
@@ -57,7 +57,7 @@ index bc05c96b4c..b6a3abe0d2 100644
5757
if (es->format == EXPLAIN_FORMAT_TEXT)
5858
appendStringInfoChar(es->str, '\n');
5959
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
60-
index 692b6c1559..580d04d784 100644
60+
index 692b6c1559f..580d04d7844 100644
6161
--- a/src/backend/nodes/copyfuncs.c
6262
+++ b/src/backend/nodes/copyfuncs.c
6363
@@ -132,6 +132,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
@@ -69,35 +69,31 @@ index 692b6c1559..580d04d784 100644
6969

7070
/*
7171
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
72-
index 21ececf0c2..a0e7a7ebca 100644
72+
index 21ececf0c2f..ebfd3ba86de 100644
7373
--- a/src/backend/nodes/outfuncs.c
7474
+++ b/src/backend/nodes/outfuncs.c
7575
@@ -342,6 +342,7 @@ _outPlanInfo(StringInfo str, const Plan *node)
7676
WRITE_NODE_FIELD(initPlan);
7777
WRITE_BITMAPSET_FIELD(extParam);
7878
WRITE_BITMAPSET_FIELD(allParam);
79-
+ /*WRITE_NODE_FIELD(ext_nodes); */
79+
+ WRITE_NODE_FIELD(ext_nodes);
8080
}
8181

8282
/*
8383
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
84-
index 7976b369ba..604314e0b3 100644
84+
index 7976b369ba8..2e47bd8d950 100644
8585
--- a/src/backend/nodes/readfuncs.c
8686
+++ b/src/backend/nodes/readfuncs.c
87-
@@ -1580,6 +1580,11 @@ ReadCommonPlan(Plan *local_node)
87+
@@ -1580,6 +1580,7 @@ ReadCommonPlan(Plan *local_node)
8888
READ_NODE_FIELD(initPlan);
8989
READ_BITMAPSET_FIELD(extParam);
9090
READ_BITMAPSET_FIELD(allParam);
91-
+ local_node->ext_nodes = NIL;
92-
+ /* READ_NODE_FIELD(ext_nodes);
93-
+ * Don't serialize this field. It is required to serialize RestrictInfo and
94-
+ * EqualenceClass.
95-
+ */
91+
+ READ_NODE_FIELD(ext_nodes);
9692
}
9793

9894
/*
9995
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
100-
index 4edc859cb5..988f2e6ab7 100644
96+
index 4edc859cb57..988f2e6ab75 100644
10197
--- a/src/backend/optimizer/path/costsize.c
10298
+++ b/src/backend/optimizer/path/costsize.c
10399
@@ -98,6 +98,12 @@
@@ -363,7 +359,7 @@ index 4edc859cb5..988f2e6ab7 100644
363359
{
364360
double parallel_divisor = path->parallel_workers;
365361
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
366-
index 917713c163..5b7bf1cec6 100644
362+
index 917713c1633..5b7bf1cec69 100644
367363
--- a/src/backend/optimizer/plan/createplan.c
368364
+++ b/src/backend/optimizer/plan/createplan.c
369365
@@ -70,6 +70,7 @@
@@ -394,7 +390,7 @@ index 917713c163..5b7bf1cec6 100644
394390

395391
/*
396392
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
397-
index 27c665ac12..f599fba755 100644
393+
index 821693c60ee..fa627f472f9 100644
398394
--- a/src/backend/optimizer/plan/planner.c
399395
+++ b/src/backend/optimizer/plan/planner.c
400396
@@ -145,7 +145,8 @@ static List *extract_rollup_sets(List *groupingSets);
@@ -407,7 +403,7 @@ index 27c665ac12..f599fba755 100644
407403
grouping_sets_data *gd,
408404
List *target_list);
409405
static RelOptInfo *create_grouping_paths(PlannerInfo *root,
410-
@@ -3686,7 +3687,8 @@ standard_qp_callback(PlannerInfo *root, void *extra)
406+
@@ -3682,7 +3683,8 @@ standard_qp_callback(PlannerInfo *root, void *extra)
411407
*/
412408
static double
413409
get_number_of_groups(PlannerInfo *root,
@@ -417,7 +413,7 @@ index 27c665ac12..f599fba755 100644
417413
grouping_sets_data *gd,
418414
List *target_list)
419415
{
420-
@@ -3723,7 +3725,7 @@ get_number_of_groups(PlannerInfo *root,
416+
@@ -3719,7 +3721,7 @@ get_number_of_groups(PlannerInfo *root,
421417
GroupingSetData *gs = lfirst_node(GroupingSetData, lc2);
422418
double numGroups = estimate_num_groups(root,
423419
groupExprs,
@@ -426,7 +422,7 @@ index 27c665ac12..f599fba755 100644
426422
&gset);
427423

428424
gs->numGroups = numGroups;
429-
@@ -3748,7 +3750,7 @@ get_number_of_groups(PlannerInfo *root,
425+
@@ -3744,7 +3746,7 @@ get_number_of_groups(PlannerInfo *root,
430426
GroupingSetData *gs = lfirst_node(GroupingSetData, lc2);
431427
double numGroups = estimate_num_groups(root,
432428
groupExprs,
@@ -435,7 +431,7 @@ index 27c665ac12..f599fba755 100644
435431
&gset);
436432

437433
gs->numGroups = numGroups;
438-
@@ -3764,8 +3766,8 @@ get_number_of_groups(PlannerInfo *root,
434+
@@ -3760,8 +3762,8 @@ get_number_of_groups(PlannerInfo *root,
439435
groupExprs = get_sortgrouplist_exprs(parse->groupClause,
440436
target_list);
441437

@@ -446,7 +442,7 @@ index 27c665ac12..f599fba755 100644
446442
}
447443
}
448444
else if (parse->groupingSets)
449-
@@ -4151,7 +4153,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
445+
@@ -4147,7 +4149,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
450446
* Estimate number of groups.
451447
*/
452448
dNumGroups = get_number_of_groups(root,
@@ -456,7 +452,7 @@ index 27c665ac12..f599fba755 100644
456452
gd,
457453
extra->targetList);
458454

459-
@@ -6935,13 +6938,15 @@ create_partial_grouping_paths(PlannerInfo *root,
455+
@@ -6931,13 +6934,15 @@ create_partial_grouping_paths(PlannerInfo *root,
460456
if (cheapest_total_path != NULL)
461457
dNumPartialGroups =
462458
get_number_of_groups(root,
@@ -475,7 +471,7 @@ index 27c665ac12..f599fba755 100644
475471
extra->targetList);
476472

477473
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
478-
index a203e6f1ff..d31bf5bae6 100644
474+
index a203e6f1ff5..d31bf5bae63 100644
479475
--- a/src/backend/optimizer/util/relnode.c
480476
+++ b/src/backend/optimizer/util/relnode.c
481477
@@ -258,6 +258,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
@@ -541,7 +537,7 @@ index a203e6f1ff..d31bf5bae6 100644
541537

542538
return ppi;
543539
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
544-
index 37458da096..248a1875a1 100644
540+
index 37458da096d..248a1875a18 100644
545541
--- a/src/backend/utils/adt/selfuncs.c
546542
+++ b/src/backend/utils/adt/selfuncs.c
547543
@@ -147,6 +147,7 @@
@@ -573,7 +569,7 @@ index 37458da096..248a1875a1 100644
573569
* estimate_num_groups - Estimate number of groups in a grouped query
574570
*
575571
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
576-
index ba661d32a6..09d0abe58b 100644
572+
index ba661d32a63..09d0abe58be 100644
577573
--- a/src/include/commands/explain.h
578574
+++ b/src/include/commands/explain.h
579575
@@ -75,6 +75,18 @@ extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
@@ -596,7 +592,7 @@ index ba661d32a6..09d0abe58b 100644
596592
extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
597593
ParamListInfo params, DestReceiver *dest);
598594
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
599-
index 5ebf070979..5b2acd7de2 100644
595+
index d2b4271de9d..559b9db7121 100644
600596
--- a/src/include/nodes/pathnodes.h
601597
+++ b/src/include/nodes/pathnodes.h
602598
@@ -739,6 +739,10 @@ typedef struct RelOptInfo
@@ -635,7 +631,7 @@ index 5ebf070979..5b2acd7de2 100644
635631

636632

637633
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
638-
index 90f02ce6fd..88c332164d 100644
634+
index 90f02ce6fdd..88c332164dd 100644
639635
--- a/src/include/nodes/plannodes.h
640636
+++ b/src/include/nodes/plannodes.h
641637
@@ -159,6 +159,9 @@ typedef struct Plan
@@ -649,7 +645,7 @@ index 90f02ce6fd..88c332164d 100644
649645

650646
/* ----------------
651647
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
652-
index 6141654e47..e6b28cbb05 100644
648+
index 6141654e478..e6b28cbb05f 100644
653649
--- a/src/include/optimizer/cost.h
654650
+++ b/src/include/optimizer/cost.h
655651
@@ -39,6 +39,37 @@ typedef enum
@@ -733,7 +729,7 @@ index 6141654e47..e6b28cbb05 100644
733729

734730
#endif /* COST_H */
735731
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
736-
index 3bd7072ae8..21bbaba11c 100644
732+
index 3bd7072ae8c..21bbaba11c8 100644
737733
--- a/src/include/optimizer/pathnode.h
738734
+++ b/src/include/optimizer/pathnode.h
739735
@@ -18,6 +18,10 @@
@@ -748,7 +744,7 @@ index 3bd7072ae8..21bbaba11c 100644
748744
* prototypes for pathnode.c
749745
*/
750746
diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h
751-
index 8ce60e202e..75415102c2 100644
747+
index 8ce60e202e5..75415102c2e 100644
752748
--- a/src/include/optimizer/planmain.h
753749
+++ b/src/include/optimizer/planmain.h
754750
@@ -24,6 +24,12 @@ extern double cursor_tuple_fraction;
@@ -765,7 +761,7 @@ index 8ce60e202e..75415102c2 100644
765761
* prototypes for plan/planmain.c
766762
*/
767763
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h
768-
index 7ac4a06391..def3522881 100644
764+
index 7ac4a063915..74fe91b89f1 100644
769765
--- a/src/include/utils/selfuncs.h
770766
+++ b/src/include/utils/selfuncs.h
771767
@@ -127,6 +127,12 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,
@@ -781,13 +777,13 @@ index 7ac4a06391..def3522881 100644
781777

782778
/* Functions in selfuncs.c */
783779

784-
@@ -195,6 +201,9 @@ extern void mergejoinscansel(PlannerInfo *root, Node *clause,
780+
@@ -193,6 +199,9 @@ extern void mergejoinscansel(PlannerInfo *root, Node *clause,
781+
Selectivity *leftstart, Selectivity *leftend,
782+
Selectivity *rightstart, Selectivity *rightend);
785783

786-
extern double estimate_num_groups(PlannerInfo *root, List *groupExprs,
787-
double input_rows, List **pgset);
788784
+extern double estimate_num_groups_ext(PlannerInfo *root, List *groupExprs,
789785
+ Path *subpath, RelOptInfo *grouped_rel,
790786
+ List **pgset);
787+
extern double estimate_num_groups(PlannerInfo *root, List *groupExprs,
788+
double input_rows, List **pgset);
791789

792-
extern void estimate_hash_bucket_stats(PlannerInfo *root,
793-
Node *hashkey, double nbuckets,

cardinality_hooks.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
186186

187187
forboth(l, allclauses, l2, selectivities)
188188
{
189-
current_hash = get_clause_hash(
190-
((RestrictInfo *) lfirst(l))->clause,
189+
current_hash = get_clause_hash(((AQOClause *) lfirst(l))->clause,
191190
nargs, args_hash, eclass_hash);
192191
cache_selectivity(current_hash, rel->relid, rte->relid,
193192
*((double *) lfirst(l2)));

hash.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "aqo.h"
2929
#include "hash.h"
30+
#include "path_utils.h"
3031

3132
static int get_str_hash(const char *str);
3233
static int get_node_hash(Node *node);
@@ -236,11 +237,11 @@ get_fss_for_object(List *relsigns, List *clauselist,
236237
i = 0;
237238
foreach(lc, clauselist)
238239
{
239-
RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
240+
AQOClause *clause = (AQOClause *) lfirst(lc);
240241

241-
clause_hashes[i] = get_clause_hash(rinfo->clause,
242+
clause_hashes[i] = get_clause_hash(clause->clause,
242243
nargs, args_hash, eclass_hash);
243-
args = get_clause_args_ptr(rinfo->clause);
244+
args = get_clause_args_ptr(clause->clause);
244245
clause_has_consts[i] = (args != NULL && has_consts(*args));
245246
i++;
246247
}
@@ -335,14 +336,14 @@ get_clause_hash(Expr *clause, int nargs, int *args_hash, int *eclass_hash)
335336

336337
cclause = copyObject(clause);
337338
args = get_clause_args_ptr(cclause);
339+
/* XXX: Why does it work even if this loop is removed? */
338340
foreach(l, *args)
339341
{
340342
arg_eclass = get_arg_eclass(get_node_hash(lfirst(l)),
341343
nargs, args_hash, eclass_hash);
342344
if (arg_eclass != 0)
343345
{
344-
lfirst(l) = makeNode(Param);
345-
((Param *) lfirst(l))->paramid = arg_eclass;
346+
lfirst(l) = create_aqo_const_node(AQO_NODE_EXPR, arg_eclass);
346347
}
347348
}
348349
if (!clause_is_eq_clause(clause) || has_consts(*args))
@@ -572,7 +573,7 @@ get_arg_eclass(int arg_hash, int nargs, int *args_hash, int *eclass_hash)
572573
static void
573574
get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
574575
{
575-
RestrictInfo *rinfo;
576+
AQOClause *clause;
576577
List **args;
577578
ListCell *l;
578579
ListCell *l2;
@@ -582,9 +583,9 @@ get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
582583

583584
foreach(l, clauselist)
584585
{
585-
rinfo = (RestrictInfo *) lfirst(l);
586-
args = get_clause_args_ptr(rinfo->clause);
587-
if (args != NULL && clause_is_eq_clause(rinfo->clause))
586+
clause = (AQOClause *) lfirst(l);
587+
args = get_clause_args_ptr(clause->clause);
588+
if (args != NULL && clause_is_eq_clause(clause->clause))
588589
foreach(l2, *args)
589590
if (!IsA(lfirst(l2), Const))
590591
cnt++;
@@ -593,9 +594,9 @@ get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
593594
*args_hash = palloc(cnt * sizeof(**args_hash));
594595
foreach(l, clauselist)
595596
{
596-
rinfo = (RestrictInfo *) lfirst(l);
597-
args = get_clause_args_ptr(rinfo->clause);
598-
if (args != NULL && clause_is_eq_clause(rinfo->clause))
597+
clause = (AQOClause *) lfirst(l);
598+
args = get_clause_args_ptr(clause->clause);
599+
if (args != NULL && clause_is_eq_clause(clause->clause))
599600
foreach(l2, *args)
600601
if (!IsA(lfirst(l2), Const))
601602
(*args_hash)[i++] = get_node_hash(lfirst(l2));
@@ -650,7 +651,7 @@ disjoint_set_merge_eclasses(int *p, int v1, int v2)
650651
static int *
651652
perform_eclasses_join(List *clauselist, int nargs, int *args_hash)
652653
{
653-
RestrictInfo *rinfo;
654+
AQOClause *clause;
654655
int *p;
655656
ListCell *l,
656657
*l2;
@@ -664,9 +665,9 @@ perform_eclasses_join(List *clauselist, int nargs, int *args_hash)
664665

665666
foreach(l, clauselist)
666667
{
667-
rinfo = (RestrictInfo *) lfirst(l);
668-
args = get_clause_args_ptr(rinfo->clause);
669-
if (args != NULL && clause_is_eq_clause(rinfo->clause))
668+
clause = (AQOClause *) lfirst(l);
669+
args = get_clause_args_ptr(clause->clause);
670+
if (args != NULL && clause_is_eq_clause(clause->clause))
670671
{
671672
i3 = -1;
672673
foreach(l2, *args)

0 commit comments

Comments
 (0)