in MySQL, If I create a unique key on two columns, say
UNIQUE KEY my_key (column1, column2)
is it necessary to build another key on column1? My goal is to have column1 and column2 to be unique, and I’ll do lots of selects keyed by column1.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it is not necessary because an index on (column1, column2) can be used instead of an index of column1 alone.
You might want to make a new index on just column two though as the index (column1, column2) is not good when searching only for (column2).