!6175 修改列为允许NULL值时,添加检测是否为逻辑复制解码列

Merge pull request !6175 from zhubin79/alter-logic
This commit is contained in:
opengauss_bot
2024-09-02 11:58:06 +00:00
committed by Gitee
3 changed files with 29 additions and 0 deletions

View File

@ -13806,6 +13806,7 @@ static ObjectAddress ATExecDropNotNull(Relation rel, const char* colName, LOCKMO
List* indexoidlist = NIL;
ListCell* indexoidscan = NULL;
ObjectAddress address;
Oid replidindex;
/*
* lookup the attribute
@ -13833,6 +13834,9 @@ static ObjectAddress ATExecDropNotNull(Relation rel, const char* colName, LOCKMO
/* Loop over all indexes on the relation */
indexoidlist = RelationGetIndexList(rel);
/* replica identity index */
replidindex = rel->rd_replidindex;
foreach (indexoidscan, indexoidlist) {
Oid indexoid = lfirst_oid(indexoidscan);
HeapTuple indexTuple;
@ -13863,6 +13867,16 @@ static ObjectAddress ATExecDropNotNull(Relation rel, const char* colName, LOCKMO
}
}
/* REPLICA IDENTIFY can't drop not null */
if (replidindex == indexoid) {
for (i = 0; i < indnkeyatts; i++) {
if (indexStruct->indkey.values[i] == attnum)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("column \"%s\" used as replica identity can't drop not null", colName)));
}
}
ReleaseSysCache(indexTuple);
}

View File

@ -80,6 +80,13 @@ SELECT count(*) FROM pg_index WHERE indrelid = 'test_replica_identity'::regclass
1
(1 row)
----
-- Make sure can't alter replica identity index alown NULL
----
CREATE UNIQUE INDEX uni_idx_keya ON test_replica_identity (keya);
ALTER TABLE test_replica_identity REPLICA IDENTITY USING INDEX uni_idx_keya;
ALTER TABLE test_replica_identity MODIFY keya NULL; -- fail
ERROR: column "keya" used as replica identity can't drop not null
----
-- Make sure non index cases work
----
@ -113,6 +120,7 @@ SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
nonkey | text |
Indexes:
"test_replica_identity_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default
"uni_idx_keya" UNIQUE, btree (keya) TABLESPACE pg_default
"test_replica_identity_hash" hash (nonkey) TABLESPACE pg_default
"test_replica_identity_keyab" btree (keya, keyb) TABLESPACE pg_default
Replica Identity: FULL

View File

@ -41,6 +41,13 @@ SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
SELECT count(*) FROM pg_index WHERE indrelid = 'test_replica_identity'::regclass AND indisreplident;
----
-- Make sure can't alter replica identity index alown NULL
----
CREATE UNIQUE INDEX uni_idx_keya ON test_replica_identity (keya);
ALTER TABLE test_replica_identity REPLICA IDENTITY USING INDEX uni_idx_keya;
ALTER TABLE test_replica_identity MODIFY keya NULL; -- fail
----
-- Make sure non index cases work
----