agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@kurilemu.de>
To: Radim Marek <radim@boringsql.com>
Cc: Antonin Houska <ah@cybertec.at>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: REPACK (CONCURRENTLY) might keep dropped-column data
Date: Sat, 3 Oct 2026 13:35:14 +0200
Message-ID: <asDkn09-y9N1_FJQ@alvherre.pgsql> (raw)
In-Reply-To: <CAJgoLkLWCw6+v6zL5bb3Tjvz=+EZ169mFrmpOh7xd45D2tSxrA@mail.gmail.com>

On 2026-Sep-30, Radim Marek wrote:

> Ok, I can't add much to the implementation discussion, but I can confirm
> the patch resolves both use cases I reported.

Thank you, I have pushed it to both branches after adjusting the test
case a bit more.

I also noticed a problem in the implementation.  We originally did this:

        CompactAttribute *attr = TupleDescCompactAttr(desc, i);
        varlena    *varlena_dst;

        if (attr->attisdropped)
+       {
+           dest->tts_isnull[i] = true;
            continue;
+       }
        if (attr->attlen != -1)
            continue;
        if (slot_attisnull(dest, i + 1))
            continue;

        slot_getsomeattrs(dest, i + 1);


Notice the slot_getsomeattrs() at the bottom: that is saying that if
the slot has not yet been deformed up to this attribute, then a
subsequent pass over the loop might overwrite the change of
dest->tts_isnull[] we did for this attribute!  In order to do this
correctly, we must ensure that the slot has been deformed up to that
point, and _then_ we can modify tts_isnull.  So I added another
slot_getsomeattrs() call inside the attisdropped() block.  But, really,
the case where tts_isnull is already true for dropped columns is by far
the most common; it would be a shame to have to deform a bunch of
attributes only for there to be nothing to do.  So I threw in a test
that the attribute is not already marked as null.


        if (attr->attisdropped)
+       {
+           if (!slot_attisnull(dest, i + 1))
+           {
+               slot_getsomeattrs(dest, i + 1);
+               dest->tts_isnull[i] = true;
+           }
            continue;
+       }

This way, we don't waste work.

(In practice, I don't expect this to have any effect, because the slot
uses the Virtual tts_ops, so it doesn't require deforming.  But better
to do things by the book just in case.)

Thanks,

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Puedes vivir sólo una vez, pero si lo haces bien, una vez es suficiente"






view thread (7+ messages)  latest in thread

Message-ID: <asDkn09-y9N1_FJQ@alvherre.pgsql>
Permalink:  ../asDkn09-y9N1_FJQ@alvherre.pgsql/
Also on:    postgresql.org/message-id/asDkn09-y9N1_FJQ@alvherre.pgsql

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@kurilemu.de, radim@boringsql.com, ah@cybertec.at, pgsql-hackers@lists.postgresql.org
  Subject: Re: REPACK (CONCURRENTLY) might keep dropped-column data
  In-Reply-To: <asDkn09-y9N1_FJQ@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox