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 1vyro4-000UiW-2G for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2026 13:35:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vyro3-008ejb-0K for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2026 13:34:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vyro2-008ejT-1m for pgsql-hackers@lists.postgresql.org; Sat, 07 Mar 2026 13:34:59 +0000 Received: from fout-b1-smtp.messagingengine.com ([202.12.124.144]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vyrnz-00000001Lkf-3ezB for pgsql-hackers@postgresql.org; Sat, 07 Mar 2026 13:34:58 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id A17E01D001A6; Sat, 7 Mar 2026 08:32:22 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Sat, 07 Mar 2026 08:32:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm2; t=1772890342; x= 1772976742; bh=6dn7rJKUR8fMC+WvgZuIQmZNBGwg/J7f/pnighgI/rE=; b=D q7VJ2omLstOhYwZdxZkFLeZLS+V0dNH1lpBHaNKSDC5IOWXnDnOVZAheOE8o88SD uUPgIM/+s8XrYlDoRn8lVb4YYW8bUkwWSNV0QAMYSL1z3liyvaHH2qxG0teP8oqa s0zd763tfT2Rl13+0kfvf0j4aEcWpWfyAiZ8jVIo0uMYziNM+kXWwV8Xb++iOfKH g7N9qZh5t9wDb/MfEmdTbRhIFsDLa59IuwIDuIEdhd0MYX+PYFkBybKDnHSKDPxV 0p8VEv5uFm5cXmNRrFVWxXODkDRq3EQ+KRLBUq9b3mcHkI3x0ZLuWRDnW8d/+Vki JfGPhv6XQKhlDrMDTsQXQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1772890342; x=1772976742; bh=6 dn7rJKUR8fMC+WvgZuIQmZNBGwg/J7f/pnighgI/rE=; b=Jvkd//P4hWXlQzTR+ lWNqxa8FEanW6t6BxBSBfov5DenobhFGG6rCzEgZD5GipuCRouZRU51+QXeWgImj ibluQH2x66rCTt9kBjx9U+pN6IdXzckLzqCIOVt5v0uH00gYAdG5HC81VctYOMjP r3kpcNOxnlHkPoATXzHMjx9lIkea5O/vCv3LdlpbcgWULco38NVhOokWPKVwW90y CfMIP0Ho2BaClwVFD7ZqHfy1BwIZzSxLiBfslmpcJ7rsfrNUqCFCWKgRf4C5csYG s6mp4/kZQpPdH7BldDCdGywbVCPaRxgKftvLlejzJLtONdU17326EHlb6Qw/2apL ZwHUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvjedvfeeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeekgfekhffggfehvdfgtddvvdeiheevudeitdeiheekudehgfetteev kedtfeekgeenucffohhmrghinhepphhoshhtghhrrdgvshdpvghnthgvrhhprhhishgvug gsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mheprghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopeefpd hmohguvgepshhmthhpohhuthdprhgtphhtthhopehgvghorhhgvgdrvhdrthgrrhgrshho vhesghhmrghilhdrtghomhdprhgtphhtthhopehrrghnihgvrhdrvhhfsehgmhgrihhlrd gtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhl rdhorhhg X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Mar 2026 08:32:21 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1772890338; bh=ilayJ6B5uJsiox3aZHMVUnYXalPOajAQHwtLVvSIEUE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=PVujrofSOrvE+gUhJKKs2oRNXqPthonSljfxwCJ2QEISeyoyz10F9lsEiNzJgrXu9 svoWWeVVOcdXU/Ojz8Uf82jnbhl/DJFeH4xpariyKh3sLurHvqxJIzy9+p7DSVIGtZ 4QGcen5TpEqDeQUJKaixqF0c05QhK2sUXHkTTYmBO6N3LOFZz0rJtO2Vs+ohbF8M2u a+8Q5khFCdeN/f3GRlkFo7/TQ7IiYaMpAzPvaroV7eScsMzBwqBP5uLlOjZhPFLYuz nHrNo61q2OU/KrROMYb60HFrQt3y5pTtO8mO5/QsjGxWqx4rMm15Gkes+dz3gJ5sG/ wsLHVErYE+KAQ== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id 78A3974; Sat, 07 Mar 2026 14:32:18 +0100 (CET) Date: Sat, 7 Mar 2026 14:32:18 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: George Tarasov Cc: pgsql-hackers@postgresql.org, Ranier Vilela Subject: Re: [BUG?] missing array index may result in a wrong constraint name (pg_dump, bin-upgrade, >=18) Message-ID: <202603071329.rtpgais3c7nq@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-Mar-07, George Tarasov wrote: > I performed static code analysis and got an error: ALWAYS FALSE SUBEXPR! > Let's look at a little snippet (pg_dump.c:10203). > >     /* >      * In binary upgrade of inheritance child tables, must have a >      * constraint name that we can UPDATE later; same if there's a >      * comment on the constraint. >      */ >     if ((dopt->binary_upgrade && >          !tbinfo->ispartition && >          !tbinfo->notnull_islocal) || >          ^^^^^^^^^^^^^^^^^^^^^^^^            ALWAYS FALSE SUBEXPR! >         !PQgetisnull(res, r, i_notnull_comment)) >     { > > It seems like index "[j]" is missing for this subexpression to make any > sense. Yeah, that's incorrect. It had been reported before: https://postgr.es/m/CAEudQAo7ah=4TDheuEjtb0dsv6bHoK7uBNqv53Tsub2h-xBSJw@mail.gmail.com However, it's pretty innocuous as far as I can understand. I pushed the suggested fix now anyway, with this commit message: commit eb2c867b0aab5fd6bbea1d8dbfea23d9d6fa1a94 Author: Álvaro Herrera [Álvaro Herrera ] AuthorDate: Sat Mar 7 14:28:16 2026 +0100 CommitDate: Sat Mar 7 14:28:16 2026 +0100 Fix invalid boolean if-test We were testing the truth value of the array of booleans (which is always true) instead of the boolean element specific to the affected table column. This causes a binary-upgrade dump fail to omit the name of a constraint; that is, the correct constraint name is always printed, even when it's not needed. The affected case is a binary-upgrade dump of a not-null constraint in an inherited column, which must in addition have no comment. Another point is that in order for this to make a difference, the constraint must have the default name in the child table. That is, the constraint must have been created _in the parent table_ with the name that it would have in the child table, like so: CREATE TABLE parent (a int CONSTRAINT child_a_not_null NOT NULL); CREATE TABLE child () INHERITS (parent); Otherwise, the correct name must be printed by binary-upgrade pg_dump anyway, since it wouldn't match the name produced at the parent. Moreover, when it does hit, the pre-18-compatibility code (which has to work with a constraint that has no name) gets involved and uses the UPDATE on pg_constraint using the conkey instead of column name ... and so everything ends up working correctly AFAICS. I think it might cause a problem if the table and column names are overly long, but I didn't want to spend time investigating further. Still, it's wrong code, and static analyzers have twice complained about it, so fix it by adding the array index accessor that was obviously meant. Reported-by: Ranier Vilela Reported-by: George Tarasov Backpatch-through: 18 Discussion: https://postgr.es/m/CAEudQAo7ah=4TDheuEjtb0dsv6bHoK7uBNqv53Tsub2h-xBSJw@mail.gmail.com Discussion: https://postgr.es/m/f3029f25-acc9-4cb9-a74f-fe93bcfb3a27@gmail.com Thanks for reporting it! -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/