Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1661a40

Browse files
committed
Cosmetic improvements in setup of planner's per-RTE arrays.
Merge setup_append_rel_array into setup_simple_rel_arrays. There's noparticularly good reason to keep them separate, and it's inconsistentwith the lack of separation in expand_planner_arrays. The only apparentbenefit was that the fast path for trivial queries in query_planner()doesn't need to set up the append_rel_array; but all we're saving thereis an if-test and NULL assignment, which surely ought to be negligible.Also improve some obsolete comments.Discussion:https://postgr.es/m/17220.1565301350@sss.pgh.pa.us
1 parentb8f2da0 commit1661a40

File tree

5 files changed

+34
-47
lines changed

5 files changed

+34
-47
lines changed

‎src/backend/optimizer/plan/planmain.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ query_planner(PlannerInfo *root,
7979
root->initial_rels=NIL;
8080

8181
/*
82-
* Make a flattened version of the rangetable for faster access (this is
83-
* OK because the rangetable won't change any more), and set up an empty
84-
* array for indexing base relations.
82+
* Set up arrays for accessing base relations and AppendRelInfos.
8583
*/
8684
setup_simple_rel_arrays(root);
8785

@@ -156,12 +154,6 @@ query_planner(PlannerInfo *root,
156154
}
157155
}
158156

159-
/*
160-
* Populate append_rel_array with each AppendRelInfo to allow direct
161-
* lookups by child relid.
162-
*/
163-
setup_append_rel_array(root);
164-
165157
/*
166158
* Construct RelOptInfo nodes for all base relations used in the query.
167159
* Appendrel member relations ("other rels") will be added later.

‎src/backend/optimizer/prep/prepunion.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,10 @@ plan_set_operations(PlannerInfo *root)
132132
/*
133133
* We'll need to build RelOptInfos for each of the leaf subqueries, which
134134
* are RTE_SUBQUERY rangetable entries in this Query. Prepare the index
135-
* arrays forthat.
135+
* arrays forthose, and for AppendRelInfos in case they're needed.
136136
*/
137137
setup_simple_rel_arrays(root);
138138

139-
/*
140-
* Populate append_rel_array with each AppendRelInfo to allow direct
141-
* lookups by child relid.
142-
*/
143-
setup_append_rel_array(root);
144-
145139
/*
146140
* Find the leftmost component Query. We need to use its column names for
147141
* all generated tlists (else SELECT INTO won't work right).

‎src/backend/optimizer/util/relnode.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,46 +67,39 @@ static void build_child_join_reltarget(PlannerInfo *root,
6767

6868
/*
6969
* setup_simple_rel_arrays
70-
* Prepare the arrays we use for quickly accessing base relations.
70+
* Prepare the arrays we use for quickly accessing base relations
71+
* and AppendRelInfos.
7172
*/
7273
void
7374
setup_simple_rel_arrays(PlannerInfo*root)
7475
{
76+
intsize;
7577
Indexrti;
7678
ListCell*lc;
7779

7880
/* Arrays are accessed using RT indexes (1..N) */
79-
root->simple_rel_array_size=list_length(root->parse->rtable)+1;
81+
size=list_length(root->parse->rtable)+1;
82+
root->simple_rel_array_size=size;
8083

81-
/* simple_rel_array is initialized to all NULLs */
84+
/*
85+
* simple_rel_array is initialized to all NULLs, since no RelOptInfos
86+
* exist yet. It'll be filled by later calls to build_simple_rel().
87+
*/
8288
root->simple_rel_array= (RelOptInfo**)
83-
palloc0(root->simple_rel_array_size*sizeof(RelOptInfo*));
89+
palloc0(size*sizeof(RelOptInfo*));
8490

8591
/* simple_rte_array is an array equivalent of the rtable list */
8692
root->simple_rte_array= (RangeTblEntry**)
87-
palloc0(root->simple_rel_array_size*sizeof(RangeTblEntry*));
93+
palloc0(size*sizeof(RangeTblEntry*));
8894
rti=1;
8995
foreach(lc,root->parse->rtable)
9096
{
9197
RangeTblEntry*rte= (RangeTblEntry*)lfirst(lc);
9298

9399
root->simple_rte_array[rti++]=rte;
94100
}
95-
}
96-
97-
/*
98-
* setup_append_rel_array
99-
*Populate the append_rel_array to allow direct lookups of
100-
*AppendRelInfos by child relid.
101-
*
102-
* The array remains unallocated if there are no AppendRelInfos.
103-
*/
104-
void
105-
setup_append_rel_array(PlannerInfo*root)
106-
{
107-
ListCell*lc;
108-
intsize=list_length(root->parse->rtable)+1;
109101

102+
/* append_rel_array is not needed if there are no AppendRelInfos */
110103
if (root->append_rel_list==NIL)
111104
{
112105
root->append_rel_array=NULL;
@@ -116,6 +109,12 @@ setup_append_rel_array(PlannerInfo *root)
116109
root->append_rel_array= (AppendRelInfo**)
117110
palloc0(size*sizeof(AppendRelInfo*));
118111

112+
/*
113+
* append_rel_array is filled with any already-existing AppendRelInfos,
114+
* which currently could only come from UNION ALL flattening. We might
115+
* add more later during inheritance expansion, but it's the
116+
* responsibility of the expansion code to update the array properly.
117+
*/
119118
foreach(lc,root->append_rel_list)
120119
{
121120
AppendRelInfo*appinfo=lfirst_node(AppendRelInfo,lc);
@@ -135,6 +134,10 @@ setup_append_rel_array(PlannerInfo *root)
135134
* expand_planner_arrays
136135
*Expand the PlannerInfo's per-RTE arrays by add_size members
137136
*and initialize the newly added entries to NULLs
137+
*
138+
* Note: this causes the append_rel_array to become allocated even if
139+
* it was not before. This is okay for current uses, because we only call
140+
* this when adding child relations, which always have AppendRelInfos.
138141
*/
139142
void
140143
expand_planner_arrays(PlannerInfo*root,intadd_size)
@@ -145,18 +148,18 @@ expand_planner_arrays(PlannerInfo *root, int add_size)
145148

146149
new_size=root->simple_rel_array_size+add_size;
147150

148-
root->simple_rte_array= (RangeTblEntry**)
149-
repalloc(root->simple_rte_array,
150-
sizeof(RangeTblEntry*)*new_size);
151-
MemSet(root->simple_rte_array+root->simple_rel_array_size,
152-
0,sizeof(RangeTblEntry*)*add_size);
153-
154151
root->simple_rel_array= (RelOptInfo**)
155152
repalloc(root->simple_rel_array,
156153
sizeof(RelOptInfo*)*new_size);
157154
MemSet(root->simple_rel_array+root->simple_rel_array_size,
158155
0,sizeof(RelOptInfo*)*add_size);
159156

157+
root->simple_rte_array= (RangeTblEntry**)
158+
repalloc(root->simple_rte_array,
159+
sizeof(RangeTblEntry*)*new_size);
160+
MemSet(root->simple_rte_array+root->simple_rel_array_size,
161+
0,sizeof(RangeTblEntry*)*add_size);
162+
160163
if (root->append_rel_array)
161164
{
162165
root->append_rel_array= (AppendRelInfo**)

‎src/include/nodes/pathnodes.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,16 @@ struct PlannerInfo
204204

205205
/*
206206
* simple_rte_array is the same length as simple_rel_array and holds
207-
* pointers to the associated rangetable entries. This lets us avoid
208-
* rt_fetch(), which can be a bit slow once large inheritance sets have
209-
* been expanded.
207+
* pointers to the associated rangetable entries. Using this is a shade
208+
* faster than using rt_fetch(), mostly due to fewer indirections.
210209
*/
211210
RangeTblEntry**simple_rte_array;/* rangetable as an array */
212211

213212
/*
214213
* append_rel_array is the same length as the above arrays, and holds
215214
* pointers to the corresponding AppendRelInfo entry indexed by
216-
* child_relid, or NULL ifnone. The array itself is not allocated if
217-
* append_rel_list is empty.
215+
* child_relid, or NULL ifthe rel is not an appendrel child. The array
216+
*itself is not allocated ifappend_rel_list is empty.
218217
*/
219218
structAppendRelInfo**append_rel_array;
220219

‎src/include/optimizer/pathnode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ extern Path *reparameterize_path_by_child(PlannerInfo *root, Path *path,
277277
* prototypes for relnode.c
278278
*/
279279
externvoidsetup_simple_rel_arrays(PlannerInfo*root);
280-
externvoidsetup_append_rel_array(PlannerInfo*root);
281280
externvoidexpand_planner_arrays(PlannerInfo*root,intadd_size);
282281
externRelOptInfo*build_simple_rel(PlannerInfo*root,intrelid,
283282
RelOptInfo*parent);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp