看起来和时间段内的数据确实有关,但是我不理解为什么会这样,难道即便 索引+回写的行数小于全表扫描行数一个数量级,实际耗时也是前者更高吗?
explain analyze SELECT ls.service_state, ls.timestamp FROM ls WHERE ls.timestamp > "2024-03-25 01:32:47" and ls.timestamp < "2024-03-30 01:32:47"
id |estRows |actRows |task |access object|execution info |operator info |memory |disk|
---------------------+-----------+--------+---------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+--------+----+
Projection_4 |580657.83 |578325 |root | |time:2.41s, loops:570, Concurrency:5 |ls.service_state, ls.timestamp |129.2 KB|N/A |
└─TableReader_7 |580657.83 |578325 |root | |time:2.41s, loops:570, cop_task: {num: 95, max: 829.4ms, min: 1.17ms, avg: 344.9ms, p95: 689.8ms, max_proc_keys: 554792, p95_proc_keys: 521241, tot_proc: 32.5s, tot_wait: 43ms, rpc_num: 95, rpc_time: 32.8s, copr_cache_hit_ratio: 0.00, distsql_concurrency:|data:Selection_6 |1.08 MB |N/A |
└─Selection_6 |580657.83 |578325 |cop[tikv]| |tikv_task:{proc max:829ms, min:0s, avg: 342.5ms, p80:502ms, p95:687ms, iters:34490, tasks:95}, scan_detail: {total_process_keys: 34892667, total_process_keys_size: 7457693379, total_keys: 34892762, get_snapshot_time: 2.92ms, rocksdb: {key_skipped_count: 3|gt(ls.timestamp, 2024-03-25 01:32:47.000000), lt(ls.timestamp, 2024-03-30 01:32:47.000000)|N/A |N/A |
└─TableFullScan_5|34892667.00|34892667|cop[tikv]|table:ls |tikv_task:{proc max:727ms, min:0s, avg: 265.5ms, p80:394ms, p95:558ms, iters:34490, tasks:95} |keep order:false |N/A |N/A |
-----
explain analyze SELECT ls.service_state, ls.timestamp FROM ls WHERE ls.timestamp > "2024-03-26 01:32:47" and ls.timestamp < "2024-03-30 01:32:47"
id |estRows |actRows|task |access object |execution info |operator info |memory |disk|
---------------------------+---------+-------+---------+-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------+--------+----+
Projection_4 |477004.35|469005 |root | |time:498ms, loops:460, Concurrency:5 |ls.service_state, ls.timestamp |140.2 KB|N/A |
└─IndexLookUp_10 |477004.35|469005 |root | |time:497.2ms, loops:460, index_task: {total_time: 471.3ms, fetch_handle: 470.9ms, build: 79.9µs, wait: 335.1µs}, table_task: {total_time: 594.9ms, num: 27, concurrency: 5} | |2.64 MB |N/A |
├─IndexRangeScan_8(Build)|477004.35|469005 |cop[tikv]|table:ls, index:timestamp(timestamp, organization_id, cluster_id, host_name, host_ip)|time:420.1ms, loops:464, cop_task: {num: 33, max: 77.7ms, min: 1.44ms, avg: 20.7ms, p95: 69.8ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 614ms, rpc_num: 33, rpc_time: 681.1ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, tikv_task:{|range:(2024-03-26 01:32:47.000,2024-03-30 01:32:47.000), keep order:false|N/A |N/A |
└─TableRowIDScan_9(Probe)|477004.35|469005 |cop[tikv]|table:ls |time:395.5ms, loops:499, cop_task: {num: 37, max: 21ms, min: 1.19ms, avg: 11.9ms, p95: 20.3ms, max_proc_keys: 20480, p95_proc_keys: 20480, tot_proc: 363ms, tot_wait: 1ms, rpc_num: 37, rpc_time: 439.2ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}|keep order:false |N/A |N/A |
-------
explain analyze SELECT ls.service_state, ls.timestamp FROM ls WHERE ls.timestamp > "2023-12-25 01:32:47" and ls.timestamp < "2023-12-30 01:32:47"
id |estRows |actRows |task |access object|execution info |operator info |memory |disk|
---------------------+-----------+--------+---------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+--------+----+
Projection_4 |633659.55 |665571 |root | |time:2.11s, loops:655, Concurrency:5 |ls.service_state, ls.timestamp |130.8 KB|N/A |
└─TableReader_7 |633659.55 |665571 |root | |time:2.11s, loops:655, cop_task: {num: 103, max: 509.2ms, min: 1.46ms, avg: 273.1ms, p95: 489.4ms, max_proc_keys: 554792, p95_proc_keys: 521184, tot_proc: 27.6s, tot_wait: 337ms, rpc_num: 103, rpc_time: 28.1s, copr_cache_hit_ratio: 0.00, distsql_concurren|data:Selection_6 |1.15 MB |N/A |
└─Selection_6 |633659.55 |665571 |cop[tikv]| |tikv_task:{proc max:494ms, min:0s, avg: 267.9ms, p80:427ms, p95:479ms, iters:34520, tasks:103}, scan_detail: {total_process_keys: 34892667, total_process_keys_size: 7457693379, total_keys: 34892770, get_snapshot_time: 141.2ms, rocksdb: {key_skipped_count:|gt(ls.timestamp, 2023-12-25 01:32:47.000000), lt(ls.timestamp, 2023-12-30 01:32:47.000000)|N/A |N/A |
└─TableFullScan_5|34892667.00|34892667|cop[tikv]|table:ls |tikv_task:{proc max:408ms, min:0s, avg: 196.2ms, p80:322ms, p95:369ms, iters:34520, tasks:103} |keep order:false |N/A |N/A |
------
explain analyze SELECT ls.service_state, ls.timestamp FROM ls WHERE ls.timestamp > "2023-11-25 01:32:47" and ls.timestamp < "2023-11-30 01:32:47"
id |estRows |actRows|task |access object |execution info |operator info |memory |disk|
---------------------------+---------+-------+---------+-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------+--------+----+
Projection_4 |206297.88|271519 |root | |time:62.5ms, loops:267, Concurrency:5 |ls.service_state, ls.timestamp |137.3 KB|N/A |
└─IndexLookUp_10 |206297.88|271519 |root | |time:62.1ms, loops:267, index_task: {total_time: 50.8ms, fetch_handle: 20.9ms, build: 23µs, wait: 29.9ms}, table_task: {total_time: 246.8ms, num: 17, concurrency: 5} | |3.93 MB |N/A |
├─IndexRangeScan_8(Build)|206297.88|271519 |cop[tikv]|table:ls, index:timestamp(timestamp, organization_id, cluster_id, host_name, host_ip)|time:8.8ms, loops:272, cop_task: {num: 21, max: 2.54ms, min: 382.8µs, avg: 1.07ms, p95: 2.13ms, max_proc_keys: 992, p95_proc_keys: 992, tot_proc: 1ms, rpc_num: 21, rpc_time: 22.1ms, copr_cache_hit_ratio: 0.71, distsql_concurrency: 15}, tikv_task:{proc max|range:(2023-11-25 01:32:47.000,2023-11-30 01:32:47.000), keep order:false|N/A |N/A |
└─TableRowIDScan_9(Probe)|206297.88|271519 |cop[tikv]|table:ls |time:163.2ms, loops:294, cop_task: {num: 27, max: 30.7ms, min: 562.8µs, avg: 7.66ms, p95: 25.7ms, max_proc_keys: 20480, p95_proc_keys: 20480, tot_proc: 161ms, rpc_num: 27, rpc_time: 206.1ms, copr_cache_hit_ratio: 0.22, distsql_concurrency: 15}, tikv_task:|keep order:false |N/A |N/A |