When I put unique() on column in laravel migration, I don't need to put index() anymore right? Unique already creates an index for fast search?
Asked
Active
Viewed 4,473 times
2 Answers
25
Yes unique()
alone is enough. It will create a UNIQUE
index on the table which basically is the same as a "normal" INDEX
but also enforces the constraint that there can be no two rows with the same value.
So in terms of performance UNIQUE
should be at least the same if not even faster. No need to add an additional index.
This question has a nice answer comparing the different indexes of MySQL.

Community
- 1
- 1

lukasgeiter
- 147,337
- 26
- 332
- 270
-1
No , You do not need to put index() anymore.

MD. Atiqur Rahman
- 2,063
- 4
- 17
- 30
-
1No it isn't but when you say it like that (even though you are right) it sounds more like an opinion than a well-founded answer. – lukasgeiter Jan 15 '15 at 16:33
-
1Okay. Thank you for your nice comment , I have up-votted you . Cheers ! – MD. Atiqur Rahman Jan 15 '15 at 16:37
-
3No worries... and thanks. Also keep in mind, that these answers aren't just for the OP but are supposed to help other people having the same or a similar struggle in the future :) – lukasgeiter Jan 15 '15 at 16:39