Re: Tuples inserted and deleted by the same transaction - Mailing list pgsql-hackers

From Matthias van de Meent
Subject Re: Tuples inserted and deleted by the same transaction
Date
Msg-id CAEze2Wi3XptG2UheAhRDMGAK7KCn-Nqed55xHCPtec1O9XVLrA@mail.gmail.com
Whole thread Raw
In response to Re: Tuples inserted and deleted by the same transaction  (Pantelis Theodosiou <ypercube@gmail.com>)
List pgsql-hackers
On Tue, 13 Sept 2022 at 12:40, Pantelis Theodosiou <ypercube@gmail.com> wrote:
>
> Forgive me if this is not related but if there is a savepoint between
> the insertion and deletion, wouldn't it be possible for the
> transaction to recover the deleted tuples?

Savepoints result in changed TransactionIds (well, subtransactions
with their own ids), so if a tuple was created before a savepoint and
deleted after, the values in xmin and xmax would be different, as you
can see in the following:

matthias=> CREATE TABLE tst(i int);
matthias=> BEGIN; INSERT INTO tst VALUES (1); SAVEPOINT s1; DELETE
FROM tst; ROLLBACK TO SAVEPOINT s1;
CREATE TABLE
BEGIN
INSERT 0 1
SAVEPOINT
DELETE 1
ROLLBACK
matthias=*> SELECT xmin, xmax FROM tst;
 xmin  | xmax
-------+-------
 62468 | 62469
(1 row)

Note that this row has different xmin/xmax from being created and
deleted in different subtransactions. This means that this needs no
specific handling in the HTSVH code that Laurenz asked about.


Kind regards,

Matthias van de Meent



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: pgsql: Doc: Explain about Column List feature.
Next
From: Peter Eisentraut
Date:
Subject: Re: ICU for global collation