Re: heapam_tuple_complete_speculative : remove unnecessary tuple fetch

From: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
To: Japin Li <japinli(at)hotmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: heapam_tuple_complete_speculative : remove unnecessary tuple fetch
Date: 2026-03-31 01:09:47
Message-ID: CABPTF7XJ3gv+R+4+eGMX=ggN1m6bD7=rbxDi-cHN+GJUV5jSYg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Mar 24, 2026 at 8:16 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
>
>
> > 在 2026年3月24日,14:57,Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> 写道:
> >
> > Hi,
> >
> > While reviewing another patch, I noticed this:
> > ```
> > static void
> > heapam_tuple_complete_speculative(Relation relation, TupleTableSlot *slot,
> > uint32 specToken, bool succeeded)
> > {
> > bool shouldFree = true;
> > HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree); // <== tuple is not used
> >
> > /* adjust the tuple's state accordingly */
> > if (succeeded)
> > heap_finish_speculative(relation, &slot->tts_tid);
> > else
> > heap_abort_speculative(relation, &slot->tts_tid);
> >
> > if (shouldFree)
> > pfree(tuple);
> > }
> > ```
> >
> > In this function, tuple is not used at all, so there seems to be no need to fetch it, and shouldFree is thus not needed either.
> >
> > This appears to have been there since 5db6df0c011, where the function was introduced. It looks like a copy-pasto from the previous function, heapam_tuple_insert_speculative(), which does need to fetch and possibly free the tuple.
> >
> > I tried simply removing ExecFetchSlotHeapTuple(), and "make check" still passes. But I may be missing something, so I’d like to confirm.
> >
> > The attached patch just removes the unused tuple and shouldFree from this function. As touching the file, I also fixed a typo in the file header comment.
>
> Makes sense! All test cases passed with make check-world.
>

+1, looks like a simple copy-pasto and the patch LGTM.

--
Best,
Xuneng

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2026-03-31 02:16:59 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Previous Message Masahiko Sawada 2026-03-31 01:00:23 Re: Initial COPY of Logical Replication is too slow