为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
- 【TiDB 版本】:4.0.2
- 【问题描述】:简单两个表关联,慢查询去到几百毫秒,但是查看执行时间显示过程中的时间并不多,然后最后一步执行sql却耗时几百毫秒,这是什么原因呢?
单独执行耗时很快统计显示也只有2到3ms,但是在并发上来后降几百毫秒
在压测中执行EXPLAIN ANALYZE,发现在root的执行计划会浮动很大:
IndexMergeJoin_18 | 0.00 | 0 | root | time:124.825988ms, loops:1, Concurrency:OFF | inner join, inner:IndexReader_16, outer key:course.homework.clazz_plan_id, inner key:course.clazz_plan.id | 0 Bytes | N/A | |
---|---|---|---|---|---|---|---|---|
├─IndexMergeJoin_50(Build) | 0.00 | 0 | root | time:63.201669ms, loops:1, Concurrency:OFF | inner join, inner:Projection_48, outer key:course.student_paper.paper_id, inner key:course.homework.paper_id | 0 Bytes | N/A | |
│ ├─IndexLookUp_75(Build) | 0.01 | 0 | root | time:63.217145ms, loops:1, rpc num: 1, rpc time:29.26465ms, proc keys:0 | 188 Bytes | N/A | ||
│ │ ├─IndexRangeScan_72(Build) | 10.00 | 0 | cop[tikv] | table:sp, index:udx_student_paper_student_id_paper_id(student_id, paper_id) | time:0s, loops:1 | range:[150607,150607], keep order:false, stats:pseudo | N/A | N/A |
│ │ └─Selection_74(Probe) | 0.01 | cop[tikv] | time:0ns, loops:0 | eq(course.student_paper.status, 1) | N/A | N/A | ||
│ │ └─TableRowIDScan_73 | 10.00 | 0 | cop[tikv] | table:sp | time:0s, loops:0 | keep order:false, stats:pseudo | N/A | N/A |
│ └─Projection_48(Probe) | 0.00 | root | time:0ns, loops:0 | course.homework.id, course.homework.title, course.homework.type, course.homework.clazz_id, course.homework.clazz_plan_id, course.homework.paper_id, course.homework.arrange_time, course.homework.start_time, course.homework.expired_time, course.homework.status | N/A | N/A | ||
│ └─IndexLookUp_47 | 0.00 | root | time:0ns, loops:0 | N/A | N/A | |||
│ ├─Selection_45(Build) | 9990.00 | cop[tikv] | time:0ns, loops:0 | not(isnull(course.homework.paper_id)) | N/A | N/A | ||
│ │ └─IndexRangeScan_43 | 10000.00 | cop[tikv] | table:h, index:paper_id(paper_id) | time:0ns, loops:0 | range: decided by [eq(course.homework.paper_id, course.student_paper.paper_id)], keep order:true, stats:pseudo | N/A | N/A | |
│ └─Selection_46(Probe) | 0.00 | cop[tikv] | time:0ns, loops:0 | eq(course.homework.status, 1), gt(course.homework.expired_time, 2020-07-10 00:00:00.000000), in(course.homework.type, 1, 2), lt(course.homework.start_time, 2020-07-11 00:00:00.000000) | N/A | N/A | ||
│ └─TableRowIDScan_44 | 9990.00 | cop[tikv] | table:h | time:0ns, loops:0 | keep order:false, stats:pseudo | N/A | N/A | |
└─IndexReader_16(Probe) | 1.00 | root | time:0ns, loops:0 | index:IndexRangeScan_15 | N/A | N/A | ||
└─IndexRangeScan_15 | 1.00 | cop[tikv] | table:cp, index:PRIMARY(id) | time:0ns, loops:0 | range: decided by [eq(course.clazz_plan.id, course.homework.clazz_plan_id)], keep order:true | N/A | N/A |
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出打印结果,请务必全选并复制粘贴上传。