Skip to content

Commit 7a2fe85

Browse files
committed
Add some notes about why it's not a bug that RI_FKey_check calls
HeapTupleSatisfiesItself without doing LockBuffer first. This code is a bit fragile, but AFAICS it's not actually broken.
1 parent e06fda0 commit 7a2fe85

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/backend/utils/adt/ri_triggers.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1919
*
20-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.87 2006/08/21 19:15:29 tgl Exp $
20+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.88 2006/08/27 21:41:21 tgl Exp $
2121
*
2222
* ----------
2323
*/
@@ -212,9 +212,19 @@ RI_FKey_check(PG_FUNCTION_ARGS)
212212
}
213213

214214
/*
215-
* We should not even consider checking the row if it is no longer valid
216-
* since it was either deleted (doesn't matter) or updated (in which case
217-
* it'll be checked with its final values).
215+
* We should not even consider checking the row if it is no longer valid,
216+
* since it was either deleted (so the deferred check should be skipped)
217+
* or updated (in which case only the latest version of the row should
218+
* be checked). Test its liveness with HeapTupleSatisfiesItself.
219+
*
220+
* NOTE: The normal coding rule is that one must acquire the buffer
221+
* content lock to call HeapTupleSatisfiesFOO. We can skip that here
222+
* because we know that AfterTriggerExecute just fetched the tuple
223+
* successfully, so there cannot be a VACUUM compaction in progress
224+
* on the page (either heap_fetch would have waited for the VACUUM,
225+
* or the VACUUM's LockBufferForCleanup would be waiting for us to drop
226+
* pin). And since this is a row inserted by our open transaction,
227+
* no one else can be entitled to change its xmin/xmax.
218228
*/
219229
Assert(new_row_buf != InvalidBuffer);
220230
if (!HeapTupleSatisfiesItself(new_row->t_data, new_row_buf))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy