mysql创建多列索引语句_mysql多列索引详解

创建多列索引 在t_user表id,userName,email字段上创建多列索引(该表只有此索引): alter table t_user add index USER_INDEX(id, userName, email); 能够利用该索引的查询 符合leftmost index prefixes原则的查询 select * from t_user where id = 40;se

创建多列索引

在t_user表id,userName,email字段上创建多列索引(该表只有此索引):alter table t_user add index USER_INDEX(id, userName, email);

能够利用该索引的查询

符合leftmost index prefixes原则的查询select * from t_user where id = 40;

select * from t_user where id between 10 and 50;

select * from t_user where id in (30, 31, 32);

select * from t_user where id = 40 and userName = '侯西阳';

select * from t_user where id = 40 and userName = '侯西阳' and email = 'xiyang.hou@gmail.com';

select * from t_user where id > 40 and userName > 't';

不能利用以上索引的查询

不符合leftmost index prefixes原则的查询select * from t_user where userName = '侯西阳';

select * from t_user where userName = '侯西阳' and email = 'xiyang.hou@gmail.om';

or查询select * from t_user where id = 40 or userName = '侯西阳';

不能使用索引的解决方案在where语句后面的查询字段建立单个索引及多列索引,注意leftmost index prefixes原则,避免建立重复索引

or查询使用union来连接查询结果,并在对应的字段上建立索引

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值