我感觉这是统计缺陷,算子在执行过程中有三个步骤(经典火山模型):open、next、close。IndexReader在统计执行时间时候是在next时候统计的。但是去tikv请求数据时候是在open阶段就开始了,但是并没有统计到IndexReader里面。如果大结果集执行时间大多都在Next上的时候不太明显,如果想你这种执行的非常快,那么就容易看到子算子的执行时间反而可能比IndexReader还要大。
看我这个大结果集的,看起来就没什么问题。
mysql> explain analyze select L_SHIPDATE from lineitem where L_RECEIPTDATE < now() and L_LINENUMBER > 1;
+----------------------------+-------------+----------+-----------+---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+----------------------------+-------------+----------+-----------+---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
| Projection_4 | 19973507.81 | 20029587 | root | | time:3.6s, loops:20923, Concurrency:5 | tpch.lineitem.l_shipdate | 193.3 KB | N/A |
| └─IndexReader_7 | 19973507.81 | 20029587 | root | | time:3.47s, loops:20923, cop_task: {num: 712, max: 248.7ms, min: 548.2µs, avg: 62.2ms, p95: 152.3ms, max_proc_keys: 67552, p95_proc_keys: 67552, tot_proc: 31.4s, tot_wait: 6.28s, rpc_num: 712, rpc_time: 44.3s, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15} | index:Selection_6 | 4.74 MB | N/A |
| └─Selection_6 | 19973507.81 | 20029587 | cop[tikv] | | tikv_task:{proc max:193ms, min:0s, avg: 41.9ms, p80:75ms, p95:116ms, iters:28903, tasks:712}, scan_detail: {total_process_keys: 26706944, total_process_keys_size: 2243383296, total_keys: 26707656, get_snapshot_time: 311.8ms, rocksdb: {key_skipped_count: 26706944, block: {cache_hit_count: 3541, read_count: 24926, read_byte: 147.6 MB, read_time: 156.8ms}}} | gt(tpch.lineitem.l_linenumber, 1) | N/A | N/A |
| └─IndexRangeScan_5 | 24966884.76 | 26706944 | cop[tikv] | table:lineitem, index:idx2(L_RECEIPTDATE, L_SHIPDATE, L_LINENUMBER) | tikv_task:{proc max:193ms, min:0s, avg: 40.9ms, p80:72ms, p95:115ms, iters:28903, tasks:712} | range:[-inf,2023-05-28], keep order:false | N/A | N/A |
+----------------------------+-------------+----------+-----------+---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
4 rows in set (3.61 sec)