Mysql联合索引优化

创建表,以及联合索引 b_c_d
CREATE TABLE tab_test (
id int(11) NOT NULL,
a int(11) NOT NULL,
b int(11) NOT NULL,
c varchar(255) NOT NULL,
d int(11) NOT NULL,
PRIMARY KEY (id),
KEY idx_b_c_d (b,c,d) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1

能命中的索引情况。
//【左匹配】,b_c_d 索引
1 explain select * from tab_test where b = 1;

2 explain select * from tab_test where b = 1 and c= ‘e’; //交换 b,c 的位置,也能命中索引,应
为查询优化器会交换他们的位置。
3 explain select * from tab_test where c= ‘e’ and b = 1 and d= 1;
//【左匹配+其它字段】也能命中 b_c_d 索引。
1 explain select * from tab_test where b = 1 and a=6;
2 explain select * from tab_test where b = 1 and c= ‘e’ and a=6;
3 explain select * from tab_test w

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值