Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Incorrect ON UPDATE CASCADE Behaviour with Multiple References #2111

Open
srhickma opened this issue Aug 20, 2019 · 1 comment
Open

[YSQL] Incorrect ON UPDATE CASCADE Behaviour with Multiple References #2111

srhickma opened this issue Aug 20, 2019 · 1 comment
Assignees
Projects
Milestone

Comments

@srhickma
Copy link
Contributor

@srhickma srhickma commented Aug 20, 2019

If a table contains multiple columns referencing the same column of another table, one of which uses ON UPDATE CASCADE, updating the referenced value will cause an error.

For example:

SET default_transaction_isolation = 'SERIALIZABLE';

CREATE TABLE test_table(id int UNIQUE, pk int PRIMARY KEY);

CREATE TABLE ref_table(
    id int,
    ref1 int REFERENCES test_table(id),
    ref2 int REFERENCES test_table(id) ON UPDATE CASCADE
);

INSERT INTO test_table(id, pk) VALUES (1, 1);
INSERT INTO ref_table(ref2) VALUES (1);

UPDATE test_table SET id = 2 WHERE pk = 1;

Produces the following error:

ERROR:  insert or update on table "ref_table" violates foreign key constraint "ref_table_ref2_fkey"
DETAIL:  Key (ref2)=(0) is not present in table "test_table".

In this case it is expected that the value of 1 in the ref_table.ref2 column would be updated to 2, without error.

NOTE: This issue goes away if the order of ref1 and ref2 in the ref_table creation statement are reversed.

@srhickma srhickma added this to To do in YSQL via automation Aug 20, 2019
@ndeodhar ndeodhar added this to the v2.0 milestone Aug 28, 2019
@ndeodhar
Copy link
Contributor

@ndeodhar ndeodhar commented Apr 28, 2020

Note: This works with snapshot isolation but fails in serializable mode.

Loading

@ndeodhar ndeodhar removed this from the v2.0 milestone May 13, 2020
@ndeodhar ndeodhar added this to the v2.2 milestone May 13, 2020
@ndeodhar ndeodhar removed this from the v2.2 milestone Jun 8, 2020
@ndeodhar ndeodhar added this to the v2.2.x milestone Jun 8, 2020
@ndeodhar ndeodhar moved this from To do to Backlog in YSQL Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
YSQL
  
Backlog
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants