简体   繁体   中英

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

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?

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.

不,你不需要再放索引()了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM