@@ -173,12 +173,13 @@ append_part_attr_to_tlist(List *tlist, Index relno, const PartRelationInfo *prel
173173}
174174
175175static void
176- pack_runtimeappend_private (CustomScan * cscan ,RuntimeAppendPath * path )
176+ pack_runtimeappend_private (CustomScan * cscan ,RuntimeAppendPath * path ,
177+ bool enable_parent )
177178{
178179ChildScanCommon * children = path -> children ;
179180int nchildren = path -> nchildren ;
180- List * custom_private = NIL ;
181- List * custom_oids = NIL ;
181+ List * custom_private = NIL ,
182+ * custom_oids = NIL ;
182183int i ;
183184
184185for (i = 0 ;i < nchildren ;i ++ )
@@ -188,31 +189,39 @@ pack_runtimeappend_private(CustomScan *cscan, RuntimeAppendPath *path)
188189pfree (children [i ]);
189190}
190191
191- /* Savemain table andpartition relids as first element of 'custom_private' */
192+ /* Saveparent & partition Oids anda flag as first element of 'custom_private' */
192193custom_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' */
196199cscan -> custom_private = custom_private ;
197200}
198201
199202static void
200203unpack_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+
207211HTAB * children_table ;
208212HASHCTL * children_table_config = & scan_state -> children_table_config ;
209213int 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+
211219memset (children_table_config ,0 ,sizeof (HASHCTL ));
212220children_table_config -> keysize = sizeof (Oid );
213221children_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 ,
216225children_table_config ,
217226HASH_ELEM |HASH_BLOBS );
218227
@@ -233,8 +242,10 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
233242child -> original_order = i ++ ;/* will be used in EXPLAIN */
234243}
235244
245+ /* Finally fill 'scan_state' with unpacked elements */
236246scan_state -> children_table = children_table ;
237247scan_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,
400411cscan -> custom_plans = custom_plans ;
401412cscan -> 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
405417return & cscan -> scan .plan ;
406418}
@@ -502,6 +514,7 @@ rescan_append_common(CustomScanState *node)
502514const PartRelationInfo * prel ;
503515List * ranges ;
504516ListCell * lc ;
517+ WalkerContext wcxt ;
505518Oid * parts ;
506519int nparts ;
507520
@@ -511,18 +524,18 @@ rescan_append_common(CustomScanState *node)
511524/* First we select all available partitions... */
512525ranges = list_make1_irange (make_irange (0 ,PrelLastChild (prel ), false));
513526
514- InitWalkerContext (& scan_state -> wcxt ,prel ,econtext , false);
527+ InitWalkerContext (& wcxt ,prel ,econtext , false);
515528foreach (lc ,scan_state -> custom_exprs )
516529{
517530WrapperNode * 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 );
521534ranges = 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' */
528541if (scan_state -> cur_plans )