Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62c42a0

Browse files
Jan WieckJan Wieck
authored andcommitted
Added global variable to have RI triggers override
time qualification of HeapTupleSatisfiesSnapshot() Jan
1 parent d31ff14 commit 62c42a0

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

src/backend/commands/trigger.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "utils/builtins.h"
2525
#include "utils/inval.h"
2626
#include "utils/syscache.h"
27+
#include "utils/tqual.h"
2728

2829
DLLIMPORT TriggerData *CurrentTriggerData = NULL;
2930

@@ -1151,6 +1152,13 @@ deferredTriggerExecute(DeferredTriggerEvent event, int itemno)
11511152
if (rettuple != NULL && rettuple != &oldtuple && rettuple != &newtuple)
11521153
pfree(rettuple);
11531154

1155+
/* ----------
1156+
* Might have been a referential integrity constraint trigger.
1157+
* Reset the snapshot overriding flag.
1158+
* ----------
1159+
*/
1160+
ReferentialIntegritySnapshotOverride = false;
1161+
11541162
/* ----------
11551163
* Release buffers and close the relation
11561164
* ----------

src/backend/utils/adt/ri_triggers.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* 1999 Jan Wieck
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.9 1999/12/08 20:41:22 wieck Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.10 1999/12/10 12:34:13 wieck Exp $
1010
*
1111
* ----------
1212
*/
@@ -163,6 +163,7 @@ RI_FKey_check (FmgrInfo *proinfo)
163163

164164
trigdata = CurrentTriggerData;
165165
CurrentTriggerData = NULL;
166+
ReferentialIntegritySnapshotOverride = true;
166167

167168
/* ----------
168169
* Check that this is a valid trigger call on the right time and event.
@@ -489,6 +490,7 @@ RI_FKey_cascade_del (FmgrInfo *proinfo)
489490

490491
trigdata = CurrentTriggerData;
491492
CurrentTriggerData = NULL;
493+
ReferentialIntegritySnapshotOverride = true;
492494

493495
/* ----------
494496
* Check that this is a valid trigger call on the right time and event.
@@ -686,6 +688,7 @@ RI_FKey_cascade_upd (FmgrInfo *proinfo)
686688

687689
trigdata = CurrentTriggerData;
688690
CurrentTriggerData = NULL;
691+
ReferentialIntegritySnapshotOverride = true;
689692

690693
/* ----------
691694
* Check that this is a valid trigger call on the right time and event.
@@ -911,6 +914,7 @@ RI_FKey_restrict_del (FmgrInfo *proinfo)
911914

912915
trigdata = CurrentTriggerData;
913916
CurrentTriggerData = NULL;
917+
ReferentialIntegritySnapshotOverride = true;
914918

915919
/* ----------
916920
* Check that this is a valid trigger call on the right time and event.
@@ -1118,6 +1122,7 @@ RI_FKey_restrict_upd (FmgrInfo *proinfo)
11181122

11191123
trigdata = CurrentTriggerData;
11201124
CurrentTriggerData = NULL;
1125+
ReferentialIntegritySnapshotOverride = true;
11211126

11221127
/* ----------
11231128
* Check that this is a valid trigger call on the right time and event.
@@ -1333,6 +1338,7 @@ RI_FKey_setnull_del (FmgrInfo *proinfo)
13331338

13341339
trigdata = CurrentTriggerData;
13351340
CurrentTriggerData = NULL;
1341+
ReferentialIntegritySnapshotOverride = true;
13361342

13371343
/* ----------
13381344
* Check that this is a valid trigger call on the right time and event.
@@ -1540,6 +1546,7 @@ RI_FKey_setnull_upd (FmgrInfo *proinfo)
15401546

15411547
trigdata = CurrentTriggerData;
15421548
CurrentTriggerData = NULL;
1549+
ReferentialIntegritySnapshotOverride = true;
15431550

15441551
/* ----------
15451552
* Check that this is a valid trigger call on the right time and event.
@@ -1758,6 +1765,7 @@ RI_FKey_setdefault_del (FmgrInfo *proinfo)
17581765

17591766
trigdata = CurrentTriggerData;
17601767
CurrentTriggerData = NULL;
1768+
ReferentialIntegritySnapshotOverride = true;
17611769

17621770
/* ----------
17631771
* Check that this is a valid trigger call on the right time and event.
@@ -2005,6 +2013,7 @@ RI_FKey_setdefault_upd (FmgrInfo *proinfo)
20052013

20062014
trigdata = CurrentTriggerData;
20072015
CurrentTriggerData = NULL;
2016+
ReferentialIntegritySnapshotOverride = true;
20082017

20092018
/* ----------
20102019
* Check that this is a valid trigger call on the right time and event.

src/backend/utils/time/tqual.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.32 1999/10/06 21:58:11 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.33 1999/12/10 12:34:14 wieck Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -24,6 +24,8 @@ Snapshot SnapshotDirty = &SnapshotDirtyData;
2424
Snapshot QuerySnapshot = NULL;
2525
Snapshot SerializableSnapshot = NULL;
2626

27+
bool ReferentialIntegritySnapshotOverride = false;
28+
2729
/*
2830
* XXX Transaction system override hacks start here
2931
*/
@@ -493,6 +495,9 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot)
493495
if (AMI_OVERRIDE)
494496
return true;
495497

498+
if (ReferentialIntegritySnapshotOverride)
499+
return HeapTupleSatisfiesNow(tuple);
500+
496501
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
497502
{
498503
if (tuple->t_infomask & HEAP_XMIN_INVALID)
@@ -606,6 +611,9 @@ void
606611
SetQuerySnapshot(void)
607612
{
608613

614+
/* Initialize snapshot overriding to false */
615+
ReferentialIntegritySnapshotOverride = false;
616+
609617
/* 1st call in xaction */
610618
if (SerializableSnapshot == NULL)
611619
{

src/include/utils/tqual.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: tqual.h,v 1.25 1999/09/29 16:06:28 wieck Exp $
10+
* $Id: tqual.h,v 1.26 1999/12/10 12:34:15 wieck Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -36,6 +36,8 @@ extern Snapshot SnapshotDirty;
3636
extern Snapshot QuerySnapshot;
3737
extern Snapshot SerializableSnapshot;
3838

39+
extern bool ReferentialIntegritySnapshotOverride;
40+
3941
#define IsSnapshotNow(snapshot) ((Snapshot) snapshot == SnapshotNow)
4042
#define IsSnapshotSelf(snapshot) ((Snapshot) snapshot == SnapshotSelf)
4143
#define IsSnapshotAny(snapshot) ((Snapshot) snapshot == SnapshotAny)

0 commit comments

Comments
 (0)