mysql - MySQL 为什么将限制从 20 增加到 21 将执行时间从 1,4s 减少到 0,0067s
问题描述
我有一个有 230 000 行的表
查询 1 持续时间 1,389 秒
SELECT sql_no_cache `model_regulation_sections`.*
FROM `model_regulation_sections`
WHERE `model_regulation_sections`.`regulation_id` = 254
ORDER BY `model_regulation_sections`.`lft` ASC
LIMIT 20
解释
select_type = SIMPLE
table = model_regulation_sections
partitions = null`
type = index
possible_keys = document_id
key = lft
key_len = 4
ref = null
rows = 2229
filtered = 0.90
Extra = 使用 where
查询 2 持续时间 0,0067
SELECT sql_no_cache `model_regulation_sections`.*
FROM `model_regulation_sections`
WHERE `model_regulation_sections`.`regulation_id` = 254
ORDER BY `model_regulation_sections`.`lft` ASC
LIMIT 21
解释
select_type = SIMPLE
table = model_regulation_sections
partitions = null`
type = ref
possible_keys = document_id
key = lft
key_len = 4
ref = const
rows = 2251
filtered = 100
Extra = '使用索引条件;使用文件排序'
MySQL 为什么将限制从 20 增加到 21 会将执行时间从 1,4s 减少到 0,0067s?
为什么 2 小时前查询 1 的执行时间是 13.5 秒?我没有更改配置。
解决方案
推荐阅读
- java - 通过 Writer 写入数百万个字符串会成为 Java 字符串池的内存和性能问题吗?
- android - IMEI SV 71 - 是否意味着 71 次服务?
- angular - webpack 引用没有变量的类型
- python - 对话流中的最大训练短语
- bootstrap-4 - Bootstrap 4嵌套下拉菜单?
- ruby-on-rails - 使用 Arel 跨表查询
- java - 如何使redis在java中的确切时间过期?
- javascript - 为 Postman 中的每个请求测试设置可访问的测试集合变量
- angular - 运行 Angular 应用程序时出错
- java - 使用 smack 4.2.2 从 Openfire 服务器获取所有用户