Re: Adding REPACK [concurrently] - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Adding REPACK [concurrently]
Date
Msg-id 202604062213.cgo352cdsgsm@alvherre.pgsql
Whole thread Raw
In response to Re: Adding REPACK [concurrently]  (Mihail Nikalayeu <mihailnikalayeu@gmail.com>)
Responses Re: Adding REPACK [concurrently]
Re: Adding REPACK [concurrently]
RE: Adding REPACK [concurrently]
Re: Adding REPACK [concurrently]
Re: Adding REPACK [concurrently]
List pgsql-hackers
Hello,

On 2026-Apr-06, Mihail Nikalayeu wrote:

> > Yeah but I don't want the virtual tuple to be materialized (which would
> > happen in tts_virtual_materialize if I set shouldFree=true).  The memory
> > should be freed in
> >                 ResetPerTupleExprContext(chgcxt->cc_estate);
> > anyway, right?  Maybe deserves a comment.
> 
> Not sure, ResetPerTupleExprContext resets just "ExecutorState".
> But slots are created in another memory context.
> 
> Also, we can't reset slot->tts_mcxt itself - it will free the slot also.

So what I ended up doing, is to just not change to the slot's context in
restore_tuple.  That was just dumb (mea culpa).  So all the memory we
allocate for the slot lives in the executor context, and goes away on
the ResetPerTupleExprContext call at the bottom of the loop.  BTW I
don't understand why you say that function only resets ExecutorState --
as far as I can tell, it does this

#define ResetPerTupleExprContext(estate) \
    do { \
        if ((estate)->es_per_tuple_exprcontext) \
            ResetExprContext((estate)->es_per_tuple_exprcontext); \
    } while (0)

which in turn does

#define ResetExprContext(econtext) \
    MemoryContextReset((econtext)->ecxt_per_tuple_memory)

which AFAICT is exactly what we want.

Anyway, here's the three missing parts.  I have not yet edited the
deadlock-checker one to protect autovacuum from processing tables under
repack.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/

Attachment

pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: Custom oauth validator options
Next
From: Zsolt Parragi
Date:
Subject: Re: Stack-based tracking of per-node WAL/buffer usage