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 1wUaoh-001HfN-1c for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 01:54:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUaof-00Gw93-08 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 01:54:45 +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 1wUaoe-00Gw7M-2G for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 01:54:44 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUaob-00000000q2X-3Ft6 for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 01:54:43 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2c132ac5ec2so10427155ad.1 for ; Tue, 02 Jun 2026 18:54:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780451681; x=1781056481; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lQ7LrPx8L+SEAisJ7vhYssgjKzamaaFDjviEI3SRoiw=; b=k2yVgss0eZfAFtYbZ7JL6Zu5cUKr9lXpvpZeL9UqyU9i4KdPn7FTu8CSsDrwS+fd8p MoJ7rZSs1RPlnkEjIOf0zgavJiH7AIFwNIy1+i5+Gnk5YY5PjAG9xnfTq8J35UBt56xp zDr6SiLwcM+u9cobLOz8g2pScQtVn40oTOTtGEXmXS+P6JISgz5NEg4dsFAEoXERwgaZ 1+M63OfY+s+p4El7UIp654/eivAwFC7FLD6iLcmekTAMohPCmhGe09nDOl4y+IY7/wf6 ZAjxaR0PUffBQJqxcv65lFvqDEtkoNDnAEUlNCTKx+DnvIAVlFS6waOaCYnE7atFEDq9 3wYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780451681; x=1781056481; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lQ7LrPx8L+SEAisJ7vhYssgjKzamaaFDjviEI3SRoiw=; b=ExqSFlWEqi7bSZRrvAGD9yYO9YmNTS0pGQlV8CTuehrmicYwLFxZ5HXM+ZXTJev3w8 IPJJxV7ECWuUYppXvQ/bwZjgLv8J1WIDbpt9yP1096tM/y/uRD+fruNOf6yqOEwZ5N2P h+bgUadq+F9qDv7n7jpKe3gqrez2Td1YLXIAGCgFs8Z3qHEGNkKht1+GSnr2LOSMM+cG wbcSgJiftg4ct2sPQaoM8fzKwdYU8hQob3osShfB04Warfug8ZhtcVvmpFmxL6X0f9nk LXbiVF+C3Ls2EK5Ao/i4fUZFZoLQsTBaGICVphYwk+pBwaHEU3nVwWpg0sccyxpGCE4j tQag== X-Gm-Message-State: AOJu0YxTX5J8IPSKYOrWXXEzFJUOBjIzPtPPAP8TqWYjxSWdEcwEuw76 ry5iy1fkR0N9wFBHI7d6tPktsWkJTGRGDRK3zyeGgHqIVdseLuEUqduc X-Gm-Gg: Acq92OGcHzBGMNgYFyc4XvY0IxZqf3IDr2A8/pOYQQj6SahiihdfTq0Ly2U/aOjMAOX /lkNs5WFtGjYPmVbMgp8aDYK1Fj7t1IejiQtRukg5TplhNLB9ez8lbMDDhZgUZrbc8WLnJ0WPfk SCZ4cbpr+YrfcU2gj0kPrP/cLQVen5Ai152rSvvgkZev0lApN+ZRkJstn0P/brosR3krL+U3gTN oVo4dUAW3U52Htki+Ujkur2GzhUT00UqXr7yXqhkdGa6qm4E2465VVw6FytVf62JGuGPP8c6f/e e4ZgsJSj4NIjWdHKxrEOqOdEeIh8c0oOeJNJNueKzutQgsdthHlgk1Yasbcn+gUq1keaj3ffMun F3kx6AYYXDRpvNXvqorSft/pBkh2swei9Uaq40aJeT0jQN0ZCwbwt1R8wKl3Cy6M6T0R6D/ym4f c5eLx64VtnbeMuCal9HoKwaPNMkfQBLeNWl/2xnfhpfA== X-Received: by 2002:a17:903:240b:b0:2b2:4029:d781 with SMTP id d9443c01a7336-2c163fa870bmr11010065ad.20.1780451680697; Tue, 02 Jun 2026 18:54:40 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f9ed6csm5964835ad.31.2026.06.02.18.54.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2026 18:54:40 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Fix bug of CHECK constraint enforceability recursion From: Chao Li In-Reply-To: Date: Wed, 3 Jun 2026 09:54:01 +0800 Cc: pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <185FC597-BF26-4075-9D59-E5905ED74E0F@gmail.com> References: <33E9C4C2-B6A8-4FCC-BEEA-461EA5FB98C8@gmail.com> <7F0EA98A-6DBC-436A-8FF4-4A511A05ABE6@gmail.com> <7B7172F4-DB02-4259-997B-6AEF5ADF7FCE@gmail.com> To: Zsolt Parragi X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 3, 2026, at 04:56, Zsolt Parragi = wrote: >=20 > Hello >=20 > + * During recursion, another parent outside this ALTER may still = enforce > + * the same constraint. In that case, keep the child constraint = ENFORCED > + * so that its merged enforceability still reflects the remaining = enforced > + * parent. > + */ > + if (!cmdcon->is_enforced) > + { >=20 > This means once is_enforced is set to true, it will never be > rechecked. See the following example which showcases an issue with > this: >=20 > create table g(a int constraint k check(a > 0) enforced); > create table o(a int constraint k check(a > 0) enforced); > create table s1() inherits(g); > create table s2() inherits(g, o); > create table s3() inherits(g); > alter table g alter constraint k not enforced; > select conrelid::regclass as tbl, conenforced > from pg_constraint > where conname =3D 'k' and contype =3D 'c' > order by conrelid::regclass::text collate "C"; > insert into s1 values (-1); > insert into s3 values (-1); -- bug: ERRORs out, but shouldn't >=20 Hi Zsolt, Thanks for your view. I just tried your test with v6, but didn't see the bug you mentioned: ``` evantest=3D# create table g(a int constraint k check(a > 0) enforced); CREATE TABLE evantest=3D# create table o(a int constraint k check(a > 0) enforced); CREATE TABLE evantest=3D# create table s1() inherits(g); CREATE TABLE evantest=3D# create table s2() inherits(g, o); NOTICE: merging multiple inherited definitions of column "a" CREATE TABLE evantest=3D# create table s3() inherits(g); CREATE TABLE evantest=3D# alter table g alter constraint k not enforced; ALTER TABLE evantest=3D# select conrelid::regclass as tbl, conenforced evantest-# from pg_constraint evantest-# where conname =3D 'k'; tbl | conenforced -----+------------- o | t s2 | t g | f s1 | f s3 | f (5 rows) evantest=3D# insert into s1 values (-1); INSERT 0 1 evantest=3D# insert into s3 values (-1); INSERT 0 1 ``` Here, both s1 and s3 are the direct child of g, thus when g is set to = =E2=80=9Cnot enforced=E2=80=9D, s1 and s3 is set to =E2=80=9Cnot = enforced" as well. While s2 is a child of both g and o, as o is still = enforced, s2 remains enforced. The test result is right as expected. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/