aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/copy.c29
-rw-r--r--src/backend/commands/trigger.c10
2 files changed, 12 insertions, 27 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 531bd7c73a5..b4ccd35ec18 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -3106,31 +3106,14 @@ CopyFrom(CopyState cstate)
/*
* If we're capturing transition tuples, we might need to convert
- * from the partition rowtype to root rowtype.
+ * from the partition rowtype to root rowtype. But if there are no
+ * BEFORE triggers on the partition that could change the tuple,
+ * we can just remember the original unconverted tuple to avoid a
+ * needless round trip conversion.
*/
if (cstate->transition_capture != NULL)
- {
- if (has_before_insert_row_trig)
- {
- /*
- * If there are any BEFORE triggers on the partition,
- * we'll have to be ready to convert their result back to
- * tuplestore format.
- */
- cstate->transition_capture->tcs_original_insert_tuple = NULL;
- cstate->transition_capture->tcs_map =
- resultRelInfo->ri_PartitionInfo->pi_PartitionToRootMap;
- }
- else
- {
- /*
- * Otherwise, just remember the original unconverted
- * tuple, to avoid a needless round trip conversion.
- */
- cstate->transition_capture->tcs_original_insert_tuple = myslot;
- cstate->transition_capture->tcs_map = NULL;
- }
- }
+ cstate->transition_capture->tcs_original_insert_tuple =
+ !has_before_insert_row_trig ? myslot : NULL;
/*
* We might need to convert from the root rowtype to the partition
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 3b4fbdadf4f..5719672f4ce 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -35,6 +35,7 @@
#include "commands/defrem.h"
#include "commands/trigger.h"
#include "executor/executor.h"
+#include "executor/execPartition.h"
#include "miscadmin.h"
#include "nodes/bitmapset.h"
#include "nodes/makefuncs.h"
@@ -4292,9 +4293,10 @@ GetAfterTriggersTableData(Oid relid, CmdType cmdType)
* If there are no triggers in 'trigdesc' that request relevant transition
* tables, then return NULL.
*
- * The resulting object can be passed to the ExecAR* functions. The caller
- * should set tcs_map or tcs_original_insert_tuple as appropriate when dealing
- * with child tables.
+ * The resulting object can be passed to the ExecAR* functions. When
+ * dealing with child tables, the caller can set tcs_original_insert_tuple
+ * to avoid having to reconstruct the original tuple in the root table's
+ * format.
*
* Note that we copy the flags from a parent table into this struct (rather
* than subsequently using the relation's TriggerDesc directly) so that we can
@@ -5389,7 +5391,7 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
if (row_trigger && transition_capture != NULL)
{
TupleTableSlot *original_insert_tuple = transition_capture->tcs_original_insert_tuple;
- TupleConversionMap *map = transition_capture->tcs_map;
+ TupleConversionMap *map = relinfo->ri_ChildToRootMap;
bool delete_old_table = transition_capture->tcs_delete_old_table;
bool update_old_table = transition_capture->tcs_update_old_table;
bool update_new_table = transition_capture->tcs_update_new_table;