summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorRobert Haas2017-05-01 12:23:01 +0000
committerRobert Haas2017-05-01 12:23:01 +0000
commite180c8aa8caf5c55a273d4a8e6092e77ff3cff10 (patch)
treedb85b867105969b352fdd95ac83d506fae3f8e04 /src/include
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/include')
-rw-r--r--src/include/nodes/execnodes.h12
-rw-r--r--src/include/nodes/plannodes.h13
-rw-r--r--src/include/nodes/relation.h1
3 files changed, 25 insertions, 1 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 4330a851c3..f289f3c3c2 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -422,6 +422,16 @@ typedef struct EState
int es_num_result_relations; /* length of array */
ResultRelInfo *es_result_relation_info; /* currently active array elt */
+ /*
+ * Info about the target partitioned target table root(s) for
+ * update/delete queries. They required only to fire any per-statement
+ * triggers defined on the table. It exists separately from
+ * es_result_relations, because partitioned tables don't appear in the
+ * plan tree for the update/delete cases.
+ */
+ ResultRelInfo *es_root_result_relations; /* array of ResultRelInfos */
+ int es_num_root_result_relations; /* length of the array */
+
/* Stuff used for firing triggers: */
List *es_trig_target_relations; /* trigger-only ResultRelInfos */
TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
@@ -914,6 +924,8 @@ typedef struct ModifyTableState
int mt_nplans; /* number of plans in the array */
int mt_whichplan; /* which one is being executed (0..n-1) */
ResultRelInfo *resultRelInfo; /* per-subplan target relations */
+ ResultRelInfo *rootResultRelInfo; /* root target relation (partitioned
+ * table root) */
List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */
EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */
bool fireBSTriggers; /* do we need to fire stmt triggers? */
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index cba915572e..164105a3a9 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -65,9 +65,19 @@ typedef struct PlannedStmt
/* rtable indexes of target relations for INSERT/UPDATE/DELETE */
List *resultRelations; /* integer list of RT indexes, or NIL */
- /* rtable indexes of non-leaf target relations for INSERT/UPDATE/DELETE */
+ /*
+ * rtable indexes of non-leaf target relations for UPDATE/DELETE on
+ * all the partitioned table mentioned in the query.
+ */
List *nonleafResultRelations;
+ /*
+ * rtable indexes of root target relations for UPDATE/DELETE; this list
+ * maintains a subset of the RT indexes in nonleafResultRelations,
+ * indicating the roots of the respective partition hierarchies.
+ */
+ List *rootResultRelations;
+
List *subplans; /* Plan trees for SubPlan expressions; note
* that some could be NULL */
@@ -211,6 +221,7 @@ typedef struct ModifyTable
List *partitioned_rels;
List *resultRelations; /* integer list of RT indexes */
int resultRelIndex; /* index of first resultRel in plan's list */
+ int rootResultRelIndex; /* index of the partitioned table root */
List *plans; /* plan(s) producing source data */
List *withCheckOptionLists; /* per-target-table WCO lists */
List *returningLists; /* per-target-table RETURNING tlists */
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index 7a8e2fd2b8..adbd3dd556 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -108,6 +108,7 @@ typedef struct PlannerGlobal
List *resultRelations; /* "flat" list of integer RT indexes */
List *nonleafResultRelations; /* "flat" list of integer RT indexes */
+ List *rootResultRelations; /* "flat" list of integer RT indexes */
List *relationOids; /* OIDs of relations the plan depends on */