Re: [PATCH] Corruption Issue: Fix missing tts_tid in ExecForceStoreHeapTuple

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>, Greg Burd <greg(at)burd(dot)me>
Cc: pgsql-hackers(at)postgresql(dot)org, zhong950419(at)gmail(dot)com, andres(at)anarazel(dot)de, nik(at)postgres(dot)ai, virender(dot)cse(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org, michael(at)paquier(dot)xyz, dilipbalaut(at)gmail(dot)com
Subject: Re: [PATCH] Corruption Issue: Fix missing tts_tid in ExecForceStoreHeapTuple
Date: 2026-10-31 08:50:46
Message-ID: 79ba7164-f924-4ca5-8012-b5a9639bbd96@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 30/10/2026 18:11, Nathan Bossart wrote:
> --- a/src/backend/executor/execTuples.c
> +++ b/src/backend/executor/execTuples.c
> @@ -1752,6 +1752,8 @@ ExecForceStoreHeapTuple(HeapTuple tuple,
> TupleTableSlot *slot,
> bool shouldFree)
> {
> + ItemPointerData tid = tuple->t_self;
> +
> if (TTS_IS_HEAPTUPLE(slot))
> {
> ExecStoreHeapTuple(tuple, slot, shouldFree);
> @@ -1784,6 +1786,13 @@ ExecForceStoreHeapTuple(HeapTuple tuple,
> pfree(tuple);
> }
> }
> +
> + /*
> + * ExecClearTuple() invalidated the slot's TID, so we need to set it again
> + * here. Note that the tuple might have already been freed, so we use the
> + * copy of its TID that we saved above.
> + */
> + slot->tts_tid = tid;
> }
>
> /*
The comment sounds wrong to me. This isn't restoring the old TID that
was in the slot previously, it's setting the new TID from 'tuple'. Or am
I missing something?

For same reason, the local variable seems pointless; you could just do:

slot->tts_tid = tuple->t_self;

The comment in Greg's earlier version (v9) said:

> + /*
> + * Store the TID from the local copy taken on entry since the stores above
> + * may have freed the tuple.
> + */
> + slot->tts_tid = tid;

But I don't see how the store might've free'd the tuple. If it did, we'd
have trouble anyway.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-10-31 08:56:05 Re: ALTER COLLATION misses errcode
Previous Message Zhang Ziming 2026-10-31 06:56:46 RE: [PATCH] Restrict partial unique index estimates to base quals