如果我们创建了(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 以上无索引 ----------------------------------- 如果在查询中需要匹配多个字段的条件,可以把这几个字段做个联合索引,效率要比在每个字段上加索引高多了
msyql同时建立索引和分开建立索引的区别
最新推荐文章于 2021-11-17 15:40:11 发布