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 1vkL20-00Dngw-1v for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Jan 2026 11:45:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkL1z-007ptb-2F for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Jan 2026 11:45:20 +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.96) (envelope-from ) id 1vkL1z-007ptS-11 for pgsql-bugs@lists.postgresql.org; Mon, 26 Jan 2026 11:45:19 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vkL1x-002O19-07 for pgsql-bugs@lists.postgresql.org; Mon, 26 Jan 2026 11:45:18 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-b8863db032dso469594766b.0 for ; Mon, 26 Jan 2026 03:45:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769427915; cv=none; d=google.com; s=arc-20240605; b=FR9GyfYslPLQff9jaLgjKfdPOFICUkOgfxxBy/OXI/MQvsrU8s/Pis3oMHPv/dnbUf 9LBCZLrSXHCWXvFm1uIkjzX+JJbUG0eJjW3jbOiAUIynBegn8e9yo2It5gRK6JNFmVHA 5sCdHjswoQpQnnCZztHp8I1Q4qt5BPWDpHiTQw0bq7ARwmAjnq7sDRbE/ktUvj0stV0/ 4bD4+t74aVdNZkqcus6hDW+Il/hH6K2WJNZwdGABkbHwwNCRSJasnPpdx0iFpCseL90f n1h354JZ/DKck1yDsaN0EQqw3Fc0f/gAxVQS1VJ4YcYBn42EcfQw3/p31D2TjwEk+/Vv C9TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=8S0YxutCfykOqg4A0wTIYTzW0IUaDDS/7wfV3ZT3nIU=; fh=w/VbxOlZVZGe40C+pstH43udc/72nX23RHSJlkQOEhc=; b=Zg7HStUgF85Zee6l2X6cly9YswmKKWRsleWmkAdIBQ4E+tes2PrXPN0iojwQA7fg8R Qs4uNl6eF8sHz2xIN6TGvub0BtRYUie6TNxSqbUYi5wFST8bFTxKaBJX+SLDDtIH7xS1 YXgDfo8mIr/opniA5R9f0yjnJZJE3HI7Vm9/C4F7OB1ssqg3nsEeA9rSI3ig+tg3AfbX +iavoucg86KDW7dUNQMmKHRWMlEbW5R5LA7ClRnryrzMwtmi9NFAXEcGfx7hTQ3HoK20 R0laansUWmX+tvCFfSFspMAXrCmBjPneCixfA5VvKzjlL8FnEcdBfNjcOXCYVK8MC3B5 G5ew==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769427915; x=1770032715; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8S0YxutCfykOqg4A0wTIYTzW0IUaDDS/7wfV3ZT3nIU=; b=abJfPW47shswgoABqWHCvGPV9aiPnyLcB4dC1K3Rxi5c5689vtNhHTF36eNGhFYXId Kmuotp4kRouAyxS+P4hT2aDtdfs0CEgujGPrgWnNTy1Y1GNkR3GRaje1LbXs3BgedDiE 5eoHr2A/NhEBLPcY41Fd+AT/VH3OYjlY0TNHv2rz7Xm6YVsSa73bvqlOMQdY6cCmFoPW LgVDEwrsRYlzVkUo7lZjO318V4ULAP7CnofPf63vLrbEM0k9DJcrWPWsZp/2wi0X6OXf 05QpHuFYKREBNdAgi6nsMdoVM5Qi8fVx++FHEzprTgDaYV+o05pyZ3+u2qNxWAJeVazu Nsow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769427915; x=1770032715; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8S0YxutCfykOqg4A0wTIYTzW0IUaDDS/7wfV3ZT3nIU=; b=dWm47Lkb12GmxO0lKx/rwvYPEI+CQmx0cUEUVpH73F3u/e1+Io5YXnkNWyV1csagNP jT+re0Pa7V+kenNchv1FQEU1y1bctvlfSnJuqmteebREGsfv9k7BGNitblus9Kw0N8+k cKxqwX4DUEtYbEPAwE9RPYE/YysaCmQGYvv6p04TPAZPkq6rh8OGem+9tORuWDHjuvN2 vRcceVkdNU5SxE2I/MjDX4/dIfGrl7OO/DyADLFFhVvc43FluL/UhYd52OeZaQBVjtvZ 4MhVIkZo45BUgcnORwCoWVjJvD2fVIkGo2wpK3Mf/CWcNnfzrciKc+AroTo1IEYnlNG8 EZ9g== X-Forwarded-Encrypted: i=1; AJvYcCVHl3w+o+fyAKyEmLg2iOl6uGraKhcoYjumUvfZLeduo9kqUvloD5CYTd7Fl+XAXLdRLIbt727AsW31@lists.postgresql.org X-Gm-Message-State: AOJu0YwVdyYDQgD6boOVjVyiIndYMpUzNY7aCljb0eawbVqamIBmmv2U pgbQB885K3U9x8RLqrdkjHn6FqJbqkADuJmOWmXjfnk04W93D6wHoiKX93BtVhbhQcUJ+lV4jVH dv/sNceOtibMJbOSiMwHPGwRS86PXjf8W+ALu X-Gm-Gg: AZuq6aI2vSzGXrX6gU4VsYCCLHcXZxiOAK87JGQablVpcb3z4rpA6JIJvaHP5XOWSu2 Gpb4yY8b5KZqMucz+xlZ1RO/hxy/zJfPSJfeozcYcYu94nxLxNbQN7hPT243+e30OzFV/tWHgVc nWDh2R2KLNK2tJGe9NFhF3U/KPnRl0upsTIPIB21bSQYOWt7oLswYl4eVvEaKsmdVK+u8vnRAOt R1KkeGx7OvH2XHS6orNEZLqqnWZkrJ8GR19sI+o+e2v8I5xiROSkHSTExwBXjkE0mMWUXL2shy/ IenEzf//tzgl1ASENPObMDH9WFf4kqPA9XsmYyJAuEgrdqCypTzunSXMDOtwT24vzwLyr4rmdCf cvFxPoQR3AqAcgFDQr2XtrcbV X-Received: by 2002:a17:907:7f94:b0:b88:7568:26dc with SMTP id a640c23a62f3a-b8d45d3e1cdmr357791566b.43.1769427914828; Mon, 26 Jan 2026 03:45:14 -0800 (PST) MIME-Version: 1.0 References: <6ec30f7.19f1.19b15ec1942.Coremail.msdnchina@163.com> <202512130812.375tew7hjksb@alvherre.pgsql> In-Reply-To: <202512130812.375tew7hjksb@alvherre.pgsql> From: Srinath Reddy Sadipiralla Date: Mon, 26 Jan 2026 17:15:03 +0530 X-Gm-Features: AZwV_QgCsMC-_RE_BZgIAnoNDh_YsvBECsE0fDUHxTVBb6RtJ62q2PGAdvZQEo8 Message-ID: Subject: Re: Re: Re: BUG #19351: in pg18.1,when not null exists in the table , and add constraint problem. To: =?UTF-8?Q?=C3=81lvaro_Herrera?= Cc: yanliang lei , pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000051aed40649490a85" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000051aed40649490a85 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi =C3=81lvaro, On Sat, Dec 13, 2025 at 6:14=E2=80=AFPM =C3=81lvaro Herrera wrote: > I hit a snag with multiple inheritance -- if > you apply this patch, you'll see failures in the pg_dump and pg_upgrade > tests. I don't have any ideas to fix this right now, but I'll keep > thinking about it. > i looked into this, the reason for these failures was when the given name for a constraint for a parent table propagates to the child table because of inheritance the name conflicts and throws "mismatching constraint name" error we added, let me show an example, postgres=3D# create table test1(col1 int); CREATE TABLE postgres=3D# create table test2(col1 int not null); CREATE TABLE postgres=3D# create table child12() inherits ( test1,test2); NOTICE: merging multiple inherited definitions of column "col1" CREATE TABLE postgres=3D# \d+ child12 Table "public.child12" Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description --------+---------+-----------+----------+---------+---------+-------------= +--------------+------------- col1 | integer | | not null | | plain | | | Not-null constraints: "test2_col1_not_null" NOT NULL "col1" (inherited) Inherits: test1, test2 Access method: heap postgres=3D# alter table test1 add constraint nn not null col1 not valid; ERROR: mismatching constraint name "nn" DETAIL: A not-null constraint named "test2_col1_not_null" already exists for this column. I think we can fix this by throwing an error only if this constraint was added directly to the table and not through inheritance/propagation from the parent, we can do this using the "is_local" flag, i have checked and all tests passed. /* * Throw an error if the proposed constraint name doesn't match the * existing one. */ + if (is_local && name && strcmp(name, NameStr(conform->conname)) !=3D 0) ereport(ERROR, errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("mismatching constraint name \"%s\"", name), errdetail("A not-null constraint named \"%s\" already exists for this column.", NameStr(conform->conname))); also checking how other constraints handle this case like CHECK and found it just appends to existing constraint postgres=3D# \d+ child34 Table "public.child34" Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description --------+---------+-----------+----------+---------+---------+-------------= +--------------+------------- a | integer | | | | plain | | | Check constraints: "c" CHECK (a > 1) "d" CHECK (a > 1) Inherits: test3, test4 Access method: heap but I don't think it makes sense for NOT NULL, thoughts? --=20 Thanks, Srinath Reddy Sadipiralla EDB: https://www.enterprisedb.com/ --00000000000051aed40649490a85 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0=C3=81lvaro,
On S= at, Dec 13, 2025 at 6:14=E2=80=AFPM =C3=81lvaro Herrera <alvherre@kurilemu.de> wro= te:
I hit a snag wit= h multiple inheritance -- if
you apply this patch, you'll see failures in the pg_dump and pg_upgrade=
tests.=C2=A0 I don't have any ideas to fix this right now, but I'll= keep
thinking about it.
=C2=A0
i looked into this= , the reason for these failures was when the given name
for a constraint= for a parent table propagates to the child table because
of inheritance= the name conflicts and throws "mismatching constraint name"
e= rror we added, let me show an example,

postgres=3D# create table tes= t1(col1 int);
CREATE TABLE
postgres=3D# create table test2(col1 int n= ot null);
CREATE TABLE
postgres=3D# create table child12() inherits (= test1,test2);
NOTICE: =C2=A0merging multiple inherited definitions of c= olumn "col1"
CREATE TABLE
postgres=3D# \d+ child12
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Table = "public.child12"
=C2=A0Column | =C2=A0Type =C2=A0 | Collation = | Nullable | Default | Storage | Compression | Stats target | Description <= br>--------+---------+-----------+----------+---------+---------+----------= ---+--------------+-------------
=C2=A0col1 =C2=A0 | integer | =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 | not null | =C2=A0 =C2=A0 =C2=A0 =C2=A0 | plai= n =C2=A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0|
Not-null constraints:
=C2=A0 =C2=A0 &q= uot;test2_col1_not_null" NOT NULL "col1" (inherited)
Inhe= rits: test1,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test2
Access method: = heap

postgres=3D# alter table test1 add constraint nn not null col1 = not valid;
ERROR: =C2=A0mismatching constraint name "nn"
DE= TAIL: =C2=A0A not-null constraint named "test2_col1_not_null" alr= eady exists for this column.

I think we can fix this by throwing an = error only if this constraint was added
directly to the table and not th= rough inheritance/propagation from the parent,
we can do this using the = "is_local" flag, i have checked and all tests passed.

=C2= =A0 /*
* Throw an error if the proposed constraint name doesn't m= atch the
* existing one.
*/
+ if (is_local && name &= amp;&
strcmp(name, NameStr(conform->conname)) !=3D 0)
er= eport(ERROR,
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
= errmsg("mismatching constraint name \"%s\"", name)= ,
errdetail("A not-null constraint named \"%s\" alre= ady exists for this column.",
=C2=A0NameStr(conform->con= name)));

also checking how other constraints handle this case like C= HECK
and found it just appends to existing constraint

postgres=3D= # \d+ child34
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0Table "public.child34"
=C2=A0Column | =C2=A0T= ype =C2=A0 | Collation | Nullable | Default | Storage | Compression | Stats= target | Description
--------+---------+-----------+----------+-------= --+---------+-------------+--------------+-------------
=C2=A0a =C2=A0 = =C2=A0 =C2=A0| integer | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 =C2=A0 | plain =C2=A0 | =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0|
Check constraints:
=C2=A0 =C2=A0 "c" CHECK (a = > 1)
=C2=A0 =C2=A0 "d" CHECK (a > 1)
Inherits: test3,=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test4
Access method: heap

= but I don't think it makes sense for NOT NULL, thoughts?

<= /div>

--
Thanks,
Srinath Reddy Sadipiralla
EDB:=C2=A0https://www.enterprisedb.com/
--00000000000051aed40649490a85--