Re: Repeatable Read Isolation Level "transaction start time"

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Repeatable Read Isolation Level "transaction start time"
Date: 2024-10-05 16:59:00
Message-ID: 368259fb-fd2e-4a05-89e9-a733fae6d964@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/5/24 02:14, Peter J. Holzer wrote:
> On 2024-09-25 18:09:44 -0400, Tom Lane wrote:
>> "Peter J. Holzer" <hjp-pgsql(at)hjp(dot)at> writes:

>> Admittedly, that would normally not be a very long interval if BEGIN
>> did both things ... but on a busy system you could lose the CPU for
>> awhile in between.
>
> Assuming that the system does have a global clock of sufficiently
> fine resolution which returns strictly monotonically increasing
> timestamps[1], I think the following is true:
>
> Every snapshot divides the set of transactions into two non-overlapping
> subsets: Those which have committed early enough that their effects are
> visible in the snapshot and those which haven't. Let's call the first set
> the "earlier" transactions and the second the "later" transactions. Let's
> call the current transaction c and any transaction in the earlier set e
> (we ignore the later transactions for now).
>
> Performing a commit and taking a snapshot take some time, but there
> should be a time t_C(e) in each commit and t_S(c) in the snapshot, such
> that t_C(e) < t_S(c) for each "earlier" transaction.

Assuming t_C is time of commit and t_S is time of snapshot, is the above
not the crux of the matter? Namely when in the current transaction the
snapshot is actually taken. That would determine what constitutes an
earlier visible transaction relative to the current transaction. In
other words I am not seeing how this changes anything?

>
> Within each transaction each timestamp t which could be visible outside
> of the transaction must have been obtained before the commit,
> so t(e) < t_C(e) < t_S(c).
>
> If we choose the transaction_timestamp to be >= t_S, then
> transaction_timestamp(e) < t_C(e) < t_S(c) <= transaction_timestamp(c)
> and therefore
> transaction_timestamp(e) < transaction_timestamp(c)
>
> Such a guarantee might be useful for some applications and it's not
> (IMHO) an entirely unreasonable assumption, but it's not true for
> PostgreSQL. So a programmer should be aware of that.
>
> hp

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2024-10-05 17:21:54 Re: Repeatable Read Isolation Level "transaction start time"
Previous Message Adrian Klaver 2024-10-05 16:26:22 Re: grant connect to all databases