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

sql: add regression logic tests for FKs #37614

Merged
merged 1 commit into from
May 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/fk
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,40 @@ CREATE TABLE no_default_table (
statement ok
DROP TABLE a;

# Test that no column can have more than 1 FK constraint
subtest column_uniqueness

statement ok
CREATE TABLE t (a INT, b INT, c INT, INDEX (a, b), INDEX (b, c))

statement ok
CREATE TABLE t2 (x INT, y INT, z INT, w INT, UNIQUE INDEX (x, y), UNIQUE INDEX (z, w))

statement ok
ALTER TABLE t ADD FOREIGN KEY (a, b) REFERENCES t2 (x, y)

statement error column "b" cannot be used by multiple foreign key constraints
ALTER TABLE t ADD FOREIGN KEY (b, c) REFERENCES t2 (z, w)

statement ok
DROP TABLE t, t2

# Also test the case where one of the FKs is on the primary key
statement ok
CREATE TABLE t (a INT, b INT, c INT, PRIMARY KEY (a, b), INDEX (b, c))

statement ok
CREATE TABLE t2 (x INT, y INT, z INT, w INT, UNIQUE INDEX (x, y), UNIQUE INDEX (z, w))

statement ok
ALTER TABLE t ADD FOREIGN KEY (a, b) REFERENCES t2 (x, y)

statement error column "b" cannot be used by multiple foreign key constraints
ALTER TABLE t ADD FOREIGN KEY (b, c) REFERENCES t2 (z, w)

statement ok
DROP TABLE t, t2

subtest 24664

statement ok
Expand Down