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

From Laurenz Albe
Subject Re: Tuples inserted and deleted by the same transaction
Date
Msg-id 2e215df8b26d665fa7152157707c0e5afd0db02e.camel@cybertec.at
Whole thread Raw
In response to Re: Tuples inserted and deleted by the same transaction  (Nikita Malakhov <hukutoc@gmail.com>)
Responses Re: Tuples inserted and deleted by the same transaction
Re: Tuples inserted and deleted by the same transaction
Re: Tuples inserted and deleted by the same transaction
List pgsql-hackers
On Tue, 2022-09-13 at 11:47 +0300, Nikita Malakhov wrote:
> On Tue, Sep 13, 2022 at 11:06 AM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
> > Shouldn't such tuples be considered dead right away, even if the inserting
> > transaction is still active?  That would allow cleaning them up even before
> > the transaction is done.
> > 
> > There is this code in HeapTupleSatisfiesVacuumHorizon:
> > 
> >         else if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmin(tuple)))
> >         {
> >             [...]
> >             /* inserted and then deleted by same xact */
> >             if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetUpdateXid(tuple)))
> >                 return HEAPTUPLE_DELETE_IN_PROGRESS;
> > 
> > Why HEAPTUPLE_DELETE_IN_PROGRESS and not HEAPTUPLE_DEAD?
>
> Please correct me if I'm wrong, despite tuples being inserted and deleted by the same 
> transaction - they are visible inside the transaction and usable by it, so considering them
> dead and cleaning up during execution is a bad idea until the transaction is ended.

But once they are deleted or updated, even the transaction that created them cannot
see them any more, right?

Yours,
Laurenz Albe



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [PATCH v1] fix potential memory leak in untransformRelOptions
Next
From: Alvaro Herrera
Date:
Subject: Re: pgsql: Prefetch data referenced by the WAL, take II.