为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
- 【TiDB 版本】:V4.0.0
- 【问题描述】:
tikv都是32核 , Coprocessor 都是默认80% 配置为25 ,手动执行毫秒级别,不知道为什么会经常有这种慢sql,应该不会慢才对
CREATE TABLE recommend_recall_user_history
(
ukey
varchar(64) NOT NULL ,
dt
date NOT NULL ,
consults
text NOT NULL ,
PRIMARY KEY (ukey
,dt
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
PARTITION BY RANGE ( TO_DAYS(dt
) ) (
PARTITION p20201028
VALUES LESS THAN (738092),
PARTITION p20201029
VALUES LESS THAN (738093),
PARTITION p20201030
VALUES LESS THAN (738094),
PARTITION p20201031
VALUES LESS THAN (738095),
PARTITION p20201101
VALUES LESS THAN (738096),
PARTITION p20201102
VALUES LESS THAN (738097),
PARTITION p20201103
VALUES LESS THAN (738098)
)
查询语句:
SELECT dt, consults FROM recommend_recall_user_history
WHERE ukey = ? ORDER BY dt DESC LIMIT 1 [arguments: 307005];
查询计划:
Projection_22 root 1 wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
└─TopN_25 root 1 wk_bigdata_main.recommend_recall_user_history.dt:desc, offset:0, count:1
└─Union_29 root 1
├─Projection_54 root 0 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
│ └─IndexLookUp_53 root 0 limit embedded(offset:0, count:1)
│ ├─Limit_52 cop 0 offset:0, count:1
│ │ └─IndexScan_50 cop 0 table:recommend_recall_user_history, partition:p20201028, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
│ └─TableScan_51 cop 0 table:recommend_recall_user_history, partition:p20201028, keep order:false, stats:pseudo
├─Projection_83 root 0 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
│ └─IndexLookUp_82 root 0 limit embedded(offset:0, count:1)
│ ├─Limit_81 cop 0 offset:0, count:1
│ │ └─IndexScan_79 cop 0 table:recommend_recall_user_history, partition:p20201029, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
│ └─TableScan_80 cop 0 table:recommend_recall_user_history, partition:p20201029, keep order:false, stats:pseudo
├─Projection_112 root 0 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
│ └─IndexLookUp_111 root 0 limit embedded(offset:0, count:1)
│ ├─Limit_110 cop 0 offset:0, count:1
│ │ └─IndexScan_108 cop 0 table:recommend_recall_user_history, partition:p20201030, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
│ └─TableScan_109 cop 0 table:recommend_recall_user_history, partition:p20201030, keep order:false, stats:pseudo
├─Projection_141 root 0 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
│ └─IndexLookUp_140 root 0 limit embedded(offset:0, count:1)
│ ├─Limit_139 cop 0 offset:0, count:1
│ │ └─IndexScan_137 cop 0 table:recommend_recall_user_history, partition:p20201031, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
│ └─TableScan_138 cop 0 table:recommend_recall_user_history, partition:p20201031, keep order:false, stats:pseudo
├─Projection_170 root 1 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
│ └─IndexLookUp_169 root 1 limit embedded(offset:0, count:1)
│ ├─Limit_168 cop 1 offset:0, count:1
│ │ └─IndexScan_166 cop 1 table:recommend_recall_user_history, partition:p20201101, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
│ └─TableScan_167 cop 1 table:recommend_recall_user_history, partition:p20201101, keep order:false, stats:pseudo
├─Projection_199 root 0 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
│ └─IndexLookUp_198 root 0 limit embedded(offset:0, count:1)
│ ├─Limit_197 cop 0 offset:0, count:1
│ │ └─IndexScan_195 cop 0 table:recommend_recall_user_history, partition:p20201102, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
│ └─TableScan_196 cop 0 table:recommend_recall_user_history, partition:p20201102, keep order:false, stats:pseudo
└─Projection_228 root 0 wk_bigdata_main.recommend_recall_user_history.ukey, wk_bigdata_main.recommend_recall_user_history.dt, wk_bigdata_main.recommend_recall_user_history.consults
└─IndexLookUp_227 root 0 limit embedded(offset:0, count:1)
├─Limit_226 cop 0 offset:0, count:1
│ └─IndexScan_224 cop 0 table:recommend_recall_user_history, partition:p20201103, index:PRIMARY(ukey, dt), range:["307005","307005"], keep order:true, desc
└─TableScan_225 cop 0 table:recommend_recall_user_history, partition:p20201103, keep order:false, stats:pseudo
执行时间:
解析耗时
26.4 µs
解析该 SQL 查询的耗时
优化耗时
1.0 ms
优化该 SQL 查询的耗时
Coprocessor 累计等待耗时
7.4 s
Coprocessor 累计执行耗时
4.0 ms
Coprocessor 累计执行耗时
累计重试等待耗时
0 ns
取 Commit Ts 耗时
0 ns
从 PD 取递交时间戳(事务号)步骤的耗时
Local Latch Wait 耗时
0 ns
事务在 TiDB 本地与其他事务产生了锁冲突并等待的耗时
Resolve Lock 耗时
0 ns
事务在 TiKV 与其他事务产生了锁冲突并处理锁冲突的耗时
Prewrite 阶段耗时
0 ns
Commit 阶段耗时
0 ns
Commit 重试等待耗时
0 ns
SQL 执行时间
3.7 s
由于存在并行执行,因此 SQL 执行时间可能远小于上述各项时间
coprocessor读取:
Coprocessor 请求数
14
可见版本数
14
遇到版本数
21
含已删除或覆盖但未 GC 的版本
最长处理时间实例
10.223.1.159:20171
耗费最长时间处理 Coprocessor 请求的 TiKV 实例地址
最长等待时间实例
10.223.1.155:20171
耗费最长时间等待 Coprocessor 请求的 TiKV 实例地址
集群信息