MySQL为什么将限制从20增加到21将执行时间从1,4秒减少到00067秒
我有一张23万行的桌子MySQL为什么将限制从20增加到21将执行时间从1,4秒减少到00067秒,mysql,Mysql,我有一张23万行的桌子 查询1持续时间1389秒 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 解释 选择类型=简单 表=型号\法规\章节 分区=
查询1持续时间1389秒
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
解释选择类型=简单
表=型号\法规\章节
分区=null`
类型=索引
可能的\u键=文档\u id
键=lft
键长度=4
ref=null
行数=2229
过滤=0.90
额外=使用where
查询2持续时间00067
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
解释选择类型=简单
表=型号\法规\章节
分区=null`
类型=ref
可能的\u键=文档\u id
键=lft
键长度=4
ref=常数
行数=2251
过滤=100
额外='使用索引条件;使用文件排序“
MySQL为什么将限制从20增加到21会将执行时间从1,4s减少到00067 为什么2小时前查询1的执行时间是13,5秒?
我没有更改配置。你能了解一些额外的知识吗?你在sp里面吗?服务器的配置如何?您似乎没有(regulation_id,lft)上的索引,因此优化器正在尽其所能。。。但是,更改表中的数据会更改统计信息,并且可能会扭曲查询计划,特别是在没有真正最优的计划可用时。你能尝试添加那个索引吗?@VictorVictorMySQL 5.7.11自制默认配置
#默认自制MySQL服务器配置
[mysqld]
#仅允许从本地主机连接
绑定地址=127.0.0.1
@Michael sqlbot添加该索引可减少执行时间。我不确定,但是查询1的持续时间从13,5秒减少到了1,4秒,执行后使用ORDER BY model_regulation_sections.regulation_id,model_regulation_sections.lft,我猜您没有索引克隆,对吗?