From ff5343275c480647c1947b12cf3e3b44513c1ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=85=E7=A8=8B?= <517719039@qq.com> Date: Tue, 22 Apr 2025 15:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D3.0.3=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E8=87=B36.0.1=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/cache/relcache.cpp | 12 ++++++------ src/test/regress/expected/table_constraint.out | 11 +++++++++++ src/test/regress/sql/table_constraint.sql | 9 ++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index 1cb5201fa1..cff3e25ce8 100755 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -6123,12 +6123,12 @@ static void CheckConstraintFetch(Relation relation) check[found].ccnoinherit = conform->connoinherit; check[found].cctype = conform->contype; val = heap_getattr(htup, Anum_pg_constraint_condisable, RelationGetDescr(conrel), &isnull); - if (isnull) - ereport(ERROR, - (errcode(ERRCODE_UNEXPECTED_NULL_VALUE), - errmsg("null disable for rel %s", RelationGetRelationName(relation)))); - bool condisable = DatumGetBool(val); - check[found].ccdisable = condisable; + if (isnull) { + check[found].ccdisable = false; + } else { + bool condisable = DatumGetBool(val); + check[found].ccdisable = condisable; + } check[found].ccname = MemoryContextStrdup(LocalMyDBCacheMemCxt(), NameStr(conform->conname)); /* Grab and test conbin is actually set */ diff --git a/src/test/regress/expected/table_constraint.out b/src/test/regress/expected/table_constraint.out index c89ca71d59..3683a0bb6a 100644 --- a/src/test/regress/expected/table_constraint.out +++ b/src/test/regress/expected/table_constraint.out @@ -799,3 +799,14 @@ insert into test1 values(14, 'ddd'); update test1 set id = 21 where name = 'aaa'; delete from test1 where id = 12; drop table test1; +create table condisable_t1 (c1 int unique); +NOTICE: CREATE TABLE / UNIQUE will create implicit index "condisable_t1_c1_key" for table "condisable_t1" +ALTER TABLE condisable_t1 ADD CONSTRAINT c1_check CHECK (c1 > 0); +-- simulate upgrade situation from low versions +update pg_constraint set condisable=NULL where conrelid = (select oid from pg_class where relname = 'condisable_t1'); +select * from condisable_t1; + c1 +---- +(0 rows) + +drop table condisable_t1 cascade; diff --git a/src/test/regress/sql/table_constraint.sql b/src/test/regress/sql/table_constraint.sql index 3a2619b2bb..6606336426 100644 --- a/src/test/regress/sql/table_constraint.sql +++ b/src/test/regress/sql/table_constraint.sql @@ -491,4 +491,11 @@ select conname,contype,condeferrable,condeferred,convalidated,condisable from pg insert into test1 values(14, 'ddd'); update test1 set id = 21 where name = 'aaa'; delete from test1 where id = 12; -drop table test1; \ No newline at end of file +drop table test1; + +create table condisable_t1 (c1 int unique); +ALTER TABLE condisable_t1 ADD CONSTRAINT c1_check CHECK (c1 > 0); +-- simulate upgrade situation from low versions +update pg_constraint set condisable=NULL where conrelid = (select oid from pg_class where relname = 'condisable_t1'); +select * from condisable_t1; +drop table condisable_t1 cascade; -- Gitee