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 1rWvd9-007sGa-9q for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Feb 2024 09:51:11 +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 1rWvd6-00CMiX-Jx for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Feb 2024 09:51:08 +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 1rWvd6-00CMiP-4L for pgsql-hackers@lists.postgresql.org; Mon, 05 Feb 2024 09:51:08 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rWvcz-005Aff-Q1 for pgsql-hackers@lists.postgresql.org; Mon, 05 Feb 2024 09:51:06 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 645103200A06; Mon, 5 Feb 2024 04:50:59 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Feb 2024 04:50:59 -0500 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=fm3; t=1707126658; x= 1707213058; bh=7f7zx0/0/LgQch3W1wupQAZSm9FbMkaLX5xdCItTQ2I=; b=b U8LIKy8+LssrGPaBikr8HDP7ZyuhaKq2Foc93zSlQJtGQ+cXKignTCQdmHx9do5/ VVWmY4ue6F+4AJFluYyezv9Cc3+yvWunzJE4W/OieSLw0m4ZnocQZocZrnvqcS5E iBsc/xkTXBJEg9FuX/0qHxiwdEWecv8YMWTU+30Br/wL/w9aAKIMXZd9hBtjPnht vX5DOXfrxRBysrzlt2zrFkzVVG/rlrn0g8zuvJp3DugYF/hoSl10C5Fmxd2Sarop yoWAE6prQULsTrYGukOhwXFy7/mTOHnx8S8cxkze06VfOXOUbRPF9RCzryUPavPZ soH67XMEZWLx03WB4OKNA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvtddgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepudelkeekgfdttdettdekgfduvdeiffelteegjeeihfet heekveeftedtuddvhfeunecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Feb 2024 04:50:58 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1707126656; bh=KJyrmdwaDYcmv0f6vOZiYGkpOV7ww0TKUro1TD2albY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=fpTgwMuHd3Di+/fImySNha733PNeeQbaShjkChAMEjVMeNZ8hZ/426x0FEMT33ikZ pItyL5LLWsV3+jhCfILjwhFn9lWxfW9+fRQiJi7LoatlGSwndjCorSoB9YsoG5loQb YMbzE3jao689dZx8tUzBvtariAebV4qbqWNRkzvdLXo5qxJZBRxCB0RZ+jQc2x+wlL 9zkkbQIr5h+y9bO6mj/O2aosM7XIQ4maWlQbM6cbinCmGzp/TWnwFa88Rhzr1Cwd+y EOCUx4dv1UuI075znrSXRtQEJzf2Mz03uOVgxA8KptPVahuFConjMVfLG3KiTuHx/A LVxFYc4vJlPzw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 8B5D4BA3; Mon, 5 Feb 2024 10:50:56 +0100 (CET) Date: Mon, 5 Feb 2024 10:50:56 +0100 From: Alvaro Herrera To: Michael Paquier Cc: Alexander Lakhin , Dean Rasheed , Peter Eisentraut , Robert Haas , pgsql-hackers@lists.postgresql.org Subject: Re: cataloguing NOT NULL constraints Message-ID: <202402050950.q367e2d6rtjs@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5dq2hkzuszcqyiio" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202402050851.2ktovxwc4irp@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --5dq2hkzuszcqyiio Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2024-Feb-05, Alvaro Herrera wrote: > Hmm, let me have a look, I can probably get this one fixed today before > embarking on a larger fix elsewhere in the same feature. You know what -- this missing CCI has a much more visible impact, which is that the attnotnull marker that a primary key imposes on a partition is propagated early. So this regression test no longer fails: create table cnn2_parted(a int primary key) partition by list (a); create table cnn2_part1(a int); alter table cnn2_parted attach partition cnn2_part1 for values in (1); Here, in the existing code the ALTER TABLE ATTACH fails with the error message that ERROR: primary key column "a" is not marked NOT NULL but with the patch, this no longer occurs. I'm not sure that this behavior change is desirable ... I have vague memories of people complaining that this sort of error was not very welcome ... but on the other hand it seems now pretty clear that if it *is* desirable, then its implementation is no good, because a single added CCI breaks it. I'm leaning towards accepting the behavior change, but I'd like to investigate a little bit more first, but what do others think? -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ --5dq2hkzuszcqyiio Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v1-0001-Fix-failure-to-merge-NOT-NULL-constraints-in-inhe.patch" From 486f6bfa8faa6162257c5f12b52180b5a3d89704 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 5 Feb 2024 10:18:43 +0100 Subject: [PATCH v1] Fix failure to merge NOT NULL constraints in inheritance set_attnotnull() was not careful to CommandCounterIncrement() in cases of multiple recursion. Omission in b0e96f311985. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/045dec3f-9b3d-aa44-0c99-85f6992306c7@gmail.com --- src/backend/commands/tablecmds.c | 4 ++++ src/test/regress/expected/constraints.out | 1 - src/test/regress/expected/inherit.out | 8 ++++++++ src/test/regress/sql/inherit.sql | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 9f51696740..02724d5f04 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7703,6 +7703,10 @@ set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum, bool recurse, List *children; ListCell *lc; + /* Make above catalog changes visible */ + if (retval) + CommandCounterIncrement(); + children = find_inheritance_children(RelationGetRelid(rel), lockmode); foreach(lc, children) { diff --git a/src/test/regress/expected/constraints.out b/src/test/regress/expected/constraints.out index 5b068477bf..bef3d6577c 100644 --- a/src/test/regress/expected/constraints.out +++ b/src/test/regress/expected/constraints.out @@ -1010,7 +1010,6 @@ ERROR: constraint "cnn_parent_pkey" of relation "cnn_parent" does not exist create table cnn2_parted(a int primary key) partition by list (a); create table cnn2_part1(a int); alter table cnn2_parted attach partition cnn2_part1 for values in (1); -ERROR: primary key column "a" is not marked NOT NULL drop table cnn2_parted, cnn2_part1; create table cnn2_parted(a int not null) partition by list (a); create table cnn2_part1(a int primary key); diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 130a924228..fe33bc4c2f 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -2496,6 +2496,14 @@ drop table inh_p1, inh_p2, inh_p3, inh_p4 cascade; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table inh_multiparent drop cascades to table inh_multiparent2 +-- recursively add column with constraint while merging existing column +create table inh_p1 (); +create table inh_p2 (f1 int) inherits (inh_p1); +create table inh_p3 () inherits (inh_p1, inh_p2); +alter table inh_p1 add column f1 int not null; +NOTICE: merging definition of column "f1" for child "inh_p2" +NOTICE: merging definition of column "f1" for child "inh_p3" +drop table inh_p1, inh_p2, inh_p3; -- -- Mixed ownership inheritance tree -- diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index 0ef9a61bc1..41cdde1d90 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -961,6 +961,14 @@ select conrelid::regclass, contype, conname, drop table inh_p1, inh_p2, inh_p3, inh_p4 cascade; +-- recursively add column with constraint while merging existing column +create table inh_p1 (); +create table inh_p2 (f1 int) inherits (inh_p1); +create table inh_p3 () inherits (inh_p1, inh_p2); +alter table inh_p1 add column f1 int not null; + +drop table inh_p1, inh_p2, inh_p3; + -- -- Mixed ownership inheritance tree -- -- 2.39.2 --5dq2hkzuszcqyiio--