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: support INSERT with partial UNIQUE WITHOUT INDEX constraints #60535

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions pkg/ccl/logictestccl/testdata/logic_test/regional_by_row
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ vectorized: true
│ │
│ └── • lookup join (semi)
│ │ table: regional_by_row_table@primary
│ │ equality: (lookup_join_const_col_@24, column1) = (crdb_region,pk)
│ │ equality: (lookup_join_const_col_@22, column1) = (crdb_region,pk)
│ │ equality cols are key
│ │ pred: column15 != crdb_region
│ │
Expand All @@ -315,7 +315,7 @@ vectorized: true
│ │
│ └── • lookup join (semi)
│ │ table: regional_by_row_table@regional_by_row_table_b_key
│ │ equality: (lookup_join_const_col_@36, column4) = (crdb_region,b)
│ │ equality: (lookup_join_const_col_@37, column4) = (crdb_region,b)
│ │ equality cols are key
│ │ pred: (column1 != pk) OR (column15 != crdb_region)
│ │
Expand All @@ -333,7 +333,7 @@ vectorized: true
└── • lookup join (semi)
│ table: regional_by_row_table@new_idx
│ equality: (lookup_join_const_col_@49, column3, column4) = (crdb_region,a,b)
│ equality: (lookup_join_const_col_@52, column3, column4) = (crdb_region,a,b)
│ equality cols are key
│ pred: (column1 != pk) OR (column15 != crdb_region)
Expand Down Expand Up @@ -383,7 +383,7 @@ vectorized: true
│ │
│ └── • lookup join (semi)
│ │ table: regional_by_row_table@primary
│ │ equality: (lookup_join_const_col_@35, upsert_pk) = (crdb_region,pk)
│ │ equality: (lookup_join_const_col_@33, upsert_pk) = (crdb_region,pk)
│ │ equality cols are key
│ │ pred: column1 != crdb_region
│ │
Expand All @@ -401,7 +401,7 @@ vectorized: true
│ │
│ └── • lookup join (semi)
│ │ table: regional_by_row_table@regional_by_row_table_b_key
│ │ equality: (lookup_join_const_col_@47, column5) = (crdb_region,b)
│ │ equality: (lookup_join_const_col_@48, column5) = (crdb_region,b)
│ │ equality cols are key
│ │ pred: (upsert_pk != pk) OR (column1 != crdb_region)
│ │
Expand All @@ -419,7 +419,7 @@ vectorized: true
└── • lookup join (semi)
│ table: regional_by_row_table@new_idx
│ equality: (lookup_join_const_col_@60, column4, column5) = (crdb_region,a,b)
│ equality: (lookup_join_const_col_@63, column4, column5) = (crdb_region,a,b)
│ equality cols are key
│ pred: (upsert_pk != pk) OR (column1 != crdb_region)
Expand Down Expand Up @@ -465,7 +465,7 @@ vectorized: true
│ │
│ └── • lookup join (semi)
│ │ table: regional_by_row_table@primary
│ │ equality: (lookup_join_const_col_@35, upsert_pk) = (crdb_region,pk)
│ │ equality: (lookup_join_const_col_@33, upsert_pk) = (crdb_region,pk)
│ │ equality cols are key
│ │ pred: column1 != crdb_region
│ │
Expand All @@ -483,7 +483,7 @@ vectorized: true
│ │
│ └── • lookup join (semi)
│ │ table: regional_by_row_table@regional_by_row_table_b_key
│ │ equality: (lookup_join_const_col_@47, column5) = (crdb_region,b)
│ │ equality: (lookup_join_const_col_@48, column5) = (crdb_region,b)
│ │ equality cols are key
│ │ pred: (upsert_pk != pk) OR (column1 != crdb_region)
│ │
Expand All @@ -501,7 +501,7 @@ vectorized: true
└── • lookup join (semi)
│ table: regional_by_row_table@new_idx
│ equality: (lookup_join_const_col_@60, column4, column5) = (crdb_region,a,b)
│ equality: (lookup_join_const_col_@63, column4, column5) = (crdb_region,a,b)
│ equality cols are key
│ pred: (upsert_pk != pk) OR (column1 != crdb_region)
Expand Down
43 changes: 43 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/unique
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,49 @@ us-west foo 1 1
eu-west bar 2 2


# Insert some non-null data into a table with a partial unique without index
# constraint.
statement ok
INSERT INTO uniq_partial VALUES (1, 1), (1, -1), (2, 2)

# Partial unique constraint violation.
statement error pgcode 23505 pq: duplicate key value violates unique constraint "unique_a"\nDETAIL: Key \(a\)=\(1\) already exists\.
INSERT INTO uniq_partial VALUES (1, 3)

# No partial unique constraint violation because b <= 0.
statement ok
INSERT INTO uniq_partial VALUES (1, -3)

# Attempt to insert conflicting keys twice in the same statement.
statement error pgcode 23505 pq: duplicate key value violates unique constraint "unique_a"\nDETAIL: Key \(a\)=\(3\) already exists\.
INSERT INTO uniq_partial VALUES (3, 3), (3, 4)

# Attempt to insert one conflicting key and one non-conflicting key in the same
# statement.
statement error pgcode 23505 pq: duplicate key value violates unique constraint "unique_a"\nDETAIL: Key \(a\)=\(1\) already exists\.
INSERT INTO uniq_partial VALUES (1, 3), (3, 3)

# Insert some rows with NULL keys.
statement ok
INSERT INTO uniq_partial VALUES (NULL, 5), (5, 5), (NULL, 5)

# Insert with non-constant input.
statement error pgcode 23505 pq: duplicate key value violates unique constraint "unique_a"\nDETAIL: Key \(a\)=\(1\) already exists\.
INSERT INTO uniq_partial SELECT w, x FROM other

query II colnames,rowsort
SELECT * FROM uniq_partial
----
a b
1 1
1 -1
1 -3
2 2
5 5
NULL 5
NULL 5


# -- Tests with UPDATE --
subtest Update

Expand Down
Loading