Laravel Do I need an index () in a unique () column?

When I put unique () on a column in a laravel migration, I no longer need to specify index ()? Is unique already creating an index for quick searches?

+5
source share
2 answers

Yes unique() enough. It will create a UNIQUE index on the table, which is basically the same as the “regular” INDEX , but also sets a limit to the fact that there cannot be two rows with the same value.

Thus, in terms of performance, UNIQUE should be at least the same, if not faster. No need to add an additional index.

This question has a good answer comparing different MySQL indexes.

+6
source

No, you no longer need to set index ().

0
source

Source: https://habr.com/ru/post/1211174/


All Articles