Home  >  Article  >  Backend Development  >  mysql 联合索引命中规则

mysql 联合索引命中规则

WBOY
WBOYOriginal
2016-06-06 20:24:592304browse

1.5个字段建了联合索引的,他们的规则是怎么样的。什么情况会用上什么情况用不上
2.如果两个字段是单独索引,where a=x order b大家觉得用到哪个索引了, 还where a=x order by C 这样用到索引了,C字段是没有索引的。

现在不太方便测试。先谢过大神

回复内容:

1.5个字段建了联合索引的,他们的规则是怎么样的。什么情况会用上什么情况用不上
2.如果两个字段是单独索引,where a=x order b大家觉得用到哪个索引了, 还where a=x order by C 这样用到索引了,C字段是没有索引的。

现在不太方便测试。先谢过大神

命名规则:表名_字段名
1、需要加索引的字段,要在where条件中
2、数据量少的字段不需要加索引
3、如果where条件中是OR关系,加索引不起作用
4、符合最左原则

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn