Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whE6o-0005cw-1F for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 22:17:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whE6m-002xkB-2s for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 22:17:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whE6m-002xk0-1d for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2026 22:17:41 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1whE6k-000000003JM-3fve for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2026 22:17:40 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4gvwZZ5WXQz49Px6; Wed, 08 Jul 2026 01:17:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783462647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=015cY/PwSv9nwUUjHDv3oCz9+y/jKh7Iv7oGMearxYQ=; b=qTo9C/Ibk+OcwRqabnRyfRCoraa4N60D077RnB061jOe9MjkwvJ5wDcue4uf+uA07FV5ii ErdtC7NZIH2xIFXQVNs3KyNV8uagScOtoPHuiRrzlPRFI6L4bPOByY1k4FuWqknmVQTGjY ePvtfy1/DCkTAqp/FRbvW4mlzd+KggAZ7qSVASlD7WOszgCg3R/21l9lmkxo2Eeo+eS1tN jNYca6gbltUN7ErGa3dNZOeWWAV43ziT3OeNLcNz4kTP2PIytY5vJ5a4BsWVw2ba5Xcs/n ZQljTuhd2x9idueAyXkYMfWcAcqpa/rzjpUB/Puh8z7CDlPEjDnwdt6W04dLNg== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1783462647; b=QW9MTt6Q9yjoKVUOqAW7yK5faTW/o43GWbzEnc5ShBbSzYEXYcHJZJXBKO/ME0fWDNcNFl VJ4T+UfSlWYFHp76F7oOaEpy+RVpi69F6Ea9/uZ+qNXgzIPVhbQVMBqnkuXw6vgln5TRw6 lyZkQ7OUhGgHQ8BMGxvNMwFfsfJG89LFufAYIgGLx5kwpev5n6aPKKyPH/w8YcO54ZslGc MHLJ6BRdJ5fm5l/fGhEzd5ePJDoHfLEEo9yfg2YjYk4aaK7AUKsvf6pCMcm+LQDWEw9DzS NsljnXtNri4fqhOKIKEE/LUQWZomU0DpA4iSm5A8qT4sTxY1U3KdROzV0w5jGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783462647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=015cY/PwSv9nwUUjHDv3oCz9+y/jKh7Iv7oGMearxYQ=; b=pJya1ORX5iO1sbgsso710dzcItTL9iLRs5FC0gtUQhd4naRdnypPTrLZMgRxc0EwvoLS+8 jnQZS67FZFzbUe+dPcHJHMk1cShggXUO8fBgIpTGwGSIxb5y95IBIhAdq9s+b24po5KKRY eirumZHK8szexDAQKWK1SU/NX8nyDZwGrlhs+/MhaV4MYZV0LuApXPr6E862Wxrde64GsT zn6gIsldHWghlqtYkZvS+ISosz8sB0LGM8uQMQNL4l4M1DSUl/6qRXPl1o1+uAeG5vRGFI Kn3COqakMsbQb/o0vIeztHLm0rXr/W0hOYmK9zalQ6Q8alT+PPbiZ+Edy151+g== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <4ae3a6dd-a4ae-43f9-9625-4dbf2084f790@iki.fi> Date: Wed, 8 Jul 2026 01:17:25 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: heapam_tuple_complete_speculative : remove unnecessary tuple fetch To: Xuneng Zhou , Japin Li , Chao Li Cc: PostgreSQL Hackers References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 31/03/2026 04:09, Xuneng Zhou wrote: > On Tue, Mar 24, 2026 at 8:16 PM Japin Li wrote: >>> 在 2026年3月24日,14:57,Chao Li 写道: >>> 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 have a slightly different theory on how it came to be. Before commit 5db6df0c011, the heap_finish_speculative() and heap_abort_speculative() functions took HeapTuple as argument, but only needed the TID from it (tuple->t_self). Commit 5db6df0c011 changed it so that they are passed just the TID directly, because with that commit, the caller didn't have a HeapTuple readily at hand anymore. But the commit *also* made the caller fetch the tuple. So I think during the development of that patch, at some point the caller really had to fetch the tuple, so that it could pass it to the heap_finish/abort_speculative() functions. Those functions were later changed to take just the TID, but we forgot to change the caller to take advantage of that. Anyway, doesn't matter how exactly we got here, the end result is the same, and the patch looks good to me. >>> 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. Committed, thanks! - Heikki