Re: WIP: System Versioned Temporal Table

From: Simon Riggs <simon(dot)riggs(at)enterprisedb(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Surafel Temesgen <surafel3000(at)gmail(dot)com>, Ryan Lambert <ryan(at)rustprooflabs(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Rémi Lapeyre <remi(dot)lapeyre(at)lenstra(dot)fr>, Eli Marmor <eli(at)netmask(dot)it>, David Steele <david(at)pgmasters(dot)net>, Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Georgios <gkokolatos(at)protonmail(dot)com>
Subject: Re: WIP: System Versioned Temporal Table
Date: 2021-01-07 17:59:39
Message-ID: CANbhV-EZu-SHXERZ=Bbq5g+ePi7QUX_0WgLtRsove_Jiigtaaw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jan 4, 2021 at 2:24 PM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> Please also note the v7 patch cannot be applied to the current HEAD. I'm switching the patch as Waiting on Author.

Surafel, please say whether you are working on this or not. If you
need help, let us know.

On Tue, 7 Jan 2020 at 10:33, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote:
> I think that the start and end timestamps represent the period where
> that version of the row was active. So UPDATE should modify the start
> timestamp of the new version to the same value with the end timestamp
> of the old version to the updated time. Thus, I don't think adding
> start timestamp to PK doesn't work as expected. That hinders us from
> rejecting rows with the same user-defined unique key because start
> timestamps is different each time of inserts. I think what Surafel is
> doing in the current patch is correct. Only end_timestamp = +infinity
> rejects another non-historical (= live) version with the same
> user-defined unique key.

The end_time needs to be updated when a row is updated, so it cannot
form part of the PK. If you try to force that to happen, then logical
replication will not work with system versioned tables, which would be
a bad thing. So *only* start_time should be added to the PK to make
this work. (A later comment also says the start_time needs to be
updated, which makes no sense!)

On Wed, 23 Oct 2019 at 21:03, Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com> wrote:
> I don't see any error handling for transaction anomalies. In READ
> COMMITTED, you can easily end up with a case where the end time comes
> before the start time. I don't even see anything constraining start
> time to be strictly inferior to the end time. Such a constraint will be
> necessary for application-time periods (which your patch doesn't address
> at all but that's okay).

I don't see how it can have meaning to have an end_time earlier than a
start_time, so yes that should be checked. Having said that, if we use
a statement timestamp on row insertion then, yes, the end_time could
be earlier than start time, so that is just wrong. Ideally we would
use commit timestamp and fill the values in later. So the only thing
that makes sense for me is to use the dynamic time of insertion while
we hold the buffer lock, otherwise we will get anomalies.

The work looks interesting and I will be doing a longer review.

--
Simon Riggs http://www.EnterpriseDB.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2021-01-07 18:11:44 Re: new heapcheck contrib module
Previous Message Mark Dilger 2021-01-07 17:32:53 Re: new heapcheck contrib module