Skip to content

Commit 4c65110

Browse files
committed
Bugfix: we can't use C++ reserved words as identifiers for shared variables or
routines.
1 parent 42a425a commit 4c65110

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

aqo_pg14.patch

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ index f27e458482..0c62191904 100644
1111
auto_explain \
1212
bloom \
1313
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
14-
index 69821c4631..f1fd5f93c5 100644
14+
index 70551522da..958529fbab 100644
1515
--- a/src/backend/commands/explain.c
1616
+++ b/src/backend/commands/explain.c
1717
@@ -24,6 +24,7 @@
@@ -35,7 +35,7 @@ index 69821c4631..f1fd5f93c5 100644
3535

3636
/* OR-able flags for ExplainXMLTag() */
3737
#define X_OPENING 0
38-
@@ -670,6 +677,10 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
38+
@@ -676,6 +683,10 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
3939
ExplainPropertyFloat("Execution Time", "ms", 1000.0 * totaltime, 3,
4040
es);
4141

@@ -46,7 +46,7 @@ index 69821c4631..f1fd5f93c5 100644
4646
ExplainCloseGroup("Query", NULL, true, es);
4747
}
4848

49-
@@ -1652,6 +1663,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
49+
@@ -1658,6 +1669,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
5050
}
5151
}
5252

@@ -57,47 +57,47 @@ index 69821c4631..f1fd5f93c5 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 5769536c6a..8aae9d5039 100644
60+
index a106a2cdf1..7150dccb4d 100644
6161
--- a/src/backend/nodes/copyfuncs.c
6262
+++ b/src/backend/nodes/copyfuncs.c
63-
@@ -129,6 +129,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
63+
@@ -132,6 +132,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
6464
COPY_NODE_FIELD(initPlan);
6565
COPY_BITMAPSET_FIELD(extParam);
6666
COPY_BITMAPSET_FIELD(allParam);
67-
+ COPY_NODE_FIELD(private);
67+
+ COPY_NODE_FIELD(ext_nodes);
6868
}
6969

7070
/*
7171
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
72-
index da212d9ddf..78dc137df8 100644
72+
index 0df9be1608..678e1f050f 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(private); */
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 4c537c30e0..40b1ce29de 100644
84+
index eaa51c5c06..6ad8b78c7d 100644
8585
--- a/src/backend/nodes/readfuncs.c
8686
+++ b/src/backend/nodes/readfuncs.c
8787
@@ -1628,6 +1628,11 @@ ReadCommonPlan(Plan *local_node)
8888
READ_NODE_FIELD(initPlan);
8989
READ_BITMAPSET_FIELD(extParam);
9090
READ_BITMAPSET_FIELD(allParam);
91-
+ local_node->private = NIL;
92-
+ /* READ_NODE_FIELD(private);
91+
+ local_node->ext_nodes = NIL;
92+
+ /* READ_NODE_FIELD(ext_nodes);
9393
+ * Don't serialize this field. It is required to serialize RestrictInfo and
9494
+ * EqualenceClass.
9595
+ */
9696
}
9797

9898
/*
9999
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
100-
index 30c8595f76..18699564b3 100644
100+
index 006f91f0a8..ef9c8ec581 100644
101101
--- a/src/backend/optimizer/path/costsize.c
102102
+++ b/src/backend/optimizer/path/costsize.c
103103
@@ -98,6 +98,11 @@
@@ -120,7 +120,7 @@ index 30c8595f76..18699564b3 100644
120120

121121

122122
/*
123-
@@ -4905,6 +4909,58 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
123+
@@ -4911,6 +4915,58 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
124124
}
125125

126126

@@ -179,7 +179,7 @@ index 30c8595f76..18699564b3 100644
179179
/*
180180
* set_baserel_size_estimates
181181
* Set the size estimates for the given base relation.
182-
@@ -4921,19 +4977,10 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
182+
@@ -4927,19 +4983,10 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
183183
void
184184
set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
185185
{
@@ -200,7 +200,7 @@ index 30c8595f76..18699564b3 100644
200200

201201
cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root);
202202

203-
@@ -4944,13 +4991,33 @@ set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
203+
@@ -4950,13 +4997,33 @@ set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
204204
* get_parameterized_baserel_size
205205
* Make a size estimate for a parameterized scan of a base relation.
206206
*
@@ -236,7 +236,7 @@ index 30c8595f76..18699564b3 100644
236236
{
237237
List *allclauses;
238238
double nrows;
239-
@@ -4979,6 +5046,36 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
239+
@@ -4985,6 +5052,36 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
240240
* set_joinrel_size_estimates
241241
* Set the size estimates for the given join relation.
242242
*
@@ -273,7 +273,7 @@ index 30c8595f76..18699564b3 100644
273273
* The rel's targetlist must have been constructed already, and a
274274
* restriction clause list that matches the given component rels must
275275
* be provided.
276-
@@ -4998,11 +5095,11 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
276+
@@ -5004,11 +5101,11 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
277277
* build_joinrel_tlist, and baserestrictcost is not used for join rels.
278278
*/
279279
void
@@ -290,7 +290,7 @@ index 30c8595f76..18699564b3 100644
290290
{
291291
rel->rows = calc_joinrel_size_estimate(root,
292292
rel,
293-
@@ -5018,6 +5115,35 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
293+
@@ -5024,6 +5121,35 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
294294
* get_parameterized_joinrel_size
295295
* Make a size estimate for a parameterized scan of a join relation.
296296
*
@@ -326,7 +326,7 @@ index 30c8595f76..18699564b3 100644
326326
* 'rel' is the joinrel under consideration.
327327
* 'outer_path', 'inner_path' are (probably also parameterized) Paths that
328328
* produce the relations being joined.
329-
@@ -5030,11 +5156,11 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
329+
@@ -5036,11 +5162,11 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
330330
* set_joinrel_size_estimates must have been applied already.
331331
*/
332332
double
@@ -343,7 +343,7 @@ index 30c8595f76..18699564b3 100644
343343
{
344344
double nrows;
345345

346-
@@ -5750,7 +5876,7 @@ set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
346+
@@ -5756,7 +5882,7 @@ set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
347347
/* Should only be applied to base relations */
348348
Assert(rel->relid > 0);
349349

@@ -352,7 +352,7 @@ index 30c8595f76..18699564b3 100644
352352

353353
cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root);
354354

355-
@@ -6036,7 +6162,7 @@ page_size(double tuples, int width)
355+
@@ -6042,7 +6168,7 @@ page_size(double tuples, int width)
356356
* Estimate the fraction of the work that each worker will do given the
357357
* number of workers budgeted for the path.
358358
*/
@@ -362,7 +362,7 @@ index 30c8595f76..18699564b3 100644
362362
{
363363
double parallel_divisor = path->parallel_workers;
364364
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
365-
index 5658f24323..3bbfa3c1b5 100644
365+
index 0ed858f305..9d4a6c5903 100644
366366
--- a/src/backend/optimizer/plan/createplan.c
367367
+++ b/src/backend/optimizer/plan/createplan.c
368368
@@ -71,6 +71,7 @@
@@ -373,7 +373,7 @@ index 5658f24323..3bbfa3c1b5 100644
373373

374374
static Plan *create_plan_recurse(PlannerInfo *root, Path *best_path,
375375
int flags);
376-
@@ -544,6 +545,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
376+
@@ -545,6 +546,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
377377
break;
378378
}
379379

@@ -384,11 +384,11 @@ index 5658f24323..3bbfa3c1b5 100644
384384
return plan;
385385
}
386386

387-
@@ -5278,6 +5283,7 @@ copy_generic_path_info(Plan *dest, Path *src)
387+
@@ -5323,6 +5328,7 @@ copy_generic_path_info(Plan *dest, Path *src)
388388
dest->plan_width = src->pathtarget->width;
389389
dest->parallel_aware = src->parallel_aware;
390390
dest->parallel_safe = src->parallel_safe;
391-
+ dest->private = NIL;
391+
+ dest->ext_nodes = NIL;
392392
}
393393

394394
/*
@@ -474,14 +474,14 @@ index 70899e5430..34075cc87b 100644
474474
extra->targetList);
475475

476476
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
477-
index e105a4d5f1..d821ea63bd 100644
477+
index e105a4d5f1..c5bcc9d1d1 100644
478478
--- a/src/backend/optimizer/util/relnode.c
479479
+++ b/src/backend/optimizer/util/relnode.c
480480
@@ -258,6 +258,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
481481
rel->all_partrels = NULL;
482482
rel->partexprs = NULL;
483483
rel->nullable_partexprs = NULL;
484-
+ rel->private = NULL;
484+
+ rel->ext_nodes = NULL;
485485

486486
/*
487487
* Pass assorted information down the inheritance hierarchy.
@@ -497,15 +497,15 @@ index e105a4d5f1..d821ea63bd 100644
497497
joinrel->all_partrels = NULL;
498498
joinrel->partexprs = NULL;
499499
joinrel->nullable_partexprs = NULL;
500-
+ joinrel->private = NULL;
500+
+ joinrel->ext_nodes = NULL;
501501

502502
/* Compute information relevant to the foreign relations. */
503503
set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
504504
@@ -850,6 +851,7 @@ build_child_join_rel(PlannerInfo *root, RelOptInfo *outer_rel,
505505
joinrel->all_partrels = NULL;
506506
joinrel->partexprs = NULL;
507507
joinrel->nullable_partexprs = NULL;
508-
+ joinrel->private = NULL;
508+
+ joinrel->ext_nodes = NULL;
509509

510510
joinrel->top_parent_relids = bms_union(outer_rel->top_parent_relids,
511511
inner_rel->top_parent_relids);
@@ -540,7 +540,7 @@ index e105a4d5f1..d821ea63bd 100644
540540

541541
return ppi;
542542
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
543-
index 10895fb287..e81a6f6896 100644
543+
index abe47dab86..0ef5f2c8da 100644
544544
--- a/src/backend/utils/adt/selfuncs.c
545545
+++ b/src/backend/utils/adt/selfuncs.c
546546
@@ -143,6 +143,7 @@
@@ -596,10 +596,10 @@ index e94d9e49cf..49236ced77 100644
596596
extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
597597
ParamListInfo params, DestReceiver *dest);
598598
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
599-
index 8ee40cc68c..d7bb9df67c 100644
599+
index f16466a0df..c48d969ba8 100644
600600
--- a/src/include/nodes/pathnodes.h
601601
+++ b/src/include/nodes/pathnodes.h
602-
@@ -755,6 +755,10 @@ typedef struct RelOptInfo
602+
@@ -756,6 +756,10 @@ typedef struct RelOptInfo
603603
Relids top_parent_relids; /* Relids of topmost parents (if "other"
604604
* rel) */
605605

@@ -610,18 +610,22 @@ index 8ee40cc68c..d7bb9df67c 100644
610610
/* used for partitioned relations: */
611611
PartitionScheme part_scheme; /* Partitioning scheme */
612612
int nparts; /* Number of partitions; -1 if not yet set; in
613-
@@ -769,7 +773,9 @@ typedef struct RelOptInfo
613+
@@ -770,7 +774,13 @@ typedef struct RelOptInfo
614614
Relids all_partrels; /* Relids set of all partition relids */
615615
List **partexprs; /* Non-nullable partition key expressions */
616616
List **nullable_partexprs; /* Nullable partition key expressions */
617617
-} RelOptInfo;
618618
+
619-
+ List *private;
619+
+ /*
620+
+ * At this list an extension can add additional nodes to pass an info along
621+
+ * the planning and executing stages.
622+
+ */
623+
+ List *ext_nodes;
620624
+} RelOptInfo;
621625

622626
/*
623627
* Is given relation partitioned?
624-
@@ -1137,6 +1143,10 @@ typedef struct ParamPathInfo
628+
@@ -1138,6 +1148,10 @@ typedef struct ParamPathInfo
625629
Relids ppi_req_outer; /* rels supplying parameters used by path */
626630
double ppi_rows; /* estimated number of result tuples */
627631
List *ppi_clauses; /* join clauses available from outer rels */
@@ -633,16 +637,19 @@ index 8ee40cc68c..d7bb9df67c 100644
633637

634638

635639
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
636-
index 5ddf947971..fe9bda387a 100644
640+
index 9ac4d9af12..6e20cd28c8 100644
637641
--- a/src/include/nodes/plannodes.h
638642
+++ b/src/include/nodes/plannodes.h
639-
@@ -158,6 +158,9 @@ typedef struct Plan
643+
@@ -158,6 +158,12 @@ typedef struct Plan
640644
*/
641645
Bitmapset *extParam;
642646
Bitmapset *allParam;
643647
+
644-
+ /* Additional field for an extension purposes. */
645-
+ List *private;
648+
+ /*
649+
+ * Additional fields for purposes of an extension.
650+
+ * TODO: allow to serialize/deserialize this list.
651+
+ */
652+
+ List *ext_nodes;
646653
} Plan;
647654

648655
/* ----------------

path_utils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ get_aqo_plan_node(Plan *plan, bool create)
6868
AQOPlanNode *node = NULL;
6969
ListCell *lc;
7070

71-
foreach(lc, plan->private)
71+
foreach(lc, plan->ext_nodes)
7272
{
7373
AQOPlanNode *candidate = (AQOPlanNode *) lfirst(lc);
7474

@@ -88,7 +88,7 @@ get_aqo_plan_node(Plan *plan, bool create)
8888
return &DefaultAQOPlanNode;
8989

9090
node = create_aqo_plan_node();
91-
plan->private = lappend(plan->private, node);
91+
plan->ext_nodes = lappend(plan->ext_nodes, node);
9292
}
9393

9494
Assert(node);
@@ -176,10 +176,10 @@ subplan_hunter(Node *node, void *context)
176176
splan->plan_id - 1);
177177
upper_rel = fetch_upper_rel(subroot, UPPERREL_FINAL, NULL);
178178

179-
Assert(list_length(upper_rel->private) == 1);
180-
Assert(IsA((Node *) linitial(upper_rel->private), A_Const));
179+
Assert(list_length(upper_rel->ext_nodes) == 1);
180+
Assert(IsA((Node *) linitial(upper_rel->ext_nodes), A_Const));
181181

182-
fss = (A_Const *) linitial(upper_rel->private);
182+
fss = (A_Const *) linitial(upper_rel->ext_nodes);
183183
return (Node *) copyObject(fss);
184184
}
185185
return expression_tree_mutator(node, subplan_hunter, context);
@@ -649,5 +649,5 @@ aqo_store_upper_signature_hook(PlannerInfo *root,
649649
fss_node->val.type = T_Integer;
650650
fss_node->location = -1;
651651
fss_node->val.val.ival = get_fss_for_object(relids, clauses, NIL, NULL, NULL);
652-
output_rel->private = lappend(output_rel->private, (void *) fss_node);
652+
output_rel->ext_nodes = lappend(output_rel->ext_nodes, (void *) fss_node);
653653
}

0 commit comments

Comments
 (0)