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 1vAHpU-00GhwN-D6 for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Oct 2025 01:03:23 +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 1vAHpS-009fvO-6N for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Oct 2025 01:03:21 +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 1vAHpR-009fvF-TD for pgsql-hackers@lists.postgresql.org; Sun, 19 Oct 2025 01:03:20 +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 1vAHpP-002XT6-0O for pgsql-hackers@lists.postgresql.org; Sun, 19 Oct 2025 01:03:19 +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=SsHIvwVb6S8sHXs8Rf0x/PqLx7z/drlKPY+Ml1zXtyY=; b=xDlCLn32TD7yjFIt7UNBJGJDrC zEj9K94ixaqsehEJNom2WjNSv58yyJP0PDYQXwSVivoFspo31+JDuJpcwB/0xTdRn5EGPOo+bL23O 698oUUB8oxjCXk78GWnedXDIPGyYupG+7fAHJn8ERDKo+wgBs16O/3vUIlj6B66DrVC+z6HGdhn84 zKeIMtUYsViEIvpP9InLZw886uBhP83GDoHpLWYIdxiyAWWfWrd77bFf8fI2wkOG7z3RcGza7xekc cRmHTO0Tr2dCpNeOzpUd+lPxd6SpW/eLXenbzzuFMsDAXZq/rllchGurX3NcM9CT1d3itRXApK2HT erEZex3Q==; Received: from [2409:11:4120:300:16cb:fba0:c571:6d54] (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 1vAHpG-007Lcx-1c; Sun, 19 Oct 2025 01:03:12 +0000 Date: Sun, 19 Oct 2025 10:02:58 +0900 (JST) Message-Id: <20251019.100258.1857152982068276203.ishii@postgresql.org> To: li.evan.chao@gmail.com Cc: michael@paquier.xyz, 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: <24DE0F3D-369B-4421-9178-FCF9A8D4B4E7@gmail.com> References: <20251016.191706.731898842046838424.ishii@postgresql.org> <24DE0F3D-369B-4421-9178-FCF9A8D4B4E7@gmail.com> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:16cb:fba0:c571:6d54 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk >> On Oct 16, 2025, at 18:17, Tatsuo Ishii wrote: >> >> 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. >> >>> > > I think Coverity is complaining about the redundant call to gettuple_eval_partition(). > > In the “else” clause, the function is called, then when “if (myisout)” is satisfied, it will break out the while loop. After that, the function is immediately called again, so “datum” is overwritten. But I haven’t spent time thinking about how to fix. Yes, the function is called again. But I think the cost is cheap in this case. Inside the function window_gettupleslot() is called. It could be costly if it spools tuples. But as tuple is already spooled by the former call of gettuple_eval_partition(), almost no cost is needed. We could avoid the redundant call by putting more code after the former function call to return immediately, or introduce a goto statement or a flag. But I think they will make the code harder to read and do not worth the trouble. Others may think differently though. Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp