summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/setrefs.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-05-01 08:23:01 -0400
committerRobert Haas <rhaas@postgresql.org>2017-05-01 08:23:01 -0400
commite180c8aa8caf5c55a273d4a8e6092e77ff3cff10 (patch)
treedb85b867105969b352fdd95ac83d506fae3f8e04 /src/backend/optimizer/plan/setrefs.c
parente18b2c480da478f62781e06488cda56fe1b4e919 (diff)
Fire per-statement triggers on partitioned tables.
Even though no actual tuples are ever inserted into a partitioned table (the actual tuples are in the partitions, not the partitioned table itself), we still need to have a ResultRelInfo for the partitioned table, or per-statement triggers won't get fired. Amit Langote, per a report from Rajkumar Raghuwanshi. Reviewed by me. Discussion: http://postgr.es/m/CAKcux6%3DwYospCRY2J4XEFuVy0L41S%3Dfic7rmkbsU-GXhhSbmBg%40mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/plan/setrefs.c')
-rw-r--r--src/backend/optimizer/plan/setrefs.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 1278371b652..c192dc4f700 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -882,11 +882,22 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
/*
* If the main target relation is a partitioned table, the
* following list contains the RT indexes of partitioned child
- * relations, which are not included in the above list.
+ * relations including the root, which are not included in the
+ * above list. We also keep RT indexes of the roots separately
+ * to be identitied as such during the executor initialization.
*/
- root->glob->nonleafResultRelations =
- list_concat(root->glob->nonleafResultRelations,
- list_copy(splan->partitioned_rels));
+ if (splan->partitioned_rels != NIL)
+ {
+ root->glob->nonleafResultRelations =
+ list_concat(root->glob->nonleafResultRelations,
+ list_copy(splan->partitioned_rels));
+ /* Remember where this root will be in the global list. */
+ splan->rootResultRelIndex =
+ list_length(root->glob->rootResultRelations);
+ root->glob->rootResultRelations =
+ lappend_int(root->glob->rootResultRelations,
+ linitial_int(splan->partitioned_rels));
+ }
}
break;
case T_Append: