On 2018/02/06 10:48, Amit Langote wrote:
> When working on this, I wondered if the es_leaf_result_relations should
> actually be named something like es_tuple_routing_result_rels, to denote
> the fact that they're created by tuple routing code.  The current name
> might lead to someone thinking that it contains *all* leaf result rels,
> but that won't remain true after this patch.  Thoughts?

While I'm waiting to hear some opinion on the renaming, I updated the
patch to clarify this in the comment about es_leaf_result_relations.

Thanks,
Amit
From 2dca4abcf584f8239b8c47a9a3b96be5585bce06 Mon Sep 17 00:00:00 2001
From: amit <amitlangot...@gmail.com>
Date: Tue, 6 Feb 2018 10:40:45 +0900
Subject: [PATCH v2] Fix trigger behavior with update tuple routing

Trigger stats shown by EXPLAIN ANALYZE may contain duplicate
entries, because leaf partitions' ResultRelInfo is redundantly
present in multiple EState lists.

Reported by: Etsuro Fujita
---
 src/backend/executor/execPartition.c | 10 +++++++---
 src/include/nodes/execnodes.h        |  5 ++++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/backend/executor/execPartition.c 
b/src/backend/executor/execPartition.c
index 106a96d910..619a8d7a99 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -178,6 +178,13 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
                                                          resultRTindex,
                                                          rel,
                                                          
estate->es_instrument);
+
+                       /*
+                        * Since we're newly creating this ResultRelInfo, add 
it to
+                        * someplace where explain.c could find them.
+                        */
+                       estate->es_leaf_result_relations =
+                               lappend(estate->es_leaf_result_relations, 
leaf_part_rri);
                }
 
                part_tupdesc = RelationGetDescr(partrel);
@@ -210,9 +217,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/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index a2a2a9f3d4..1915b53b2f 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -466,7 +466,10 @@ 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: */
+       /*
+        * The following list contains ResultRelInfo's created by the tuple
+        * routing code for partitions that don't already have one.
+        */
        List       *es_leaf_result_relations;   /* List of ResultRelInfos */
 
        /* Stuff used for firing triggers: */
-- 
2.11.0

Reply via email to