diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index d16d9a55843d2e91f9bcf018c570432f87f34ff6..695b216fb554ad93d6f4d79cf0f936be5baa0972 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -24,6 +24,7 @@ #include "utils/builtins.h" #include "utils/inval.h" #include "utils/syscache.h" +#include "utils/tqual.h" DLLIMPORT TriggerData *CurrentTriggerData = NULL; @@ -1151,6 +1152,13 @@ deferredTriggerExecute(DeferredTriggerEvent event, int itemno) if (rettuple != NULL && rettuple != &oldtuple && rettuple != &newtuple) pfree(rettuple); + /* ---------- + * Might have been a referential integrity constraint trigger. + * Reset the snapshot overriding flag. + * ---------- + */ + ReferentialIntegritySnapshotOverride = false; + /* ---------- * Release buffers and close the relation * ---------- diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index a9b5c7cf2d00f424207f196df41eaf107599615c..323c1050a6f1dd124c936a30f81a3c45364d2874 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -6,7 +6,7 @@ * * 1999 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.9 1999/12/08 20:41:22 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.10 1999/12/10 12:34:13 wieck Exp $ * * ---------- */ @@ -163,6 +163,7 @@ RI_FKey_check (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -489,6 +490,7 @@ RI_FKey_cascade_del (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -686,6 +688,7 @@ RI_FKey_cascade_upd (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -911,6 +914,7 @@ RI_FKey_restrict_del (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -1118,6 +1122,7 @@ RI_FKey_restrict_upd (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -1333,6 +1338,7 @@ RI_FKey_setnull_del (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -1540,6 +1546,7 @@ RI_FKey_setnull_upd (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -1758,6 +1765,7 @@ RI_FKey_setdefault_del (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. @@ -2005,6 +2013,7 @@ RI_FKey_setdefault_upd (FmgrInfo *proinfo) trigdata = CurrentTriggerData; CurrentTriggerData = NULL; + ReferentialIntegritySnapshotOverride = true; /* ---------- * Check that this is a valid trigger call on the right time and event. diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 97080e010f9554edd1bfda3b5b4351a766409900..4a96c5736cfbc94da7cb1bb64a7b473116647377 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.32 1999/10/06 21:58:11 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.33 1999/12/10 12:34:14 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -24,6 +24,8 @@ Snapshot SnapshotDirty = &SnapshotDirtyData; Snapshot QuerySnapshot = NULL; Snapshot SerializableSnapshot = NULL; +bool ReferentialIntegritySnapshotOverride = false; + /* * XXX Transaction system override hacks start here */ @@ -493,6 +495,9 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) if (AMI_OVERRIDE) return true; + if (ReferentialIntegritySnapshotOverride) + return HeapTupleSatisfiesNow(tuple); + if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED)) { if (tuple->t_infomask & HEAP_XMIN_INVALID) @@ -606,6 +611,9 @@ void SetQuerySnapshot(void) { + /* Initialize snapshot overriding to false */ + ReferentialIntegritySnapshotOverride = false; + /* 1st call in xaction */ if (SerializableSnapshot == NULL) { diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index d8aa6638f6aa109856c4465acced6560bf872ac0..89314764ea60cf5c8240c860febf8c24d078faef 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: tqual.h,v 1.25 1999/09/29 16:06:28 wieck Exp $ + * $Id: tqual.h,v 1.26 1999/12/10 12:34:15 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -36,6 +36,8 @@ extern Snapshot SnapshotDirty; extern Snapshot QuerySnapshot; extern Snapshot SerializableSnapshot; +extern bool ReferentialIntegritySnapshotOverride; + #define IsSnapshotNow(snapshot) ((Snapshot) snapshot == SnapshotNow) #define IsSnapshotSelf(snapshot) ((Snapshot) snapshot == SnapshotSelf) #define IsSnapshotAny(snapshot) ((Snapshot) snapshot == SnapshotAny)