Not try locking relations referencing to views (#6430)

Since there can't be such a foreign key already.

This mainly fixes the error that Citus throws
when trying to truncate a distributed view.

Fixes #5990.
pull/6445/head
Onur Tirtir 2022-10-19 11:24:22 +03:00 committed by GitHub
parent 93e162def6
commit 5aec88d084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -1357,7 +1357,11 @@ AcquireDistributedLockOnRelations(List *relationList, LOCKMODE lockMode, uint32
(void *) lockRelationRecord);
}
if ((configs & DIST_LOCK_REFERENCING_TABLES) > 0)
char relkind = get_rel_relkind(relationId);
bool relationCanBeReferenced = (relkind == RELKIND_RELATION ||
relkind == RELKIND_PARTITIONED_TABLE);
if (relationCanBeReferenced &&
(configs & DIST_LOCK_REFERENCING_TABLES) > 0)
{
CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(relationId);
Assert(cacheEntry != NULL);

View File

@ -522,6 +522,18 @@ SELECT truncate_local_data_after_distributing_table('t1');
(1 row)
ALTER TABLE t1 VALIDATE CONSTRAINT t1_a_check;
CREATE TABLE tbl(a INT);
SELECT create_distributed_table('tbl', 'a');
create_distributed_table
---------------------------------------------------------------------
(1 row)
CREATE VIEW vw AS SELECT * FROM tbl;
-- throws an error because vw is not a table
TRUNCATE TABLE tbl, vw CASCADE;
ERROR: "vw" is not a table
SET client_min_messages TO ERROR;
DROP VIEW table_sizes;
DROP TABLE t1;
DROP SCHEMA multi_truncate CASCADE;

View File

@ -304,6 +304,15 @@ ALTER TABLE t1 VALIDATE CONSTRAINT t1_a_check;
SELECT truncate_local_data_after_distributing_table('t1');
ALTER TABLE t1 VALIDATE CONSTRAINT t1_a_check;
CREATE TABLE tbl(a INT);
SELECT create_distributed_table('tbl', 'a');
CREATE VIEW vw AS SELECT * FROM tbl;
-- throws an error because vw is not a table
TRUNCATE TABLE tbl, vw CASCADE;
SET client_min_messages TO ERROR;
DROP VIEW table_sizes;
DROP TABLE t1;
DROP SCHEMA multi_truncate CASCADE;