为提高效率,请提供以下信息,问题描述清晰能够更快得到解决:
【 TiDB 使用环境】
版本:v4.0.10
环境:生产环境
【概述】 场景 + 问题概述
相同的sql,并且force index,问题期间从执行计划的算子信息中查看是rpc_time比正常期间更长,这个值的含义从官网有看到,但是不清楚具体原因是什么。
问题期间服务器无压力,cpu load在2.39%左右、io使用率在10%以内,内存256G
tikv节点无pending,恢复正常前无analyze table,表健康度91。
【背景】 做过哪些操作
无任何操作
【现象】 业务和数据库现象
问题期间该条sql慢查较多
【问题】 当前遇到的问题
相同的执行计划,问题期间limit算子中的rpc_time比正常时间高200ms左右
【TiDB 版本】
v4.0.10
【附件】 相关日志及配置信息
sql如下:
SELECT id
, videocid
, videoaid
, cmtid
, userid
, state
, dmctime
, utime
, last_push_time
, last_push_state
, current_push_status
, last_hit_strategy
, validate
, mtime
, ctime
FROM table_xx
force index(ix_current_push_status_utime) WHERE (current_push_status
= 0 AND utime
<= 1640335762) AND utime
>= 1640332252 LIMIT 2000;
表结构如下:
CREATE TABLE `table_xx` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`videocid` bigint(20) unsigned NOT NULL DEFAULT '0'',
`cmtid` bigint(20) unsigned NOT NULL DEFAULT '0' ,
`userid` bigint(20) unsigned NOT NULL DEFAULT '0' ,
`state` int(11) NOT NULL DEFAULT '0',
`dmctime` int(11) NOT NULL DEFAULT '0',
`utime` int(11) NOT NULL DEFAULT '0',
`last_push_time` int(11) NOT NULL DEFAULT '0' ,
`last_push_state` int(11) NOT NULL DEFAULT '0',
`current_push_status` tinyint(4) NOT NULL DEFAULT '0' ,
`last_hit_strategy` varchar(20) NOT NULL DEFAULT '' ,
`validate` int(11) NOT NULL DEFAULT '0',
`mtime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
`ctime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`videoaid` bigint(20) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_cmtid` (`cmtid`),
KEY `ix_current_push_status_last_push_time` (`current_push_status`,`last_push_time`),
KEY `ix_dmctime` (`dmctime`),
KEY `ix_ctime` (`ctime`),
KEY `ix_mtime` (`mtime`),
KEY `ix_utime` (`utime`),
KEY `ix_aid` (`videoaid`),
KEY `ix_current_push_status_utime` (`current_push_status`,`utime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=730415744
正常期间执行计划:
+----------------------------------+---------+---------+-----------+-----------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+----------------------------------+---------+---------+-----------+-----------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------+
| Projection_7 | 77.71 | 0 | root | | time:38.881407ms, loops:1, Concurrency:OFF | DBxx.tablexx.id, DBxx.tablexx.videocid, DBxx.tablexx.videoaid, DBxx.tablexx.cmtid, DBxx.tablexx.userid, DBxx.tablexx.state, DBxx.tablexx.dmctime, DBxx.tablexx.utime, DBxx.tablexx.last_push_time, DBxx.tablexx.last_push_state, DBxx.tablexx.current_push_status, DBxx.tablexx.last_hit_strategy, DBxx.tablexx.validate, DBxx.tablexx.mtime, DBxx.tablexx.ctime | 5.5703125 KB | N/A |
| └─IndexLookUp_14 | 77.71 | 0 | root | | time:38.878846ms, loops:1, table_task:{num:0, concurrency:4, time:155.34822ms} | limit embedded(offset:0, count:2000) | 235 Bytes | N/A |
| ├─Limit_13(Build) | 77.71 | 0 | cop[tikv] | | time:0s, loops:0, cop_task: {num: 1, max:38.73929ms, proc_keys: 50678, rpc_num: 1, rpc_time: 38.723702ms, copr_cache_hit_ratio: 0.00}, tikv_task:{time:36ms, loops:1} | offset:0, count:2000 | N/A | N/A |
| │ └─IndexRangeScan_11 | 77.71 | 0 | cop[tikv] | table:tablexx, index:ix_current_push_status_utime(current_push_status, utime) | time:0ns, loops:0, tikv_task:{time:36ms, loops:1} | range:[0 1640332252,0 1640335762], keep order:false | N/A | N/A |
| └─TableRowIDScan_12(Probe) | 77.71 | 0 | cop[tikv] | table:tablexx | time:0ns, loops:0 | keep order:false, stats:pseudo | N/A | N/A |
+----------------------------------+---------+---------+-----------+-----------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+------+
5 rows in set (0.04 sec)
问题期间执行计划:
|| |id |task |estRows |operator info |actRows|execution info |memory |disk|
|---|---|---|---|---|---|---|---|---|
||Projection_7 |root |77.62712324719992|DBxx.tablexx.id, DBxx.tablexx.videocid, DBxx.tablexx.videoaid, DBxx.tablexx.cmtid, DBxx.tablexx.userid, DBxx.tablexx.state, DBxx.tablexx.dmctime, DBxx.tablexx.utime, DBxx.tablexx.last_push_time, DBxx.tablexx.last_push_state, DBxx.tablexx.current_push_status, DBxx.tablexx.last_hit_strategy, DBxx.tablexx.validate, DBxx.tablexx.mtime, DBxx.tablexx.ctime|0 |time:182.72606ms, loops:1, Concurrency:OFF |5.5703125 KB|N/A|
||└─IndexLookUp_14 |root |77.62712324719992|limit embedded(offset:0, count:2000) |0 |time:182.723766ms, loops:1, table_task:{num:0, concurrency:4, time:730.762083ms} |235 Bytes |N/A|
|| ├─Limit_13 |cop[tikv]|77.62712324719992|offset:0, count:2000 |0 |time:0s, loops:0, cop_task: {num: 1, max:182.618097ms, proc_keys: 50678, rpc_num: 1, rpc_time: 182.606906ms, copr_cache_hit_ratio: 0.00}, tikv_task:{time:64ms, loops:1}|N/A |N/A|
|| │ └─IndexScan_11|cop[tikv]|77.62712324719992|table:tablexx, index:ix_current_push_status_utime(current_push_status, utime), range:[0 1640332252,0 1640335762], keep order:false |0 |time:0ns, loops:0, tikv_task:{time:64ms, loops:1} |N/A |N/A|
|| └─TableScan_12 |cop[tikv]|77.62712324719992|table:tablexx, keep order:false, stats:pseudo |0 |time:0ns, loops:0 |N/A |N/A ||
两个执行计划不同的地方:
有问题:cop_task: {num: 1, max:182.618097ms, proc_keys: 50678, rpc_num: 1, rpc_time: 182.606906ms, copr_cache_hit_ratio: 0.00}, tikv_task:{time:64ms, loops:1}
正常:cop_task: {num: 1, max:38.73929ms, proc_keys: 50678, rpc_num: 1, rpc_time: 38.723702ms, copr_cache_hit_ratio: 0.00}, tikv_task:{time:36ms, loops:1}
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。