Skip to content

Commit 3e5ec3e

Browse files
ayushdshRucha Kulkarni
authored andcommitted
[BABEL] Fixes for Babelfish triggers after community commit c5fc17ddacc
Community commit c5fc17ddacc introduced a fix for CTEs with DMLs not being inserted into the transition tables. For this fix, the previous tcs_private field is now split into individual ins, upd and del field each with the old and new tuplestore. TSQL triggers are implicitly created with new "inserted" and old "deleted" transition tables even for insert and delete triggers and both are referenceble in the trigger function. With the splitting of the tcs_private field we no longer intialize the old ins tuplestore and new del tuplestore. However, since these transition tables are atleast accessible from a TSQL trigger, we should have an empty tuplestore for both of them anyway. Since these will be empty as per behaviour of INSERT and DELETE triggers, we are okay with simply creating an empty tuplestore for them. Signed-off-by: Ayush Shah <ayushdsh@amazon.com> cr: https://code.amazon.com/reviews/CR-256859140
1 parent 054df65 commit 3e5ec3e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/backend/commands/trigger.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5445,6 +5445,25 @@ MakeTransitionCaptureState(TriggerDesc *trigdesc, Oid relid, CmdType cmdType)
54455445
if (need_new_ins && ins_table->new_tuplestore == NULL)
54465446
ins_table->new_tuplestore = tuplestore_begin_heap(false, false, work_mem);
54475447

5448+
/*
5449+
* BABELFISH: TSQL triggers are implicitly created with and old and new transition tables
5450+
* called "deleted" and "inserted" respectively. Since we've replaced the tcs_private field
5451+
* with individual ins, upd, del fields, with INSERTs we no longer create an empty tuplestore
5452+
* for old transition table and similarly for DELETEs we don't create a new one. However,
5453+
* since these transition tables are atleast accessible from a TSQL trigger, we should have an empty
5454+
* tuplestore for both of them anyway.
5455+
*
5456+
* Since these will be empty as per behaviour of INSERT and DELETE triggers, we are okay with
5457+
* simply creating an empty tuplestore for them.
5458+
*/
5459+
if (sql_dialect == SQL_DIALECT_TSQL)
5460+
{
5461+
if (ins_table && ins_table->old_tuplestore == NULL)
5462+
ins_table->old_tuplestore = tuplestore_begin_heap(false, false, work_mem);
5463+
if (del_table && del_table->new_tuplestore == NULL)
5464+
del_table->new_tuplestore = tuplestore_begin_heap(false, false, work_mem);
5465+
}
5466+
54485467
CurrentResourceOwner = saveResourceOwner;
54495468
MemoryContextSwitchTo(oldcxt);
54505469

0 commit comments

Comments
 (0)