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 1w4viT-002hmp-0s for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 06:58:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4vhR-004qUr-1p for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 06:57:13 +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 1w4vhR-004qUZ-0y for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 06:57:13 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4vhJ-00000000kbI-3s0S for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 06:57:07 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-35ba749f441so802489a91.1 for ; Mon, 23 Mar 2026 23:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774335424; x=1774940224; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=oxJWT8s3zi18TN+YnL+nRZsCuXz2AkG4bVweeK/npR0=; b=bbsZvV59P+6Qwbv8o0M+6FjpoqL80hQOPb+1Or273Jw9GqOUJRnfF3vTEN1Vaf31p2 r7+6BUZLiclUkKKDVbfOkPb79QCy9SfSaSzCCQ1yPb11Z0m5e+IiwVsZDyfNQdTzH0/K Q+RhvtGjymo47Si2nUJPglsWqug0DoOvpqsLC9Wacu6Ppo6kgFPSN1Es4b/6MMmlGHQY VjaxQVXsk1dwyRvxYIa7TgdEXbriTaLpnmzAa8nBNRrVgRUqZbJgODPu7tYWUeeI9x5c wRuRVqICVxobrQVyJkB5kC62ZuY0+eIhWnvvbeXJJpstCH6Ce9BujC1EXSo80REJ74hr gcCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774335424; x=1774940224; h=to:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oxJWT8s3zi18TN+YnL+nRZsCuXz2AkG4bVweeK/npR0=; b=a9bP/8F9saB22PQNwvJprQ06X85S2YNktOHYU8T9ll1VZNbovMws8JOMGdD8ggn8tg aa0zrlN6AonTrg3Y5cfpnzfyD/WLPlP+I3fXRpd1SEBrySkeVyQk2D6tzaSyZylNk7lK SybE8svQl3uA6TM39a6vbP81/RAmUrYPb3FIZU90qdbOdkLiOrm+1b1Gt790WEGzKMnP FMpa+LfcSi+6NMcCFemBY6ZnBil7axEb6HH4ZeUJ9RMNFZiwqp2y4rnB24bt0HkNngjn KXubuhgkF7+tKY1XmZx0m3qCanrX261/GyKhZ0k8tfWCnTkd5c8mirlDi5YMfJAOpGIx m4Iw== X-Gm-Message-State: AOJu0YwfZPs7ysXH7l4smztunCt/WITv7S6faoCDvmvab1Oxhs5qibo1 S7ZzVMI/yr1fPKPBvRMFl+qekpU4YZkOyv5uiCu2beLtJhNToJwyicI3XciSuIBf X-Gm-Gg: ATEYQzyEPE8GuExTz7QZtnyfAqZPkJyaK3wI7Jw+xz+5qQO4RGBmkwVkgmek17z+J8C kK8BLlH2uE6Z15JBOgXZ3nraCUCuf7z8CKejeCPCGUtc7rOvwP3qNxlM5WV58Tdm3L468LexMV9 R2u4+V+YCEytcdke2xAcuchN8UHfo1wxPS2srhtzXrwmyg+50Snkpau236kJNGOPh9nObuYLLv7 Nn5HTNW+CRZNnIkLRrFOEngYH3HZLADZ+30TmU8LnkMBJfNII02GsGoIfovDGhOtKA30gX/0NYk 97NThwNmWTC0lcq22pV5Viwn6F6Nl4s3GdDl3uZo30+aA1HrT1U7Peq5HFz/113X9KR+4fdbbd9 4IsMLc57KFJEfIgX4PpmG8rs+pQUad1VDE+tTNm0Yr1Vph/JABjn7VcmsagPAroyLPGp6Z3MXgf VYz8ef/LqdOJUOsZWzKDmzNigEtFVoz8Q= X-Received: by 2002:a17:90b:3810:b0:353:5595:3247 with SMTP id 98e67ed59e1d1-35bd2c1a3cemr13041786a91.12.1774335424483; Mon, 23 Mar 2026 23:57:04 -0700 (PDT) Received: from smtpclient.apple ([103.62.49.186]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35c017477eesm568979a91.1.2026.03.23.23.57.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2026 23:57:03 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_03473D25-1D04-4FC6-A941-0861CAA3EEA3" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: heapam_tuple_complete_speculative : remove unnecessary tuple fetch Message-Id: Date: Tue, 24 Mar 2026 14:56:28 +0800 To: PostgreSQL Hackers X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_03473D25-1D04-4FC6-A941-0861CAA3EEA3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, While reviewing another patch, I noticed this: ``` static void heapam_tuple_complete_speculative(Relation relation, TupleTableSlot = *slot, uint32 = specToken, bool succeeded) { bool shouldFree =3D true; HeapTuple tuple =3D ExecFetchSlotHeapTuple(slot, true, = &shouldFree); // <=3D=3D 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=E2=80=99d 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/ --Apple-Mail=_03473D25-1D04-4FC6-A941-0861CAA3EEA3 Content-Disposition: attachment; filename=v1-0001-heapam_handler-remove-unused-tuple-fetch-in-specu.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-heapam_handler-remove-unused-tuple-fetch-in-specu.patch" Content-Transfer-Encoding: quoted-printable =46rom=20576c596d20c67a92713da971e01a2b567901b76d=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Wed,=2011=20Mar=202026=2014:14:57=20+0800=0ASubject:=20[PATCH=20= v1]=20heapam_handler:=20remove=20unused=20tuple=20fetch=20in=20= speculative=0A=20completion=0A=0Aheapam_tuple_complete_speculative()=20= fetched=20a=20tuple=20from=20the=20slot=20only=20to=0Afree=20it=20= immediately=20afterwards,=20without=20ever=20using=20it.=0A=0AThe=20= function=20only=20needs=20slot->tts_tid=20to=20complete=20or=20abort=20= the=0Aspeculative=20insertion,=20so=20remove=20the=20unnecessary=20fetch=20= and=20pfree().=0A=0AAuthor:=20Chao=20Li=20=0A= Reviewed-by:=0ADiscussion:=20https://postgr.es/m/=0A---=0A=20= src/backend/access/heap/heapam_handler.c=20|=208=20+-------=0A=201=20= file=20changed,=201=20insertion(+),=207=20deletions(-)=0A=0Adiff=20--git=20= a/src/backend/access/heap/heapam_handler.c=20= b/src/backend/access/heap/heapam_handler.c=0Aindex=20= 253a735b6c1..f0e2be3e85d=20100644=0A---=20= a/src/backend/access/heap/heapam_handler.c=0A+++=20= b/src/backend/access/heap/heapam_handler.c=0A@@=20-12,7=20+12,7=20@@=0A=20= =20*=0A=20=20*=0A=20=20*=20NOTES=0A-=20*=09=20=20This=20files=20wires=20= up=20the=20lower=20level=20heapam.c=20et=20al=20routines=20with=20the=0A= +=20*=09=20=20This=20file=20wires=20up=20the=20lower=20level=20heapam.c=20= et=20al=20routines=20with=20the=0A=20=20*=09=20=20tableam=20abstraction.=0A= =20=20*=0A=20=20= *-------------------------------------------------------------------------= =0A@@=20-295,17=20+295,11=20@@=20static=20void=0A=20= heapam_tuple_complete_speculative(Relation=20relation,=20TupleTableSlot=20= *slot,=0A=20=09=09=09=09=09=09=09=09=20=20uint32=20specToken,=20bool=20= succeeded)=0A=20{=0A-=09bool=09=09shouldFree=20=3D=20true;=0A-=09= HeapTuple=09tuple=20=3D=20ExecFetchSlotHeapTuple(slot,=20true,=20= &shouldFree);=0A-=0A=20=09/*=20adjust=20the=20tuple's=20state=20= accordingly=20*/=0A=20=09if=20(succeeded)=0A=20=09=09= heap_finish_speculative(relation,=20&slot->tts_tid);=0A=20=09else=0A=20=09= =09heap_abort_speculative(relation,=20&slot->tts_tid);=0A-=0A-=09if=20= (shouldFree)=0A-=09=09pfree(tuple);=0A=20}=0A=20=0A=20static=20TM_Result=0A= --=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_03473D25-1D04-4FC6-A941-0861CAA3EEA3--