Skip to content

Dolt allows me to create an unique index that violates uniqueness #4420

@timsehn

Description

@timsehn

Repro:

$ dolt init --new-format
Successfully initialized dolt data repository.
$ dolt sql -q "create table t (c1 int, c2 int, c3 int, c4 int)"
$ dolt sql -q "create index m on t (c3,c4)"
$ dolt sql -q "show create table t"
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                              |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `c1` int,
  `c2` int,
  `c3` int,
  `c4` int,
  KEY `m` (`c3`,`c4`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+

$ dolt sql -q "insert into t values (0,0,0,0)";
Query OK, 1 row affected (0.00 sec)
$ dolt sql -q "insert into t values (0,0,0,0)" 
Query OK, 1 row affected (0.00 sec)
$ dolt sql -q "select * from t"
+----+----+----+----+
| c1 | c2 | c3 | c4 |
+----+----+----+----+
| 0  | 0  | 0  | 0  |
| 0  | 0  | 0  | 0  |
+----+----+----+----+

$ dolt sql -q "drop index m on t"
$ dolt sql -q "show create table t"            
+-------+------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                       |
+-------+------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `c1` int,
  `c2` int,
  `c3` int,
  `c4` int
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+-------+------------------------------------------------------------------------------------------------------------------------------------+

$ dolt sql -q "create unique index m on t (c3,c4)"
$ dolt sql -q "insert into t values (0,0,0,0)"   
error executing query on line 1: duplicate unique key given: [0,0]
$ dolt sql -q "select * from t"                  
+----+----+----+----+
| c1 | c2 | c3 | c4 |
+----+----+----+----+
| 0  | 0  | 0  | 0  |
| 0  | 0  | 0  | 0  |
+----+----+----+----+

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsqlIssue with SQL

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions