Self-deadlock when creating foreign key to reference table after adding coordinator
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
The following self-deadlocks as of 11.1:
```sql
SET citus.replicate_reference_tables_on_activate = off;
-- below taken from pg15 tests
CREATE TABLE set_on_default_test_referenced(
col_1 int, col_2 int, col_3 int, col_4 int,
unique (col_1, col_3)
);
SELECT create_reference_table('set_on_default_test_referenced');
CREATE TABLE set_on_default_test_referencing(
col_1 int, col_2 int, col_3 serial, col_4 int,
FOREIGN KEY(col_1, col_3)
REFERENCES set_on_default_test_referenced(col_1, col_3)
ON DELETE SET DEFAULT (col_1)
ON UPDATE SET DEFAULT
);
-- should error since col_3 defaults to a sequence
SELECT create_reference_table('set_on_default_test_referencing');
DROP TABLE set_on_default_test_referencing;
CREATE TABLE set_on_default_test_referencing(
col_1 int, col_2 int, col_3 serial, col_4 int,
FOREIGN KEY(col_1, col_3)
REFERENCES set_on_default_test_referenced(col_1, col_3)
ON DELETE SET DEFAULT (col_1)
);
-- should not error since this doesn't set any sequence based columns to default
SELECT create_reference_table('set_on_default_test_referencing');
INSERT INTO set_on_default_test_referenced (col_1, col_3) VALUES (1, 1);
INSERT INTO set_on_default_test_referencing (col_1, col_3) VALUES (1, 1);
DELETE FROM set_on_default_test_referenced;
SELECT * FROM set_on_default_test_referencing ORDER BY 1,2;
DROP TABLE set_on_default_test_referencing;
SET client_min_messages to ERROR;
SELECT 1 FROM citus_add_node('localhost', :master_port, groupId => 0);
RESET client_min_messages;
-- should error since col_3 defaults to a sequence
CREATE TABLE set_on_default_test_referencing(
col_1 int, col_2 int, col_3 serial, col_4 int,
FOREIGN KEY(col_1, col_3)
REFERENCES set_on_default_test_referenced(col_1, col_3)
ON DELETE SET DEFAULT (col_3)
);
ERROR: canceling the transaction since it was involved in a distributed deadlock
DETAIL: When adding a foreign key from a local table to a reference table, Citus applies a conversion to all the local tables in the foreign key graph
```
Taken from the pg15 test suite with `citus.replicate_reference_tables_on_activate = off` (default as of #6474, and on Cosmos DB)
Contributor guide
Assessment
This issue has not been assessed yet.