Skip to content

Question about unique key #33

Answered by carlsverre
anym0re asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the great question @anym0re!

The reason we can't have a unique index on the "email" column is that SingleStoreDB is a sharded database. This means that for us to know whether or not a particular email is unique would require storing all of the rows with the same email value on the same partition. But, in this case, we also want a primary key on the ID column - which has a similar issue. So, unfortunately there is no way to have a unique index on two different columns in the same table.

However! As you point out, you could put a unique index on (id, email) as that index starts with the primary key (which also happens to be the shard key for the table). While this does technical …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by carlsverre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #31 on October 06, 2022 18:42.