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

Keyless Tables with a Unique Key do not enforce uniqueness and create extra values on insert #5433

Closed
timsehn opened this issue Feb 27, 2023 · 4 comments
Labels
bug Something isn't working good repro Easily reproducible bugs sql Issue with SQL

Comments

@timsehn
Copy link
Contributor

timsehn commented Feb 27, 2023

Repro:

PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "create table t (c1 int, c2 int, c3 int, unique key(c1,c2))"
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into t(c1,c2,c3) values (0,0,0) on duplicate key update c3=0"
Query OK, 1 row affected (0.00 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into t(c1,c2,c3) values (0,0,0) on duplicate key update c3=0"
Query OK, 0 rows affected (0.00 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into t(c1,c2,c3) values (0,0,1) on duplicate key update c3=0"
Query OK, 0 rows affected (0.00 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "select * from t"
+----+----+----+
| c1 | c2 | c3 |
+----+----+----+
| 0  | 0  | 1  |
| 2  | 0  | 0  |
| 0  | 0  | 0  |
| 0  | 0  | 0  |
+----+----+----+
@timsehn
Copy link
Contributor Author

timsehn commented Feb 27, 2023

Related: #2289

@timsehn timsehn added bug Something isn't working sql Issue with SQL good repro Easily reproducible bugs labels Feb 27, 2023
@timsehn
Copy link
Contributor Author

timsehn commented Feb 27, 2023

Workaround is to make the unique key a primary key like so:

create table t (c1 int, c2 int, c3 int, primary key(c1,c2))
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "create table p (c1 int, c2 int, c3 int, primary key(c1,c2))"
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into p(c1,c2,c3) values (0,0,0) on duplicate key update c3=0"
Query OK, 1 row affected (0.00 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into p(c1,c2,c3) values (0,0,0) on duplicate key update c3=0"
Query OK, 0 rows affected (0.00 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into p(c1,c2,c3) values (0,0,0) on duplicate key update c3=1"
Query OK, 2 rows affected (0.00 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "insert into p(c1,c2,c3) values (0,0,0) on duplicate key update c3=1"
Query OK, 0 rows affected (0.01 sec)
PS C:\Users\timse\dolthub\dolt\test_unique_key_on_duplicate> dolt sql -q "select * from p"
+----+----+----+
| c1 | c2 | c3 |
+----+----+----+
| 0  | 0  | 1  |
+----+----+----+

@timsehn
Copy link
Contributor Author

timsehn commented Mar 10, 2023

Fixed in the above PR

@jycor
Copy link
Contributor

jycor commented Mar 14, 2023

Issue should be resolved for GMS and dolt new format. Behavior for dolt old format is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good repro Easily reproducible bugs sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

2 participants