Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m7fS3-0000qk-DI for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Jul 2021 14:49:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m7fS0-000151-QV for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Jul 2021 14:49:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m7fS0-00014s-J0 for pgsql-hackers@lists.postgresql.org; Sun, 25 Jul 2021 14:49:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m7fRy-0008KC-2G for pgsql-hackers@lists.postgresql.org; Sun, 25 Jul 2021 14:49:55 +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 16PEnhQZ1337563; Sun, 25 Jul 2021 10:49:43 -0400 From: Tom Lane To: Alvaro Herrera cc: Arne Roland , vignesh C , Zhihong Yu , Pg Hackers Subject: Re: Rename of triggers for partitioned tables In-reply-to: <202107222235.djjcscrqxpwn@alvherre.pgsql> References: <202107222235.djjcscrqxpwn@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Thu, 22 Jul 2021 18:35:25 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1337561.1627224583.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 25 Jul 2021 10:49:43 -0400 Message-ID: <1337562.1627224583@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera writes: > I pushed this patch with some minor corrections (mostly improved the > message wording.) Coverity does not like this bit, and I fully agree: /srv/coverity/git/pgsql-git/postgresql/src/backend/commands/trigger.c: 163= 9 in renametrig_partition() >>> CID 1489387: Incorrect expression (ASSERT_SIDE_EFFECT) >>> Argument "found++" of Assert() has a side effect. The containing = function might work differently in a non-debug build. 1639 Assert(found++ <=3D 0); Perhaps there's no actual bug there, but it's still horrible coding. For one thing, the implication that found could be negative is extremely confusing to readers. A boolean might be better. However, I wonder why you bothered with a flag in the first place. The usual convention if we know there can be only one match is to just not write a loop at all, with a suitable comment, like this pre-existing example elsewhere in trigger.c: /* There should be at most one matching tuple */ if (HeapTupleIsValid(tuple =3D systable_getnext(tgscan))) If you're not quite convinced there can be only one match, then it still shouldn't be an Assert --- a real test-and-elog would be better. regards, tom lane