@@ -30,21 +30,6 @@ cmp_child_scan_common_by_orig_order(const void *ap,
30
30
return 0 ;
31
31
}
32
32
33
- static void
34
- free_child_scan_common_array (ChildScanCommon * cur_plans , int n )
35
- {
36
- int i ;
37
-
38
- if (!cur_plans )
39
- return ;
40
-
41
- /* We shouldn't free inner objects e.g. Plans here */
42
- for (i = 0 ; i < n ; i ++ )
43
- pfree (cur_plans [i ]);
44
-
45
- pfree (cur_plans );
46
- }
47
-
48
33
static void
49
34
transform_plans_into_states (RuntimeAppendState * scan_state ,
50
35
ChildScanCommon * selected_plans , int n ,
@@ -55,33 +40,35 @@ transform_plans_into_states(RuntimeAppendState *scan_state,
55
40
for (i = 0 ; i < n ; i ++ )
56
41
{
57
42
ChildScanCommon child = selected_plans [i ];
58
- PreservedPlanState * pps ;
59
- bool pps_found ;
60
-
61
- pps = (PreservedPlanState * ) hash_search (scan_state -> plan_state_table ,
62
- (const void * ) & child -> relid ,
63
- HASH_ENTER , & pps_found );
43
+ PlanState * ps ;
64
44
65
45
/* Create new node since this plan hasn't been used yet */
66
- if (! pps_found )
46
+ if (child -> content_type != CHILD_PLAN_STATE )
67
47
{
68
- pps -> ps = ExecInitNode (child -> content .plan , estate , 0 );
48
+ Assert (child -> content_type == CHILD_PLAN ); /* no paths allowed */
49
+
50
+ ps = ExecInitNode (child -> content .plan , estate , 0 );
51
+ child -> content .plan_state = ps ;
52
+ child -> content_type = CHILD_PLAN_STATE ; /* update content type */
53
+
69
54
/* Explain and clear_plan_states rely on this list */
70
- scan_state -> css .custom_ps = lappend (scan_state -> css .custom_ps , pps -> ps );
55
+ scan_state -> css .custom_ps = lappend (scan_state -> css .custom_ps , ps );
71
56
}
72
-
57
+ else
58
+ ps = child -> content .plan_state ;
59
+
73
60
/* Node with params will be ReScanned */
74
61
if (scan_state -> css .ss .ps .chgParam )
75
- UpdateChangedParamSet (pps -> ps , scan_state -> css .ss .ps .chgParam );
62
+ UpdateChangedParamSet (ps , scan_state -> css .ss .ps .chgParam );
76
63
77
64
/*
78
65
* We should ReScan this node manually since
79
66
* ExecProcNode won't do this for us in this case.
80
67
*/
81
- if (bms_is_empty (pps -> ps -> chgParam ))
82
- ExecReScan (pps -> ps );
68
+ if (bms_is_empty (ps -> chgParam ))
69
+ ExecReScan (ps );
83
70
84
- child -> content .plan_state = pps -> ps ;
71
+ child -> content .plan_state = ps ;
85
72
}
86
73
}
87
74
@@ -95,23 +82,19 @@ select_required_plans(HTAB *children_table, Oid *parts, int nparts, int *nres)
95
82
96
83
for (i = 0 ; i < nparts ; i ++ )
97
84
{
98
- ChildScanCommon child_copy ;
99
85
ChildScanCommon child = hash_search (children_table ,
100
86
(const void * ) & parts [i ],
101
87
HASH_FIND , NULL );
102
88
if (!child )
103
- continue ;
89
+ continue ; /* no plan for this partition */
104
90
105
91
if (allocated <= used )
106
92
{
107
93
allocated *= 2 ;
108
94
result = repalloc (result , allocated * sizeof (ChildScanCommon ));
109
95
}
110
96
111
- child_copy = palloc (sizeof (ChildScanCommonData ));
112
- memcpy (child_copy , child , sizeof (ChildScanCommonData ));
113
-
114
- result [used ++ ] = child_copy ;
97
+ result [used ++ ] = child ;
115
98
}
116
99
117
100
* nres = used ;
@@ -204,6 +187,7 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
204
187
205
188
Assert (!child_found ); /* there should be no collisions */
206
189
190
+ child -> content_type = CHILD_PLAN ;
207
191
child -> content .plan = (Plan * ) lfirst (plan_cell );
208
192
child -> original_order = i ++ ; /* will be used in EXPLAIN */
209
193
}
@@ -265,6 +249,7 @@ create_append_path_common(PlannerInfo *root,
265
249
result -> cpath .path .startup_cost += path -> startup_cost ;
266
250
result -> cpath .path .total_cost += path -> total_cost ;
267
251
252
+ child -> content_type = CHILD_PATH ;
268
253
child -> content .path = path ;
269
254
child -> relid = root -> simple_rte_array [relindex ]-> relid ;
270
255
Assert (child -> relid != InvalidOid );
@@ -336,18 +321,7 @@ void
336
321
begin_append_common (CustomScanState * node , EState * estate , int eflags )
337
322
{
338
323
RuntimeAppendState * scan_state = (RuntimeAppendState * ) node ;
339
- HTAB * plan_state_table ;
340
- HASHCTL * plan_state_table_config = & scan_state -> plan_state_table_config ;
341
-
342
- memset (plan_state_table_config , 0 , sizeof (HASHCTL ));
343
- plan_state_table_config -> keysize = sizeof (Oid );
344
- plan_state_table_config -> entrysize = sizeof (PreservedPlanState );
345
-
346
- plan_state_table = hash_create ("PlanState storage" , 128 ,
347
- plan_state_table_config ,
348
- HASH_ELEM | HASH_BLOBS );
349
324
350
- scan_state -> plan_state_table = plan_state_table ;
351
325
scan_state -> custom_expr_states =
352
326
(List * ) ExecInitExpr ((Expr * ) scan_state -> custom_exprs ,
353
327
(PlanState * ) scan_state );
@@ -359,7 +333,6 @@ end_append_common(CustomScanState *node)
359
333
RuntimeAppendState * scan_state = (RuntimeAppendState * ) node ;
360
334
361
335
clear_plan_states (& scan_state -> css );
362
- hash_destroy (scan_state -> plan_state_table );
363
336
hash_destroy (scan_state -> children_table );
364
337
}
365
338
@@ -391,7 +364,9 @@ rescan_append_common(CustomScanState *node)
391
364
parts = get_partition_oids (ranges , & nparts , prel );
392
365
393
366
/* Select new plans for this run using 'parts' */
394
- free_child_scan_common_array (scan_state -> cur_plans , scan_state -> ncur_plans );
367
+ if (scan_state -> cur_plans )
368
+ pfree (scan_state -> cur_plans ); /* shallow free since cur_plans
369
+ * belong to children_table */
395
370
scan_state -> cur_plans = select_required_plans (scan_state -> children_table ,
396
371
parts , nparts ,
397
372
& scan_state -> ncur_plans );
0 commit comments