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

Commit b3aaf90

Browse files
committed
Rearrange planner to save the whole PlannerInfo (subroot) for a subquery.
Formerly, set_subquery_pathlist and other creators of plans for subqueries saved only the rangetable and rowMarks lists from the lower-level PlannerInfo. But there's no reason not to remember the whole PlannerInfo, and indeed this turns out to simplify matters in a number of places. The immediate reason for doing this was so that the subroot will still be accessible when we're trying to extract column statistics out of an already-planned subquery. But now that I've done it, it seems like a good code-beautification effort in its own right. I also chose to get rid of the transient subrtable and subrowmark fields in SubqueryScan nodes, in favor of having setrefs.c look up the subquery's RelOptInfo. That required changing all the APIs in setrefs.c to pass PlannerInfo not PlannerGlobal, which was a large but quite mechanical transformation. One side-effect not foreseen at the beginning is that this finally broke inheritance_planner's assumption that replanning the same subquery RTE N times would necessarily give interchangeable results each time. That assumption was always pretty risky, but now we really have to make a separate RTE for each instance so that there's a place to carry the separate subroots.
1 parent 42ad992 commit b3aaf90

File tree

19 files changed

+394
-304
lines changed

19 files changed

+394
-304
lines changed

src/backend/executor/nodeSubqueryscan.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,9 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
9999
/* check for unsupported flags */
100100
Assert(!(eflags & EXEC_FLAG_MARK));
101101

102-
/*
103-
* SubqueryScan should not have any "normal" children. Also, if planner
104-
* left anything in subrtable/subrowmark, it's fishy.
105-
*/
102+
/* SubqueryScan should not have any "normal" children */
106103
Assert(outerPlan(node) == NULL);
107104
Assert(innerPlan(node) == NULL);
108-
Assert(node->subrtable == NIL);
109-
Assert(node->subrowmark == NIL);
110105

111106
/*
112107
* create state structure

src/backend/nodes/copyfuncs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,6 @@ _copySubqueryScan(SubqueryScan *from)
456456
* copy remainder of node
457457
*/
458458
COPY_NODE_FIELD(subplan);
459-
COPY_NODE_FIELD(subrtable);
460-
COPY_NODE_FIELD(subrowmark);
461459

462460
return newnode;
463461
}

src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ _outSubqueryScan(StringInfo str, SubqueryScan *node)
489489
_outScanInfo(str, (Scan *) node);
490490

491491
WRITE_NODE_FIELD(subplan);
492-
WRITE_NODE_FIELD(subrtable);
493-
WRITE_NODE_FIELD(subrowmark);
494492
}
495493

496494
static void
@@ -1656,8 +1654,7 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
16561654
/* NB: this isn't a complete set of fields */
16571655
WRITE_NODE_FIELD(paramlist);
16581656
WRITE_NODE_FIELD(subplans);
1659-
WRITE_NODE_FIELD(subrtables);
1660-
WRITE_NODE_FIELD(subrowmarks);
1657+
WRITE_NODE_FIELD(subroots);
16611658
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
16621659
WRITE_NODE_FIELD(finalrtable);
16631660
WRITE_NODE_FIELD(finalrowmarks);
@@ -1734,8 +1731,7 @@ _outRelOptInfo(StringInfo str, RelOptInfo *node)
17341731
WRITE_UINT_FIELD(pages);
17351732
WRITE_FLOAT_FIELD(tuples, "%.0f");
17361733
WRITE_NODE_FIELD(subplan);
1737-
WRITE_NODE_FIELD(subrtable);
1738-
WRITE_NODE_FIELD(subrowmark);
1734+
WRITE_NODE_FIELD(subroot);
17391735
WRITE_NODE_FIELD(baserestrictinfo);
17401736
WRITE_NODE_FIELD(joininfo);
17411737
WRITE_BOOL_FIELD(has_eclass_joins);

src/backend/optimizer/path/allpaths.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,10 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
791791
root,
792792
false, tuple_fraction,
793793
&subroot);
794-
rel->subrtable = subroot->parse->rtable;
795-
rel->subrowmark = subroot->rowMarks;
794+
rel->subroot = subroot;
796795

797796
/* Mark rel with estimated output rows, width, etc */
798-
set_subquery_size_estimates(root, rel, subroot);
797+
set_subquery_size_estimates(root, rel);
799798

800799
/* Convert subquery pathkeys to outer representation */
801800
pathkeys = convert_subquery_pathkeys(root, rel, subroot->query_pathkeys);

src/backend/optimizer/path/costsize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,9 +3221,9 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
32213221
* We set the same fields as set_baserel_size_estimates.
32223222
*/
32233223
void
3224-
set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel,
3225-
PlannerInfo *subroot)
3224+
set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
32263225
{
3226+
PlannerInfo *subroot = rel->subroot;
32273227
RangeTblEntry *rte;
32283228
ListCell *lc;
32293229

src/backend/optimizer/plan/createplan.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,9 +1557,7 @@ create_subqueryscan_plan(PlannerInfo *root, Path *best_path,
15571557
scan_plan = make_subqueryscan(tlist,
15581558
scan_clauses,
15591559
scan_relid,
1560-
best_path->parent->subplan,
1561-
best_path->parent->subrtable,
1562-
best_path->parent->subrowmark);
1560+
best_path->parent->subplan);
15631561

15641562
copy_path_costsize(&scan_plan->scan.plan, best_path);
15651563

@@ -2931,9 +2929,7 @@ SubqueryScan *
29312929
make_subqueryscan(List *qptlist,
29322930
List *qpqual,
29332931
Index scanrelid,
2934-
Plan *subplan,
2935-
List *subrtable,
2936-
List *subrowmark)
2932+
Plan *subplan)
29372933
{
29382934
SubqueryScan *node = makeNode(SubqueryScan);
29392935
Plan *plan = &node->scan.plan;
@@ -2952,8 +2948,6 @@ make_subqueryscan(List *qptlist,
29522948
plan->righttree = NULL;
29532949
node->scan.scanrelid = scanrelid;
29542950
node->subplan = subplan;
2955-
node->subrtable = subrtable;
2956-
node->subrowmark = subrowmark;
29572951

29582952
return node;
29592953
}

src/backend/optimizer/plan/planmain.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ query_planner(PlannerInfo *root, List *tlist,
9898
Path *cheapestpath;
9999
Path *sortedpath;
100100
Index rti;
101-
ListCell *lc;
102101
double total_pages;
103102

104103
/* Make tuple_fraction, limit_tuples accessible to lower-level routines */
@@ -128,15 +127,11 @@ query_planner(PlannerInfo *root, List *tlist,
128127
}
129128

130129
/*
131-
* Init planner lists to empty, and set up the array to hold RelOptInfos
132-
* for "simple" rels.
130+
* Init planner lists to empty.
133131
*
134132
* NOTE: append_rel_list was set up by subquery_planner, so do not touch
135133
* here; eq_classes and minmax_aggs may contain data already, too.
136134
*/
137-
root->simple_rel_array_size = list_length(parse->rtable) + 1;
138-
root->simple_rel_array = (RelOptInfo **)
139-
palloc0(root->simple_rel_array_size * sizeof(RelOptInfo *));
140135
root->join_rel_list = NIL;
141136
root->join_rel_hash = NULL;
142137
root->join_rel_level = NULL;
@@ -151,17 +146,10 @@ query_planner(PlannerInfo *root, List *tlist,
151146

152147
/*
153148
* Make a flattened version of the rangetable for faster access (this is
154-
* OK because the rangetable won't change any more).
149+
* OK because the rangetable won't change any more), and set up an
150+
* empty array for indexing base relations.
155151
*/
156-
root->simple_rte_array = (RangeTblEntry **)
157-
palloc0(root->simple_rel_array_size * sizeof(RangeTblEntry *));
158-
rti = 1;
159-
foreach(lc, parse->rtable)
160-
{
161-
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
162-
163-
root->simple_rte_array[rti++] = rte;
164-
}
152+
setup_simple_rel_arrays(root);
165153

166154
/*
167155
* Construct RelOptInfo nodes for all base relations in query, and

0 commit comments

Comments
 (0)