public inbox for [email protected]
help / color / mirror / Atom feedFrom: Chao Li <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: heapam_tuple_complete_speculative : remove unnecessary tuple fetch
Date: Tue, 24 Mar 2026 14:56:28 +0800
Message-ID: <[email protected]> (raw)
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.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
[application/octet-stream] v1-0001-heapam_handler-remove-unused-tuple-fetch-in-specu.patch (1.7K, 2-v1-0001-heapam_handler-remove-unused-tuple-fetch-in-specu.patch)
download | inline diff:
From 576c596d20c67a92713da971e01a2b567901b76d Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Wed, 11 Mar 2026 14:14:57 +0800
Subject: [PATCH v1] heapam_handler: remove unused tuple fetch in speculative
completion
heapam_tuple_complete_speculative() fetched a tuple from the slot only to
free it immediately afterwards, without ever using it.
The function only needs slot->tts_tid to complete or abort the
speculative insertion, so remove the unnecessary fetch and pfree().
Author: Chao Li <[email protected]>
Reviewed-by:
Discussion: https://postgr.es/m/
---
src/backend/access/heap/heapam_handler.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 253a735b6c1..f0e2be3e85d 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -12,7 +12,7 @@
*
*
* NOTES
- * This files wires up the lower level heapam.c et al routines with the
+ * This file wires up the lower level heapam.c et al routines with the
* tableam abstraction.
*
*-------------------------------------------------------------------------
@@ -295,17 +295,11 @@ static void
heapam_tuple_complete_speculative(Relation relation, TupleTableSlot *slot,
uint32 specToken, bool succeeded)
{
- bool shouldFree = true;
- HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
-
/* 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);
}
static TM_Result
--
2.50.1 (Apple Git-155)
view thread (4+ messages) latest in thread
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: [email protected]
Cc: [email protected], [email protected]
Subject: Re: heapam_tuple_complete_speculative : remove unnecessary tuple fetch
In-Reply-To: <[email protected]>
* 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