Home » Php » php – laravel do I need index() on unique() column?

php – laravel do I need index() on unique() column?

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&Answers:

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.

Answer:

No , You do not need to put index() anymore.