From c77c9387b77f700bede9d5cc949045ecd1e2a8d0 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Fri, 7 Feb 2025 13:55:52 +0900
Subject: [PATCH 2/2] Fix MakeTransitionCaptureState to return a consistent 
 result

When both an UPDATE trigger referencing NEW TABLE and a DELETE trigger
referencing OLD TABLE are present, the function returns an
inconsistent result for UPDATE command between reference flags and
tuplestores.  This caused a crash in version 14 and earlier during
cross-partition UPDATEs on a partitioned table, but commit 3a46a45f6f0
accidentally fixed the issue.

Still, it is better to fix this inconsistency, and since similar fixes
have been made in older versions, we should apply the same fix in this
version to keep the code consistent across major versions.
---
 src/backend/commands/trigger.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 7a5ffe32f60..05b31bcb30a 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -4991,10 +4991,10 @@ MakeTransitionCaptureState(TriggerDesc *trigdesc, Oid relid, CmdType cmdType)
 
 	/* Now build the TransitionCaptureState struct, in caller's context */
 	state = (TransitionCaptureState *) palloc0(sizeof(TransitionCaptureState));
-	state->tcs_delete_old_table = trigdesc->trig_delete_old_table;
-	state->tcs_update_old_table = trigdesc->trig_update_old_table;
-	state->tcs_update_new_table = trigdesc->trig_update_new_table;
-	state->tcs_insert_new_table = trigdesc->trig_insert_new_table;
+	state->tcs_delete_old_table = need_old_del;
+	state->tcs_update_old_table = need_old_upd;
+	state->tcs_update_new_table = need_new_upd;
+	state->tcs_insert_new_table = need_new_ins;
 	state->tcs_private = table;
 
 	return state;
-- 
2.43.5

