创建多列索引 在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原则的查询
BJXSHOP购物管理系统是一个功能完善、展示信息丰富的电子商店销售平台;针对企业与个人的网上销售系统;开放式远程商店管理;完善的订单管理、销售统计、结算系统;强力搜索引擎支持;提供网上多种在线支付方式解决方案;强大的技术应用能力和网络安全系统 BJXSHOP网上购物系统 - 书店版,它具备其他通用购物系统不同的功能,有针对图书销售而进行开发的一个电子商店销售平台,如图书ISBN,图书目录
0
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来连接查询结果,并在对应的字段上建立索引
原文地址:mysql多列索引详解, 感谢原作者分享。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号