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 1rp8gY-005GPC-U6 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 15:25:59 +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 1rp8gX-00H6p2-6w for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 15:25:57 +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.94.2) (envelope-from ) id 1rp8gV-00H6oo-Ps for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 15:25:56 +0000 Received: from wfout3-smtp.messagingengine.com ([64.147.123.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rp8gR-006bSU-Em for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 15:25:54 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 606641C00074; Tue, 26 Mar 2024 11:25:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 26 Mar 2024 11:25:47 -0400 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1711466746; x= 1711553146; bh=p7zBlLpreeYKMfj8Q+zi2Ew36thri8p/UISP3du2MLY=; b=c RIivHTfE90iU4LbHpJ5Xn1inDVlqpePthdu0L/fE3CIrKa4Dg2bVSEFrSetJOjSI siNisUy1hVqsWjgQDwmyM0rTrfKJUJk3xc2ihErhNJiI0cg5ayoVw568XfSBeBsr WyP668DQFGUY0YVhV+jm8FeXu+TLf66+/Yvd5+aM/aONbqfd+pcVL+lb4QSxR8Mb mI4sh+Ta9b5MW1XozuOqxrk/Nt7IGpPCLH52z9RQ4Dj4tyY7bFxmSQfJy4uAIkvY Nw0GJ+BWYYH8972dHqXoCQQmRU+2w7HR7qchRZ5FBz2QqpOZqgmOpxsbT1i95kS5 djvsMv/+KBrGEI2MLjkXg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddufedgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Mar 2024 11:25:45 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1711466742; bh=AIQMWtCXAJ3VKxlSBvN19KqRSRwIn7KeReGqFXMqMJs=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=fxS02ShxP1Rq2PT6qXu7rKqE2NCsfGx5msa5Hoo1OrCLHJStPnvmHM/6YUprze8Oq FuC71bZlHc2P6x8nT051neCQQTQv8AIWA5jVQOFTt2PEEAj74bbbUK+oXuWggaPJqH F0AFQjCi3w3N72ujGwVMohQO8oqyog5g0u3Dm9Am5TobP6RuXqot9gXU5vrZNSbfEM DWHZ7GmkGzqkJQhq/RxMrSOp+nvxEnDzxQ+eB6wzVxXLNUmDrJxNppAxHtPkokC+6F llwryIK1+1JagxmBBtkpXVs9WZ9Du0Y/UtKANjEOEtxPvFk9BmArQzZ17h/hSievz9 O7yCkm7b3+Axw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id F1C1A153; Tue, 26 Mar 2024 16:25:42 +0100 (CET) Date: Tue, 26 Mar 2024 16:25:42 +0100 From: Alvaro Herrera To: Tender Wang Cc: PostgreSQL Hackers Subject: Re: Can't find not null constraint, but \d+ shows that Message-ID: <202403261525.ciahntfgj25o@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 2024-Mar-26, Tender Wang wrote: > postgres=# CREATE TABLE t1(c0 int, c1 int); > postgres=# ALTER TABLE t1 ADD CONSTRAINT Q PRIMARY KEY(c0, c1); > postgres=# ALTER TABLE t1 DROP c1; > > postgres=# ALTER TABLE t1 ALTER c0 DROP NOT NULL; > ERROR: could not find not-null constraint on column "c0", relation "t1" Ooh, hah, what happens here is that we drop the PK constraint indirectly, so we only go via doDeletion rather than the tablecmds.c code, so we don't check the attnotnull flags that the PK was protecting. > The attached patch is my workaround solution. Look forward your apply. Yeah, this is not a very good approach -- I think you're just guessing that the column is marked NOT NULL because a PK was dropped in the past -- but really what this catalog state is, is corrupted contents because the PK drop was mishandled. At least in theory there are other ways to drop a constraint other than dropping one of its columns (for example, maybe this could happen if you drop a collation that the PK depends on). The right approach is to ensure that the PK drop always does the dance that ATExecDropConstraint does. A good fix probably just moves some code from dropconstraint_internal to RemoveConstraintById. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ really, I see PHP as like a strange amalgamation of C, Perl, Shell inflex: you know that "amalgam" means "mixture with mercury", more or less, right? i.e., "deadly poison"