Skip to content

Commit 852a7ee

Browse files
committed
RuntimeAppend now caches prel->enable_parent (just in case)
1 parent 4631711 commit 852a7ee

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

src/nodes_common.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ append_part_attr_to_tlist(List *tlist, Index relno, const PartRelationInfo *prel
173173
}
174174

175175
static void
176-
pack_runtimeappend_private(CustomScan *cscan, RuntimeAppendPath *path)
176+
pack_runtimeappend_private(CustomScan *cscan, RuntimeAppendPath *path,
177+
bool enable_parent)
177178
{
178179
ChildScanCommon *children = path->children;
179180
int nchildren = path->nchildren;
180-
List *custom_private = NIL;
181-
List *custom_oids = NIL;
181+
List *custom_private = NIL,
182+
*custom_oids = NIL;
182183
int i;
183184

184185
for (i = 0; i < nchildren; i++)
@@ -188,31 +189,39 @@ pack_runtimeappend_private(CustomScan *cscan, RuntimeAppendPath *path)
188189
pfree(children[i]);
189190
}
190191

191-
/* Save main table and partition relids as first element of 'custom_private' */
192+
/* Save parent & partition Oids and a flag as first element of 'custom_private' */
192193
custom_private = lappend(custom_private,
193-
list_make2(list_make1_oid(path->relid),
194-
custom_oids));
194+
list_make3(list_make1_oid(path->relid),
195+
custom_oids, /* list of Oids */
196+
list_make1_int(enable_parent)));
195197

198+
/* Store freshly built 'custom_private' */
196199
cscan->custom_private = custom_private;
197200
}
198201

199202
static void
200203
unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
201204
{
202-
ListCell *oid_cell;
203-
ListCell *plan_cell;
204-
List *runtimeappend_private = linitial(cscan->custom_private);
205-
List *custom_oids = (List *) lsecond(runtimeappend_private);
206-
int nchildren = list_length(custom_oids);
205+
ListCell *oid_cell,
206+
*plan_cell;
207+
List *runtimeappend_private = linitial(cscan->custom_private),
208+
*custom_oids; /* Oids of partitions */
209+
int custom_oids_count; /* number of partitions */
210+
207211
HTAB *children_table;
208212
HASHCTL *children_table_config = &scan_state->children_table_config;
209213
int i;
210214

215+
/* Extract Oids list from packed data */
216+
custom_oids = (List *) lsecond(runtimeappend_private);
217+
custom_oids_count = list_length(custom_oids);
218+
211219
memset(children_table_config, 0, sizeof(HASHCTL));
212220
children_table_config->keysize = sizeof(Oid);
213221
children_table_config->entrysize = sizeof(ChildScanCommonData);
214222

215-
children_table = hash_create("Plan storage", nchildren,
223+
children_table = hash_create("RuntimeAppend plan storage",
224+
custom_oids_count,
216225
children_table_config,
217226
HASH_ELEM | HASH_BLOBS);
218227

@@ -233,8 +242,10 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
233242
child->original_order = i++; /* will be used in EXPLAIN */
234243
}
235244

245+
/* Finally fill 'scan_state' with unpacked elements */
236246
scan_state->children_table = children_table;
237247
scan_state->relid = linitial_oid(linitial(runtimeappend_private));
248+
scan_state->enable_parent = (bool) linitial_int(lthird(runtimeappend_private));
238249
}
239250

240251

@@ -400,7 +411,8 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
400411
cscan->custom_plans = custom_plans;
401412
cscan->methods = scan_methods;
402413

403-
pack_runtimeappend_private(cscan, rpath);
414+
/* Cache 'prel->enable_parent' as well */
415+
pack_runtimeappend_private(cscan, rpath, prel->enable_parent);
404416

405417
return &cscan->scan.plan;
406418
}
@@ -502,6 +514,7 @@ rescan_append_common(CustomScanState *node)
502514
const PartRelationInfo *prel;
503515
List *ranges;
504516
ListCell *lc;
517+
WalkerContext wcxt;
505518
Oid *parts;
506519
int nparts;
507520

@@ -511,18 +524,18 @@ rescan_append_common(CustomScanState *node)
511524
/* First we select all available partitions... */
512525
ranges = list_make1_irange(make_irange(0, PrelLastChild(prel), false));
513526

514-
InitWalkerContext(&scan_state->wcxt, prel, econtext, false);
527+
InitWalkerContext(&wcxt, prel, econtext, false);
515528
foreach (lc, scan_state->custom_exprs)
516529
{
517530
WrapperNode *wn;
518531

519532
/* ... then we cut off irrelevant ones using the provided clauses */
520-
wn = walk_expr_tree((Expr *) lfirst(lc), &scan_state->wcxt);
533+
wn = walk_expr_tree((Expr *) lfirst(lc), &wcxt);
521534
ranges = irange_list_intersect(ranges, wn->rangeset);
522535
}
523536

524537
/* Get Oids of the required partitions */
525-
parts = get_partition_oids(ranges, &nparts, prel, prel->enable_parent);
538+
parts = get_partition_oids(ranges, &nparts, prel, scan_state->enable_parent);
526539

527540
/* Select new plans for this run using 'parts' */
528541
if (scan_state->cur_plans)

src/runtime_merge_append.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ static void
113113
pack_runtimemergeappend_private(CustomScan *cscan, MergeAppendGuts *mag)
114114
{
115115
List *runtimemergeappend_private = NIL;
116-
List *sortColIdx = NIL,
117-
*sortOperators = NIL,
118-
*collations = NIL,
119-
*nullsFirst = NIL;
116+
List *sortColIdx = NIL,
117+
*sortOperators = NIL,
118+
*collations = NIL,
119+
*nullsFirst = NIL;
120120
int i;
121121

122122
for (i = 0; i < mag->numCols; i++)
123123
{
124-
sortColIdx = lappend_int(sortColIdx, mag->sortColIdx[i]);
125-
sortOperators = lappend_oid(sortOperators, mag->sortOperators[i]);
126-
collations = lappend_oid(collations, mag->collations[i]);
127-
nullsFirst = lappend_int(nullsFirst, mag->nullsFirst[i]);
124+
sortColIdx = lappend_int(sortColIdx, mag->sortColIdx[i]);
125+
sortOperators = lappend_oid(sortOperators, mag->sortOperators[i]);
126+
collations = lappend_oid(collations, mag->collations[i]);
127+
nullsFirst = lappend_int(nullsFirst, mag->nullsFirst[i]);
128128
}
129129

130130
runtimemergeappend_private = list_make2(makeInteger(mag->numCols),
@@ -133,7 +133,14 @@ pack_runtimemergeappend_private(CustomScan *cscan, MergeAppendGuts *mag)
133133
collations,
134134
nullsFirst));
135135

136-
/* Append RuntimeMergeAppend's data to the 'custom_private' */
136+
/*
137+
* Append RuntimeMergeAppend's data to the 'custom_private' (2nd).
138+
*
139+
* This way some sort of hierarchy is maintained in 'custom_private':
140+
* inherited structure (in this case RuntimeAppend) is stored first,
141+
* so we can think of pack\unpack functions as 'constructors' to some
142+
* extent.
143+
*/
137144
cscan->custom_private = lappend(cscan->custom_private,
138145
runtimemergeappend_private);
139146
}
@@ -168,15 +175,15 @@ unpack_runtimemergeappend_private(RuntimeMergeAppendState *scan_state,
168175
runtimemergeappend_private = lsecond(cscan->custom_private);
169176
scan_state->numCols = intVal(linitial(runtimemergeappend_private));
170177

171-
sortColIdx = linitial(lsecond(runtimemergeappend_private));
172-
sortOperators = lsecond(lsecond(runtimemergeappend_private));
173-
collations = lthird(lsecond(runtimemergeappend_private));
174-
nullsFirst = lfourth(lsecond(runtimemergeappend_private));
178+
sortColIdx = linitial(lsecond(runtimemergeappend_private));
179+
sortOperators = lsecond(lsecond(runtimemergeappend_private));
180+
collations = lthird(lsecond(runtimemergeappend_private));
181+
nullsFirst = lfourth(lsecond(runtimemergeappend_private));
175182

176-
FillStateField(sortColIdx, AttrNumber, lfirst_int);
177-
FillStateField(sortOperators, Oid, lfirst_oid);
178-
FillStateField(collations, Oid, lfirst_oid);
179-
FillStateField(nullsFirst, bool, lfirst_int);
183+
FillStateField(sortColIdx, AttrNumber, lfirst_int);
184+
FillStateField(sortOperators, Oid, lfirst_oid);
185+
FillStateField(collations, Oid, lfirst_oid);
186+
FillStateField(nullsFirst, bool, lfirst_int);
180187
}
181188

182189
void

src/runtimeappend.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
typedef struct
2424
{
2525
CustomPath cpath;
26-
Oid relid; /* relid of the partitioned table */
26+
Oid relid; /* relid of the partitioned table */
2727

28-
ChildScanCommon *children; /* all available plans */
28+
ChildScanCommon *children; /* all available plans */
2929
int nchildren;
3030
} RuntimeAppendPath;
3131

@@ -46,15 +46,14 @@ typedef struct
4646
ChildScanCommon *cur_plans;
4747
int ncur_plans;
4848

49+
/* Should we include parent table? Cached for prepared statements */
50+
bool enable_parent;
51+
4952
/* Index of the selected plan state */
5053
int running_idx;
5154

5255
/* Last saved tuple (for SRF projections) */
5356
TupleTableSlot *slot;
54-
55-
/* Cached walker context */
56-
WalkerContext wcxt;
57-
bool wcxt_cached;
5857
} RuntimeAppendState;
5958

6059

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy