1、这个表有几十亿数据,脚本是分批删除的,实际上是limit 5000;
统计信息早上刚搜集过了
2、删除的慢具体慢在哪里从上图的执行计划信息能分辨出来吗 ?这个sql 执行计划是走了正确的索引的
重新跑了一个delete 信息如下: 麻烦看下能否大概定位到问题,为何indexlookup 这里会耗时这么久 ?
MySQL [up_ks_pigai]> explain analyze DELETE FROM `tblCorrectRecordScancode` force index(idx_create_time) WHERE create_time < 1668287229 limit 5000;
+----------------------------------+---------+---------+-----------+--------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+---------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+----------------------------------+---------+---------+-----------+--------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+---------+------+
| Delete_5 | N/A | 0 | root | | time:2m16.9s, loops:1 | N/A | 4.72 MB | N/A |
| └─IndexLookUp_14 | 5000.00 | 5000 | root | | time:2m16.8s, loops:6, index_task: {total_time: 2m16.7s, fetch_handle: 2m16.7s, build: 2.29µs, wait: 7.8µs}, table_task: {total_time: 220.2ms, num: 3, concurrency: 5}, next: {wait_index: 2m16.7s, wait_table_lookup_build: 568.5µs, wait_table_lookup_resp: 28.6ms} | limit embedded(offset:0, count:5000) | 23.5 MB | N/A |
| ├─Limit_13(Build) | 5000.00 | 6752 | cop[tikv] | | time:2m16.7s, loops:6, cop_task: {num: 343, max: 1.94s, min: 276.5µs, avg: 398.4ms, p95: 793.4ms, max_proc_keys: 3040, p95_proc_keys: 0, tot_proc: 2m16.1s, tot_wait: 8ms, rpc_num: 343, rpc_time: 2m16.6s, copr_cache_hit_ratio: 0.14, distsql_concurrency: 1}, tikv_task:{proc max:1.94s, min:0s, avg: 456.5ms, p80:618ms, p95:793ms, iters:363, tasks:343}, scan_detail: {total_process_keys: 6752, total_process_keys_size: 310592, total_keys: 441734885, get_snapshot_time: 16.4ms, rocksdb: {delete_skipped_count: 57658013, key_skipped_count: 547864360, block: {cache_hit_count: 333684, read_count: 29, read_byte: 1.34 MB, read_time: 822.3µs}}} | offset:0, count:5000 | N/A | N/A |
| │ └─IndexRangeScan_11 | 6250.00 | 6752 | cop[tikv] | table:tblCorrectRecordScancode, index:idx_create_time(create_time) | tikv_task:{proc max:1.94s, min:0s, avg: 456.4ms, p80:618ms, p95:793ms, iters:363, tasks:343} | range:[-inf,1668287229), keep order:false | N/A | N/A |
| └─TableRowIDScan_12(Probe) | 5000.00 | 5000 | cop[tikv] | table:tblCorrectRecordScancode | time:217.2ms, loops:9, cop_task: {num: 95, max: 61.1ms, min: 1.02ms, avg: 4.96ms, p95: 11ms, max_proc_keys: 127, p95_proc_keys: 92, tot_proc: 145ms, rpc_num: 95, rpc_time: 469.7ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, tikv_task:{proc max:4ms, min:0s, avg: 1.53ms, p80:2ms, p95:3ms, iters:179, tasks:95}, scan_detail: {total_process_keys: 5000, total_process_keys_size: 22088846, total_keys: 5538, get_snapshot_time: 1.86ms, rocksdb: {delete_skipped_count: 297, key_skipped_count: 1160, block: {cache_hit_count: 54287, read_count: 13, read_byte: 526.3 KB, read_time: 405.3µs}}} | keep order:false | N/A | N/A |
+----------------------------------+---------+---------+-----------+--------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+---------+------+
3、max_execution_time 这个参数我问的 表述有误,我的理解是sql 执行超过5s 会被终止执行,返回报错 interrupted ? 这个delete 没有被终止是因为前面indexLookUP 这里的等待不算在执行时间里 ?
从执行计划看出,应该慢在了这个cop_task 上了,然后再怎么优化 ?遇到技术瓶颈了😂
cop_task: {num: 343, max: 1.95s, min: 712.6µs, avg: 460.7ms, p95: 821.8ms, max_proc_keys: 3040, p95_proc_keys: 0, tot_proc: 2m37.2s, tot_wait: 24ms, rpc_num: 343, rpc_time: 2m38s, copr_cache_hit_ratio: 0.00, distsql_concurrency: 1}