msyql同时建立索引和分开建立索引的区别

来源:互联网 发布:用sql创建表 编辑:程序博客网 时间:2024/06/06 21:06
如果我们创建了(area, age,salary)的复合索引,那么其实相当于创建了:(area,age,salary),(area,age)、(area)三个索引,这被称为最佳左前缀特性。因此我们在创建复合索引时应该将最常用作限制条件的列放在最左边,依次递减。例:select * from test where area='11' select * from test where area='11' and age=1 select * from test where area='11' and age=1 and salary=2.0 以上有索引select * from test where age=11 select * from test where  age=1 and salary=2.0 以上无索引 -----------------------------------如果在查询中需要匹配多个字段的条件,可以把这几个字段做个联合索引,效率要比在每个字段上加索引高多了