@@ -9593,6 +9593,8 @@ validateForeignKeyConstraint(char *conname,
9593
9593
TableScanDesc scan;
9594
9594
Trigger trig;
9595
9595
Snapshot snapshot;
9596
+ MemoryContext oldcxt;
9597
+ MemoryContext perTupCxt;
9596
9598
9597
9599
ereport(DEBUG1,
9598
9600
(errmsg("validating foreign key constraint \"%s\"", conname)));
@@ -9628,11 +9630,18 @@ validateForeignKeyConstraint(char *conname,
9628
9630
slot = table_slot_create(rel, NULL);
9629
9631
scan = table_beginscan(rel, snapshot, 0, NULL);
9630
9632
9633
+ perTupCxt = AllocSetContextCreate(CurrentMemoryContext,
9634
+ "validateForeignKeyConstraint",
9635
+ ALLOCSET_SMALL_SIZES);
9636
+ oldcxt = MemoryContextSwitchTo(perTupCxt);
9637
+
9631
9638
while (table_scan_getnextslot(scan, ForwardScanDirection, slot))
9632
9639
{
9633
9640
LOCAL_FCINFO(fcinfo, 0);
9634
9641
TriggerData trigdata;
9635
9642
9643
+ CHECK_FOR_INTERRUPTS();
9644
+
9636
9645
/*
9637
9646
* Make a call to the trigger function
9638
9647
*
@@ -9649,13 +9658,18 @@ validateForeignKeyConstraint(char *conname,
9649
9658
trigdata.tg_trigtuple = ExecFetchSlotHeapTuple(slot, false, NULL);
9650
9659
trigdata.tg_trigslot = slot;
9651
9660
trigdata.tg_newtuple = NULL;
9661
+ trigdata.tg_newslot = NULL;
9652
9662
trigdata.tg_trigger = &trig;
9653
9663
9654
9664
fcinfo->context = (Node *) &trigdata;
9655
9665
9656
9666
RI_FKey_check_ins(fcinfo);
9667
+
9668
+ MemoryContextReset(perTupCxt);
9657
9669
}
9658
9670
9671
+ MemoryContextSwitchTo(oldcxt);
9672
+ MemoryContextDelete(perTupCxt);
9659
9673
table_endscan(scan);
9660
9674
UnregisterSnapshot(snapshot);
9661
9675
ExecDropSingleTupleTableSlot(slot);
0 commit comments