Skip to content

Commit

Permalink
Merge #37614
Browse files Browse the repository at this point in the history
37614: sql: add regression logic tests for FKs r=lucy-zhang a=lucy-zhang

A recent change incidentally fixed a bug where a single column in a table could
have multiple FK constraints, if one of the indexes for the FKs was the primary
key. This PR adds regression tests.

Related to #37590.

Release note: None

Co-authored-by: Lucy Zhang <[email protected]>
  • Loading branch information
craig[bot] and lucy-zhang committed May 21, 2019
2 parents b4fabf9 + 81fbb80 commit 23a68e9
Showing 1 changed file with 34 additions and 0 deletions.
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

0 comments on commit 23a68e9

Please sign in to comment.