Skip to content

Allow UNIQUE and PRIMARY KEY to be specified on the same column#305

Merged
fulghum merged 3 commits intomainfrom
fulghum/serial
Jan 23, 2024
Merged

Allow UNIQUE and PRIMARY KEY to be specified on the same column#305
fulghum merged 3 commits intomainfrom
fulghum/serial

Conversation

@fulghum
Copy link

@fulghum fulghum commented Jan 23, 2024

Related to: dolthub/dolt#7395

@fulghum fulghum requested a review from zachmu as a code owner January 23, 2024 19:32
Copy link

@jycor jycor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

It seems like MySQL also allows multiple unique keys to be defined over the same column(s), and just ignores the duplicates
Not sure if it's worth adding in this PR though.

mysql> create table t (id int unique key unique key);
Query OK, 0 rows affected (0.0259 sec)

mysql> show create table t;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                            |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int DEFAULT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.0012 sec)

@fulghum
Copy link
Author

fulghum commented Jan 23, 2024

whoa... good find on the duplicate key options! Very weird that MySQL allows that. I'll go ahead and add support for that while I'm in here since it's only a couple more lines of code and some new test statements. Thank you!

@fulghum fulghum merged commit b7f758f into main Jan 23, 2024
@fulghum fulghum deleted the fulghum/serial branch January 23, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants