Mysql:如何在表上建立索引
我想知道当我必须放置多个索引时,我应该将它们放在同一个“索引”下还是不同的索引下?
INDEX `field1` (`field1`)
INDEX `field2` (`field2`)
或者
INDEX `field1` (`field1`,`field2`)
有什么区别吗?
谢谢
I would like to know when i have to put multiple index should i make them under the same "index" or on a different index?
INDEX `field1` (`field1`)
INDEX `field2` (`field2`)
or
INDEX `field1` (`field1`,`field2`)
Are there any differneces?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个区别。由两列(或更多列)组成的索引是根据您指定的列的顺序构建的。仅当您搜索前 X 个字段时才可以使用它。假设您有一个索引,
它将在运行如下查询时使用:
在运行如下查询时不会使用它:
在第一种类型的查询中,拥有 3 字段索引将比拥有单独的索引更快,因此决定如何构建索引取决于您需要的查询类型。
There is a difference. An index made out of two columns (or more) is built according to the order of columns you specified. It can be used only when you are searching for the first X fields. Let's say you have an index
It will be used when running queries like:
It will NOT be used when running queries like:
On queries of the first type, having the 3 field index will be quicker than having separate indexes, so deciding how to build the indexes depends on which types of queries you are going to need.
是的,有区别。看:当您要运行查询时,
您将为 a 和 b 列创建一个索引:
两个索引会更慢。
抱歉我的英语不好。
Yes, there is a difference. Look: when you gonna run query like
you will create one index for columns a and b:
Two indexes will be slower.
Sorry for my bad english.