aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAppend.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-06-13 12:03:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-06-13 12:03:26 -0400
commite23bae82cf3d76365d48b1204ca4c631bac7550d (patch)
tree1422c664271c244dc10ca5e8c908f67e639600e8 /src/backend/executor/nodeAppend.c
parente146e4d02dbc241b6091596331fb1bdf0fb1c081 (diff)
downloadpostgresql-e23bae82cf3d76365d48b1204ca4c631bac7550d.tar.gz
postgresql-e23bae82cf3d76365d48b1204ca4c631bac7550d.zip
Fix up run-time partition pruning's use of relcache's partition data.
The previous coding saved pointers into the partitioned table's relcache entry, but then closed the relcache entry, causing those pointers to nominally become dangling. Actual trouble would be seen in the field only if a relcache flush occurred mid-query, but that's hardly out of the question. While we could fix this by copying all the data in question at query start, it seems better to just hold the relcache entry open for the whole query. While at it, improve the handling of support-function lookups: do that once per query not once per pruning test. There's still something to be desired here, in that we fail to exploit the possibility of caching data across queries in the fn_extra fields of the relcache's FmgrInfo structs, which could happen if we just used those structs in-place rather than copying them. However, combining that with the possibility of per-query lookups of cross-type comparison functions seems to require changes in the APIs of a lot of the pruning support functions, so it's too invasive to consider as part of this patch. A win would ensue only for complex partition key data types (e.g. arrays), so it may not be worth the trouble. David Rowley and Tom Lane Discussion: https://postgr.es/m/17850.1528755844@sss.pgh.pa.us
Diffstat (limited to 'src/backend/executor/nodeAppend.c')
-rw-r--r--src/backend/executor/nodeAppend.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 6dd53e90ba8..5ce4fb43e1a 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -136,8 +136,10 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
/* We may need an expression context to evaluate partition exprs */
ExecAssignExprContext(estate, &appendstate->ps);
- prunestate = ExecSetupPartitionPruneState(&appendstate->ps,
- node->part_prune_infos);
+ /* Create the working data structure for pruning. */
+ prunestate = ExecCreatePartitionPruneState(&appendstate->ps,
+ node->part_prune_infos);
+ appendstate->as_prune_state = prunestate;
/* Perform an initial partition prune, if required. */
if (prunestate->do_initial_prune)
@@ -178,8 +180,6 @@ ExecInitAppend(Append *node, EState *estate, int eflags)
*/
if (!prunestate->do_exec_prune)
appendstate->as_valid_subplans = bms_add_range(NULL, 0, nplans - 1);
-
- appendstate->as_prune_state = prunestate;
}
else
{
@@ -330,6 +330,12 @@ ExecEndAppend(AppendState *node)
*/
for (i = 0; i < nplans; i++)
ExecEndNode(appendplans[i]);
+
+ /*
+ * release any resources associated with run-time pruning
+ */
+ if (node->as_prune_state)
+ ExecDestroyPartitionPruneState(node->as_prune_state);
}
void