@@ -173,12 +173,13 @@ append_part_attr_to_tlist(List *tlist, Index relno, const PartRelationInfo *prel
173
173
}
174
174
175
175
static void
176
- pack_runtimeappend_private (CustomScan * cscan , RuntimeAppendPath * path )
176
+ pack_runtimeappend_private (CustomScan * cscan , RuntimeAppendPath * path ,
177
+ bool enable_parent )
177
178
{
178
179
ChildScanCommon * children = path -> children ;
179
180
int nchildren = path -> nchildren ;
180
- List * custom_private = NIL ;
181
- List * custom_oids = NIL ;
181
+ List * custom_private = NIL ,
182
+ * custom_oids = NIL ;
182
183
int i ;
183
184
184
185
for (i = 0 ; i < nchildren ; i ++ )
@@ -188,31 +189,39 @@ pack_runtimeappend_private(CustomScan *cscan, RuntimeAppendPath *path)
188
189
pfree (children [i ]);
189
190
}
190
191
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' */
192
193
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 )));
195
197
198
+ /* Store freshly built 'custom_private' */
196
199
cscan -> custom_private = custom_private ;
197
200
}
198
201
199
202
static void
200
203
unpack_runtimeappend_private (RuntimeAppendState * scan_state , CustomScan * cscan )
201
204
{
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
+
207
211
HTAB * children_table ;
208
212
HASHCTL * children_table_config = & scan_state -> children_table_config ;
209
213
int i ;
210
214
215
+ /* Extract Oids list from packed data */
216
+ custom_oids = (List * ) lsecond (runtimeappend_private );
217
+ custom_oids_count = list_length (custom_oids );
218
+
211
219
memset (children_table_config , 0 , sizeof (HASHCTL ));
212
220
children_table_config -> keysize = sizeof (Oid );
213
221
children_table_config -> entrysize = sizeof (ChildScanCommonData );
214
222
215
- children_table = hash_create ("Plan storage" , nchildren ,
223
+ children_table = hash_create ("RuntimeAppend plan storage" ,
224
+ custom_oids_count ,
216
225
children_table_config ,
217
226
HASH_ELEM | HASH_BLOBS );
218
227
@@ -233,8 +242,10 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
233
242
child -> original_order = i ++ ; /* will be used in EXPLAIN */
234
243
}
235
244
245
+ /* Finally fill 'scan_state' with unpacked elements */
236
246
scan_state -> children_table = children_table ;
237
247
scan_state -> relid = linitial_oid (linitial (runtimeappend_private ));
248
+ scan_state -> enable_parent = (bool ) linitial_int (lthird (runtimeappend_private ));
238
249
}
239
250
240
251
@@ -400,7 +411,8 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
400
411
cscan -> custom_plans = custom_plans ;
401
412
cscan -> methods = scan_methods ;
402
413
403
- pack_runtimeappend_private (cscan , rpath );
414
+ /* Cache 'prel->enable_parent' as well */
415
+ pack_runtimeappend_private (cscan , rpath , prel -> enable_parent );
404
416
405
417
return & cscan -> scan .plan ;
406
418
}
@@ -502,6 +514,7 @@ rescan_append_common(CustomScanState *node)
502
514
const PartRelationInfo * prel ;
503
515
List * ranges ;
504
516
ListCell * lc ;
517
+ WalkerContext wcxt ;
505
518
Oid * parts ;
506
519
int nparts ;
507
520
@@ -511,18 +524,18 @@ rescan_append_common(CustomScanState *node)
511
524
/* First we select all available partitions... */
512
525
ranges = list_make1_irange (make_irange (0 , PrelLastChild (prel ), false));
513
526
514
- InitWalkerContext (& scan_state -> wcxt , prel , econtext , false);
527
+ InitWalkerContext (& wcxt , prel , econtext , false);
515
528
foreach (lc , scan_state -> custom_exprs )
516
529
{
517
530
WrapperNode * wn ;
518
531
519
532
/* ... 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 );
521
534
ranges = irange_list_intersect (ranges , wn -> rangeset );
522
535
}
523
536
524
537
/* 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 );
526
539
527
540
/* Select new plans for this run using 'parts' */
528
541
if (scan_state -> cur_plans )
0 commit comments