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 1wEWax-0046g2-3C for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Apr 2026 18:10:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEWax-00FpkK-0R for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Apr 2026 18:10:11 +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 1wEWaw-00FpkC-2n for pgsql-hackers@lists.postgresql.org; Sun, 19 Apr 2026 18:10:10 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wEWau-00000001nvM-35Ez for pgsql-hackers@lists.postgresql.org; Sun, 19 Apr 2026 18:10:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 63JIA2gF4126232; Sun, 19 Apr 2026 14:10:02 -0400 From: Tom Lane To: Peter Eisentraut cc: Paul A Jungwirth , Chao Li , PostgreSQL Hackers Subject: Re: SQL:2011 Application Time Update & Delete In-reply-to: References: <85ac7f0e-d95f-4377-ade0-8941fd328012@eisentraut.org> <7d63ddfa-c735-4dfe-8c7a-4f1e2a621058@eisentraut.org> <4606deaa-7d65-4f22-8a78-356c3180be9d@eisentraut.org> <53f1c094-3c29-4ef6-a9bd-dc2e7894ceb0@eisentraut.org> Comments: In-reply-to Peter Eisentraut message dated "Tue, 07 Apr 2026 13:53:13 +0200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <4126188.1776622192.0@sss.pgh.pa.us> Date: Sun, 19 Apr 2026 14:10:02 -0400 Message-ID: <4126231.1776622202@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4126188.1776622192.1@sss.pgh.pa.us> Peter Eisentraut writes: > I have committed the patches 0001 through 0003. Coverity is complaining that rsi.isDone may be used uninitialized in ExecForPortionOfLeftovers. It's correct: that function is not obeying the function call protocol, and it's only accidental that it's not failing. In ValuePerCall mode the caller is supposed to initialize isDone (and isnull too) before each call. The canonical reference for this is execSRF.c, and it does that. So I think we need something like the attached. I notice that execSRF.c also runs pgstat_init_function_usage and pgstat_end_function_usage around each call. That's not too important right now, but I wonder whether we should add it while we're looking at this. It would perhaps be important once we support user-defined withoutPortionProcs. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="v1-make-ExecForPortionOfLeftovers-obey-protocol.patch"; charset="us-ascii" Content-ID: <4126188.1776622192.2@sss.pgh.pa.us> Content-Description: v1-make-ExecForPortionOfLeftovers-obey-protocol.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor= /nodeModifyTable.c index ef2a6bc6e9d..b852b96839d 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -1514,6 +1514,7 @@ ExecForPortionOfLeftovers(ModifyTableContext *contex= t, rsi.expectedDesc =3D NULL; rsi.allowedModes =3D (int) (SFRM_ValuePerCall); rsi.returnMode =3D SFRM_ValuePerCall; + /* isDone is filled below */ rsi.setResult =3D NULL; rsi.setDesc =3D NULL; = @@ -1537,14 +1538,22 @@ ExecForPortionOfLeftovers(ModifyTableContext *cont= ext, */ while (true) { - Datum leftover =3D FunctionCallInvoke(fcinfo); + Datum leftover; + + /* Call the function one time */ + fcinfo->isnull =3D false; + rsi.isDone =3D ExprSingleResult; + leftover =3D FunctionCallInvoke(fcinfo); + + if (rsi.returnMode !=3D SFRM_ValuePerCall) + elog(ERROR, "without_portion function violated function call protocol"= ); = /* Are we done? */ if (rsi.isDone =3D=3D ExprEndResult) break; = if (fcinfo->isnull) - elog(ERROR, "Got a null from without_portion function"); + elog(ERROR, "got a null from without_portion function"); = /* * Does the new Datum violate domain checks? Row-level CHECK ------- =_aaaaaaaaaa0--