简体   繁体   English

laravel我在unique()列上需要index()吗?

[英]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? 当我在laravel迁移中将unique()放在列上时,我不再需要放入index()了吗? Unique already creates an index for fast search? Unique已创建快速搜索索引?

Yes unique() alone is enough. unique()就足够了。 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. 它将在表上创建一个UNIQUE索引,它基本上与“普通” INDEX相同,但也强制执行约束,即不能有两个具有相同值的行。

So in terms of performance UNIQUE should be at least the same if not even faster. 所以在性能方面,如果不是更快, UNIQUE至少应该是相同的。 No need to add an additional index. 无需添加其他索引。

This question has a nice answer comparing the different indexes of MySQL. 这个问题比较MySQL的不同索引有一个很好的答案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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