aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-04-08 12:20:22 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-04-08 12:20:22 -0400
commita8cb8f124679e0c373fdd07108b136e1cf1ee14a (patch)
treeb2fb93add68867cb95bbf671fea2b322095177d7 /src/backend/executor/execMain.c
parent348f57ce5be96190491e2153abb47060884f8ebf (diff)
downloadpostgresql-a8cb8f124679e0c373fdd07108b136e1cf1ee14a.tar.gz
postgresql-a8cb8f124679e0c373fdd07108b136e1cf1ee14a.zip
Fix EvalPlanQualStart to handle partitioned result rels correctly.
The es_root_result_relations array needs to be shallow-copied in the same way as the main es_result_relations array, else EPQ rechecks on partitioned result relations fail, as seen in bug #15677 from Norbert Benkocs. Amit Langote, isolation test case added by me Discussion: https://postgr.es/m/15677-0bf089579b4cd02d@postgresql.org Discussion: https://postgr.es/m/19321.1554567786@sss.pgh.pa.us
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 602a08e5858..ed7c0606bf1 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -2779,7 +2779,7 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
* es_param_exec_vals, etc.
*
* The ResultRelInfo array management is trickier than it looks. We
- * create a fresh array for the child but copy all the content from the
+ * create fresh arrays for the child but copy all the content from the
* parent. This is because it's okay for the child to share any
* per-relation state the parent has already created --- but if the child
* sets up any ResultRelInfo fields, such as its own junkfilter, that
@@ -2800,6 +2800,7 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
if (parentestate->es_num_result_relations > 0)
{
int numResultRelations = parentestate->es_num_result_relations;
+ int numRootResultRels = parentestate->es_num_root_result_relations;
ResultRelInfo *resultRelInfos;
resultRelInfos = (ResultRelInfo *)
@@ -2808,6 +2809,17 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
numResultRelations * sizeof(ResultRelInfo));
estate->es_result_relations = resultRelInfos;
estate->es_num_result_relations = numResultRelations;
+
+ /* Also transfer partitioned root result relations. */
+ if (numRootResultRels > 0)
+ {
+ resultRelInfos = (ResultRelInfo *)
+ palloc(numRootResultRels * sizeof(ResultRelInfo));
+ memcpy(resultRelInfos, parentestate->es_root_result_relations,
+ numRootResultRels * sizeof(ResultRelInfo));
+ estate->es_root_result_relations = resultRelInfos;
+ estate->es_num_root_result_relations = numRootResultRels;
+ }
}
/* es_result_relation_info must NOT be copied */
/* es_trig_target_relations must NOT be copied */