summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Haas2018-02-08 19:29:05 +0000
committerRobert Haas2018-02-08 19:29:05 +0000
commite44dd84325c277fd031b9ef486c51a0946c7d3a0 (patch)
treea501ae2a890898c23dcac6a791fe08299ed9b3c6 /src
parent88fdc7006018b92d6ec92c54b3819764703daaba (diff)
Avoid listing the same ResultRelInfo in more than one EState list.
Doing so causes EXPLAIN ANALYZE to show trigger statistics multiple times. Commit 2f178441044be430f6b4d626e4dae68a9a6f6cec seems to be to blame for this. Amit Langote, revieed by Amit Khandekar, Etsuro Fujita, and me.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/explain.c11
-rw-r--r--src/backend/executor/execMain.c7
-rw-r--r--src/backend/executor/execPartition.c12
-rw-r--r--src/backend/executor/execUtils.c2
-rw-r--r--src/include/nodes/execnodes.h7
5 files changed, 27 insertions, 12 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 41cd47e8bc..900fa74e85 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -652,15 +652,18 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
bool show_relname;
int numrels = queryDesc->estate->es_num_result_relations;
int numrootrels = queryDesc->estate->es_num_root_result_relations;
- List *leafrels = queryDesc->estate->es_leaf_result_relations;
- List *targrels = queryDesc->estate->es_trig_target_relations;
+ List *routerels;
+ List *targrels;
int nr;
ListCell *l;
+ routerels = queryDesc->estate->es_tuple_routing_result_relations;
+ targrels = queryDesc->estate->es_trig_target_relations;
+
ExplainOpenGroup("Triggers", "Triggers", false, es);
show_relname = (numrels > 1 || numrootrels > 0 ||
- leafrels != NIL || targrels != NIL);
+ routerels != NIL || targrels != NIL);
rInfo = queryDesc->estate->es_result_relations;
for (nr = 0; nr < numrels; rInfo++, nr++)
report_triggers(rInfo, show_relname, es);
@@ -669,7 +672,7 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
for (nr = 0; nr < numrootrels; rInfo++, nr++)
report_triggers(rInfo, show_relname, es);
- foreach(l, leafrels)
+ foreach(l, routerels)
{
rInfo = (ResultRelInfo *) lfirst(l);
report_triggers(rInfo, show_relname, es);
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 410921cc40..5d3e923cca 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1413,8 +1413,11 @@ ExecGetTriggerResultRel(EState *estate, Oid relid)
rInfo++;
nr--;
}
- /* Third, search through the leaf result relations, if any */
- foreach(l, estate->es_leaf_result_relations)
+ /*
+ * Third, search through the result relations that were created during
+ * tuple routing, if any.
+ */
+ foreach(l, estate->es_tuple_routing_result_relations)
{
rInfo = (ResultRelInfo *) lfirst(l);
if (RelationGetRelid(rInfo->ri_RelationDesc) == relid)
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c
index ba6b52c32c..4048c3ebc6 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -178,6 +178,15 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
resultRTindex,
rel,
estate->es_instrument);
+
+ /*
+ * Since we've just initialized this ResultRelInfo, it's not in
+ * any list attached to the estate as yet. Add it, so that it can
+ * be found later.
+ */
+ estate->es_tuple_routing_result_relations =
+ lappend(estate->es_tuple_routing_result_relations,
+ leaf_part_rri);
}
part_tupdesc = RelationGetDescr(partrel);
@@ -210,9 +219,6 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
mtstate != NULL &&
mtstate->mt_onconflict != ONCONFLICT_NONE);
- estate->es_leaf_result_relations =
- lappend(estate->es_leaf_result_relations, leaf_part_rri);
-
proute->partitions[i] = leaf_part_rri;
i++;
}
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index e29f7aaf7b..50b6edce63 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -119,7 +119,7 @@ CreateExecutorState(void)
estate->es_root_result_relations = NULL;
estate->es_num_root_result_relations = 0;
- estate->es_leaf_result_relations = NIL;
+ estate->es_tuple_routing_result_relations = NIL;
estate->es_trig_target_relations = NIL;
estate->es_trig_tuple_slot = NULL;
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 54ce63f147..286d55be03 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -466,8 +466,11 @@ typedef struct EState
ResultRelInfo *es_root_result_relations; /* array of ResultRelInfos */
int es_num_root_result_relations; /* length of the array */
- /* Info about leaf partitions of partitioned table(s) for insert queries: */
- List *es_leaf_result_relations; /* List of ResultRelInfos */
+ /*
+ * The following list contains ResultRelInfos created by the tuple
+ * routing code for partitions that don't already have one.
+ */
+ List *es_tuple_routing_result_relations;
/* Stuff used for firing triggers: */
List *es_trig_target_relations; /* trigger-only ResultRelInfos */