联合索引和单个索引的区别:

联合索引和单个索引的区别:
如果我们创建了(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

以上无索引

如果在查询中需要匹配多个字段的条件,可以把这几个字段做个联合索引,效率要比在每个字段上加索引高多了

猜你喜欢

转载自blog.csdn.net/weixin_42914675/article/details/85158866