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.94.2) (envelope-from ) id 1v9L3B-00G4Kj-FO for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 10:17:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v9L3A-00BNGt-Fd for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 10:17:35 +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.94.2) (envelope-from ) id 1v9L39-00BNGV-WD for pgsql-hackers@lists.postgresql.org; Thu, 16 Oct 2025 10:17:35 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v9L36-0024Z1-2K for pgsql-hackers@lists.postgresql.org; Thu, 16 Oct 2025 10:17:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=nrv0j4Jp5q5t7J2WAXmWEdmNV9iftD9E0YalkxkPrug=; b=krRVbX7IAo6oOFcMcpAkBAjcTl rfiNpyWeb2jHQDhsr0CNxCGUjVUsiJVpNCK8kWv2y2/Fciqd+Ux+AMczv1CdQqoWNCkM0BPglzW8D 1q0KmicUG6+RtQ/c/mNBjiYRExGLO0eOHfLBiGy1KqXV8cukxkt3dDeJQ/97zPJmHHYKpxwgohxtI oEO6XE8Y6dp4UrXoJP17wZ0cHtlGnTOXElXnKwf6dUP0+9jA1Wk1V2x93vq78kDy/Hj1kt1PlWahu Dg2g3Oc3dZOa66QZ8X2tFG5Vj87vxJ1cD7HeR2hmlVmAuJKsS3RSivPjQzBkaor7Dx8zqg34NelNL ZxE0YYcg==; Received: from [2409:11:4120:300:5b69:8361:468a:2953] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v9L2x-006IPz-0A; Thu, 16 Oct 2025 10:17:25 +0000 Date: Thu, 16 Oct 2025 19:17:06 +0900 (JST) Message-Id: <20251016.191706.731898842046838424.ishii@postgresql.org> To: michael@paquier.xyz Cc: li.evan.chao@gmail.com, tgl@sss.pgh.pa.us, pramsey@cleverelephant.ca, ojford@gmail.com, peter@eisentraut.org, krasiyan@gmail.com, vik@postgresfriends.org, andrew@tao11.riddles.org.uk, david@fetter.org, pgsql-hackers@lists.postgresql.org Subject: Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options From: Tatsuo Ishii In-Reply-To: References: <20251013.143941.1447453701514209859.ishii@postgresql.org> <20251014.192113.1554227757626092006.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Thu_Oct_16_19_17_06_2025_168)--" Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:5b69:8361:468a:2953 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Thu_Oct_16_19_17_06_2025_168)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thanks for the report. > Coverity thinks that this code has still some incorrect bits, and I > think that it is right to think so even on today's HEAD at > 02c171f63fca. > > In WinGetFuncArgInPartition()@nodeWindowAgg.c, we have the following > loop (keeping only the relevant parts: > do > { > [...] > else /* need to check NULL or not */ > { > /* get tuple and evaluate in partition */ > datum = gettuple_eval_partition(winobj, argno, > abs_pos, isnull, &myisout); > if (myisout) /* out of partition? */ > break; > if (!*isnull) > notnull_offset++; > /* record the row status */ > put_notnull_info(winobj, abs_pos, *isnull); > } > } while (notnull_offset < notnull_relpos); > > /* get tuple and evaluate in partition */ > datum = gettuple_eval_partition(winobj, argno, > abs_pos, isnull, &myisout); > > And Coverity is telling that there is no point in setting a datum in > this else condition to just override its value when we exit the while > loop. To me, it's a sigh that this code's logic could be simplified. To fix the issue, I think we can change: > datum = gettuple_eval_partition(winobj, argno, > abs_pos, isnull, &myisout); to: (void) gettuple_eval_partition(winobj, argno, abs_pos, isnull, &myisout); This explicitely stats that we ignore the return value from gettuple_eval_partition. I hope coverity understands this. > In passing, gettuple_eval_partition() is under-documented for me. Its > name refers to the fact that it gets a tuple and evaluates a > partition. Its top comment tells the same thing as the name of the > function, so it's a bit hard to say why it is useful with the code > written this way, and how others many benefit when attempting to reuse > it, or if it even makes sense to reuse it for other purposes. What about changing the comment this way? /* gettuple_eval_partition * get tuple in a patition and evaluate the window function's argument * expression on it. */ Attached is the patch for above. -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp ----Next_Part(Thu_Oct_16_19_17_06_2025_168)-- Content-Type: Application/Octet-Stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="v1-0001-Fix-coverity-complaint-about-WinGetFuncArgInParti.patch" RnJvbSBjMThkY2JjY2ZmN2JkN2M5NTI5NWJlZWRhYmIyMTE2Y2JiM2IzYmUyIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBUYXRzdW8gSXNoaWkgPGlzaGlpQHBvc3RncmVzcWwub3JnPgpE YXRlOiBUaHUsIDE2IE9jdCAyMDI1IDE5OjAwOjU2ICswOTAwClN1YmplY3Q6IFtQQVRDSCB2MV0g Rml4IGNvdmVyaXR5IGNvbXBsYWludCBhYm91dCBXaW5HZXR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