Re: ExecForceStoreHeapTuple() loses tts_tid, so ORDER BY-op index scans project an invalid ctid

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Greg Burd <greg(at)burd(dot)me>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: ExecForceStoreHeapTuple() loses tts_tid, so ORDER BY-op index scans project an invalid ctid
Date: 2026-09-09 00:03:46
Message-ID: aqCiYp8QjIXFckiN@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 08, 2026 at 01:28:22PM -0400, Greg Burd wrote:
> ExecForceStoreHeapTuple() does not set slot->tts_tid when the target
> slot is a TTS_IS_BUFFERTUPLE slot. Any plan that re-stores a heap tuple
> through it and then projects ctid therefore gets (4294967295,0) instead
> of the row's real heap TID.

Oops.

My question would be what kind of testing you have done to spot that..

> ExecClearTuple() reaches tts_buffer_heap_clear(), which does
> ItemPointerSetInvalid(&slot->tts_tid). The tuple is then copied in, but
> tts_tid is left invalid. The sibling path, ExecStoreHeapTuple() ->
> tts_heap_store_tuple() — *does* slot->tts_tid = tuple->t_self, so this
> reads as a plain asymmetry rather than an intentional choice.

That's strange. Once thing that I can see why scanning this file is
the same code pattern in tts_buffer_heap_copyslot(), where a slot is
similarly cleared in a copy-paste fashion.

Andres?
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2026-09-09 00:03:57 Re: pg_dump: assert failure sorting casts/transforms
Previous Message Lucas Jeffrey 2026-09-09 00:00:31 [PATCH] Optimization: avoid repeated strlen() calls in function CreateTriggerFiringOn when parsing trigger arguments