Re: Foreign key isolation tests

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Rustam ALLAKOV <rustamallakov(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Foreign key isolation tests
Date: 2025-09-11 16:30:30
Message-ID: 202509111622.zdaxtors4wxy@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you, I pushed 0001 and 0002.

Regarding 0003,

On 2025-Aug-11, Paul A Jungwirth wrote:

> /*
> * We implement three isolation levels internally.
> - * The two stronger ones use one snapshot per database transaction;
> - * the others use one snapshot per statement.
> + * The weakest uses one snapshot per statement;
> + * the two stronger levels use one snapshot per database transaction.
> * Serializable uses predicate locks in addition to snapshots.
> * These macros should be used to check which isolation level is selected.
> */

The wording of the last sentence (which you don't change) is a bit
funny, because the macros aren't really to be used to check which
isolation level is selected (which an interested observer could
determine simply by looking at XactIsoLevel). What they do is implement
a layer on top of the selected isolation level -- they are there to know
which implementation to use depending on the isolation level.

I also think that, for the explanation about serializable, we should
change "in addition to snapshots" to "in addition to the snapshot",
calling out the fact that the transaction will in fact use a single
snapshot throughout.

So how about something like this? (I include the macros in question so
that we see exactly what we're talking about).

/*
* We implement three isolation levels internally.
* The weakest uses one snapshot per statement;
* the two stronger levels use one snapshot per database transaction.
* Serializable uses predicate locks in addition to the snapshot.
* These macros can be used to determine which implementation to use
* depending on the prevailing serialization level.
*/
#define IsolationUsesXactSnapshot() (XactIsoLevel >= XACT_REPEATABLE_READ)
#define IsolationIsSerializable() (XactIsoLevel == XACT_SERIALIZABLE)

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Porque Kim no hacía nada, pero, eso sí,
con extraordinario éxito" ("Kim", Kipling)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-09-11 16:36:04 Re: race condition in pg_class
Previous Message Ranier Vilela 2025-09-11 16:21:38 Re: PgStat_HashKey padding issue when passed by reference