mysql - LIKE 查询没有禁用 MySQL 中的复合索引的原因是什么
问题描述
这是我的表结构
CREATE TABLE t(
c1 CHAR(1) not null,
c2 CHAR(1) not null,
c3 CHAR(1) not null,
c4 CHAR(1) not null,
c5 CHAR(1) not null
)ENGINE InnoDB CHARSET UTF8;
alter table t add index c1234(c1,c2,c3,c4);
当我使用explain select * from t where c1='1' and c2 >'2' and c3='4'
时,解释结果显示key_len
只有 6,即只有 c1 和 c2 处于活动状态。
但是,执行后explain select * from t where c1='1' and c2 like '2%' and c3='4'
,结果显示key_len
为 9,所有索引都处于活动状态。
我认为LIKE %
查询是一个范围查询,例如<
and >
,而 的出现LIKE %
并没有影响它之后索引的使用。
解决方案
推荐阅读
- unity3d - Unity 2020.2.1f1 无标记 AR 插件
- applepay - ApplePay 服务器请求 Apple Pay 支付会话
- python - 有没有办法安装“pystan”和“fbprophet”。安装时出现错误
- java - RecyclerView 没有返回所有项目
- git - NPM 脚本自动执行包增量和 GIT 推送
- swift - 位置()/偏移()swiftUI的问题
- javascript - Vue:如何从 api 中删除项目
- python - 在python链表的头部插入
- php - 来自 LEFT JOIN 项的排序和分组查询结果
- java - Optaplanner 可以自动添加或删除计划实体吗?