Re: Tuples inserted and deleted by the same transaction

From: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
To: Pantelis Theodosiou <ypercube(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Nikita Malakhov <hukutoc(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Tuples inserted and deleted by the same transaction
Date: 2022-09-13 12:40:47
Message-ID: CAEze2Wi3XptG2UheAhRDMGAK7KCn-Nqed55xHCPtec1O9XVLrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 13 Sept 2022 at 12:40, Pantelis Theodosiou <ypercube(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2022-09-13 12:41:41 Re: ICU for global collation
Previous Message Alvaro Herrera 2022-09-13 12:11:38 Re: pgsql: Doc: Explain about Column List feature.