【 TiDB 使用环境】生产环境 /测试/ Poc
【 TiDB 版本】
【复现路径】做过哪些操作出现的问题
【遇到的问题:问题现象及影响】
【资源配置】
语句1
select
count(1) as is_mobile_black
from abc.customer_risk
where aes_risk_value in ( 'PuJ/d/FH1B4Y23K+7sPYMg==','mMIAL/pPIJ724OtBXXvv+w==') and risk_type=1 and risk_item = 1
语句1的执行计划
+-----------------------------+---------+---------+-----------+---------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+-----------------------------+---------+---------+-----------+---------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+
| StreamAgg_17 | 1.00 | 1 | root | | time:626µs, loops:2 | funcs:count(Column#23)->Column#21 | 5.50 KB | N/A |
| └─IndexReader_18 | 1.00 | 0 | root | | time:623.3µs, loops:1, cop_task: {num: 2, max: 592.1µs, min: 512.8µs, avg: 552.5µs, p95: 592.1µs, rpc_num: 2, rpc_time: 1.05ms, copr_cache_hit_ratio: 1.00, distsql_concurrency: 15} | index:StreamAgg_9 | 319 Bytes | N/A |
| └─StreamAgg_9 | 1.00 | 0 | cop[tikv] | | tikv_task:{proc max:3ms, min:2ms, avg: 2.5ms, p80:3ms, p95:3ms, iters:2, tasks:2}, scan_detail: {get_snapshot_time: 551µs, rocksdb: {block: {}}} | funcs:count(1)->Column#23 | N/A | N/A |
| └─IndexRangeScan_16 | 2.03 | 0 | cop[tikv] | table:customer_risk, index:idx_aes_risk_value_risk_type_risk_item(aes_risk_value, risk_type, risk_item) | tikv_task:{proc max:3ms, min:2ms, avg: 2.5ms, p80:3ms, p95:3ms, iters:2, tasks:2} | range:["mMIAL/pPIJ724OtBXXvv+w==" 1 1,"mMIAL/pPIJ724OtBXXvv+w==" 1 1], ["PuJ/d/FH1B4Y23K+7sPYMg==" 1 1,"PuJ/d/FH1B4Y23K+7sPYMg==" 1 1], keep order:false | N/A | N/A |
+-----------------------------+---------+---------+-----------+---------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------+
4 rows in set (0.00 sec)
语句2
with related_id_collection as (
select distinct
aes_mobile
from abc.client_info_new
where related_id in (
select related_id
from abc.activity_join
where activity_id=1 and join_role='MGM_BE_INVITED' and account_id=202312200123
)
)
select
count(1) as is_mobile_black
from abc.customer_risk
where aes_risk_value in (select * from related_id_collection) and risk_type=1 and risk_item = 1
语句2的执行计划
+----------------------------------------------+------------+---------+-----------+---------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+---------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+----------------------------------------------+------------+---------+-----------+---------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+---------+
| HashAgg_18 | 1.00 | 1 | root | | time:1.72s, loops:2, partial_worker:{wall_time:1.718923941s, concurrency:5, task_num:0, tot_wait:8.594333898s, tot_exec:0s, tot_time:8.594335877s, max:1.71886768s, p95:1.71886768s}, final_worker:{wall_time:0s, concurrency:5, task_num:0, tot_wait:8.594411803s, tot_exec:3.568µs, tot_time:8.594418221s, max:1.718888906s, p95:1.718888906s} | funcs:count(1)->Column#52 | 6.15 KB | N/A |
| └─HashJoin_20 | 2226585.93 | 0 | root | | time:1.72s, loops:1, build_hash_table:{total:9.68ms, fetch:9.67ms, build:5.63µs}, probe:{concurrency:5, total:8.59s, max:1.72s, probe:421.3ms, fetch:8.17s} | semi join, equal:[eq(abc.customer_risk.aes_risk_value, abc.client_info_new.aes_mobile)] | 2.46 KB | 0 Bytes |
| ├─HashAgg_27(Build) | 11.01 | 2 | root | | time:9.65ms, loops:3, partial_worker:{wall_time:9.644612ms, concurrency:5, task_num:2, tot_wait:47.775398ms, tot_exec:274.905µs, tot_time:48.057754ms, max:9.615447ms, p95:9.615447ms}, final_worker:{wall_time:9.651113ms, concurrency:5, task_num:4, tot_wait:48.103764ms, tot_exec:18.188µs, tot_time:48.124101ms, max:9.626935ms, p95:9.626935ms} | group by:abc.client_info_new.aes_mobile, funcs:firstrow(abc.client_info_new.aes_mobile)->abc.client_info_new.aes_mobile | 240.2 KB | N/A |
| │ └─IndexHashJoin_37 | 11.01 | 1574 | root | | time:9.47ms, loops:3, inner:{total:8.41ms, concurrency:5, task:1, construct:12.9µs, fetch:7.96ms, build:2.9µs, join:434.1µs} | inner join, inner:IndexLookUp_34, outer key:abc.activity_join.related_id, inner key:abc.client_info_new.related_id, equal cond:eq(abc.activity_join.related_id, abc.client_info_new.related_id) | 67.7 KB | N/A |
| │ ├─HashAgg_65(Build) | 1.00 | 1 | root | | time:1.01ms, loops:3, partial_worker:{wall_time:995.868µs, concurrency:5, task_num:1, tot_wait:4.735654ms, tot_exec:5.978µs, tot_time:4.746302ms, max:961.318µs, p95:961.318µs}, final_worker:{wall_time:1.011992ms, concurrency:5, task_num:1, tot_wait:4.851593ms, tot_exec:12.018µs, tot_time:4.866267ms, max:988.619µs, p95:988.619µs} | group by:abc.activity_join.related_id, funcs:firstrow(abc.activity_join.related_id)->abc.activity_join.related_id | 74.8 KB | N/A |
| │ │ └─IndexLookUp_88 | 1.08 | 1 | root | | time:928.6µs, loops:2, index_task: {total_time: 432.9µs, fetch_handle: 431.1µs, build: 838ns, wait: 953ns}, table_task: {total_time: 441.6µs, num: 1, concurrency: 5}, next: {wait_index: 477.2µs, wait_table_lookup_build: 63.8µs, wait_table_lookup_resp: 374.7µs} | | 9.75 KB | N/A |
| │ │ ├─IndexRangeScan_85(Build) | 1.08 | 1 | cop[tikv] | table:activity_join, index:idx_account_active_rule(activity_id, join_role, account_id) | time:428.1µs, loops:3, cop_task: {num: 1, max: 387.1µs, proc_keys: 1, rpc_num: 1, rpc_time: 374.3µs, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, tikv_task:{time:0s, loops:1}, scan_detail: {total_process_keys: 1, total_process_keys_size: 120, total_keys: 2, get_snapshot_time: 7.88µs, rocksdb: {key_skipped_count: 1, block: {cache_hit_count: 10}}} | range:[1 "MGM_BE_INVITED" 202312200123,1 "MGM_BE_INVITED" 202312200123], keep order:false | N/A | N/A |
| │ │ └─Selection_87(Probe) | 1.08 | 1 | cop[tikv] | | time:358.3µs, loops:2, cop_task: {num: 1, max: 320.4µs, proc_keys: 1, rpc_num: 1, rpc_time: 297.1µs, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, tikv_task:{time:0s, loops:1}, scan_detail: {total_process_keys: 1, total_process_keys_size: 94, total_keys: 1, get_snapshot_time: 3.74µs, rocksdb: {block: {cache_hit_count: 9}}} | not(isnull(abc.activity_join.related_id)) | N/A | N/A |
| │ │ └─TableRowIDScan_86 | 1.08 | 1 | cop[tikv] | table:activity_join | tikv_task:{time:0s, loops:1} | keep order:false | N/A | N/A |
| │ └─IndexLookUp_34(Probe) | 11.01 | 1574 | root | | time:7.93ms, loops:3, index_task: {total_time: 2.01ms, fetch_handle: 2ms, build: 997ns, wait: 9.19µs}, table_task: {total_time: 10.6ms, num: 2, concurrency: 5}, next: {wait_index: 2.03ms, wait_table_lookup_build: 586.6µs, wait_table_lookup_resp: 5.24ms} | | 124.8 KB | N/A |
| │ ├─IndexRangeScan_32(Build) | 11.01 | 1574 | cop[tikv] | table:client_info_new, index:related_id(related_id) | time:1.95ms, loops:4, cop_task: {num: 3, max: 726.4µs, min: 523.1µs, avg: 629.9µs, p95: 726.4µs, max_proc_keys: 870, p95_proc_keys: 870, rpc_num: 3, rpc_time: 1.86ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, tikv_task:{proc max:1ms, min:0s, avg: 333.3µs, p80:1ms, p95:1ms, iters:12, tasks:3}, scan_detail: {total_process_keys: 1574, total_process_keys_size: 72404, total_keys: 1577, get_snapshot_time: 22.7µs, rocksdb: {key_skipped_count: 1574, block: {cache_hit_count: 42, read_count: 1, read_byte: 64.0 KB, read_time: 27.6µs}}} | range: decided by [eq(abc.client_info_new.related_id, abc.activity_join.related_id)], keep order:false | N/A | N/A |
| │ └─TableRowIDScan_33(Probe) | 11.01 | 1574 | cop[tikv] | table:client_info_new | time:9.58ms, loops:4, cop_task: {num: 305, max: 2.89ms, min: 216.1µs, avg: 1.14ms, p95: 2.38ms, max_proc_keys: 15, p95_proc_keys: 5, tot_proc: 2ms, tot_wait: 40ms, rpc_num: 305, rpc_time: 344ms, copr_cache_hit_ratio: 0.51, distsql_concurrency: 15}, tikv_task:{proc max:90ms, min:0s, avg: 16.6ms, p80:36ms, p95:68ms, iters:306, tasks:305}, scan_detail: {total_process_keys: 316, total_process_keys_size: 93044, total_keys: 316, get_snapshot_time: 66.2ms, rocksdb: {block: {cache_hit_count: 3850, read_count: 7, read_byte: 167.2 KB, read_time: 1.55ms}}} | keep order:false | N/A | N/A |
| └─IndexReader_26(Probe) | 2783232.42 | 2779713 | root | | time:1.64s, loops:2707, cop_task: {num: 461, max: 712ms, min: 188.8µs, avg: 32.9ms, p95: 94.5ms, max_proc_keys: 141280, p95_proc_keys: 47072, tot_proc: 14.2s, tot_wait: 192ms, rpc_num: 461, rpc_time: 15.1s, copr_cache_hit_ratio: 0.11, distsql_concurrency: 15} | index:Selection_25 | 3.49 MB | N/A |
| └─Selection_25 | 2783232.42 | 2779713 | cop[tikv] | | tikv_task:{proc max:704ms, min:0s, avg: 31.1ms, p80:49ms, p95:88ms, iters:9483, tasks:461}, scan_detail: {total_process_keys: 7740744, total_process_keys_size: 1669491051, total_keys: 7741156, get_snapshot_time: 52.2ms, rocksdb: {key_skipped_count: 7740744, block: {cache_hit_count: 5095, read_count: 25252, read_byte: 631.9 MB, read_time: 4.41s}}} | eq(abc.customer_risk.risk_item, 1), eq(abc.customer_risk.risk_type, 1) | N/A | N/A |
| └─IndexFullScan_24 | 7808808.00 | 7808808 | cop[tikv] | table:customer_risk, index:idx_aes_risk_value_risk_type_risk_item(aes_risk_value, risk_type, risk_item) | tikv_task:{proc max:694ms, min:0s, avg: 30.2ms, p80:48ms, p95:86ms, iters:9483, tasks:461} | keep order:false | N/A | N/A |
+----------------------------------------------+------------+---------+-----------+---------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+---------+
15 rows in set (1.72 sec)
related_id_collection子句的执行计划
+----------------------------------------+---------+-----------+----------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------------------+---------+-----------+----------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| HashAgg_12 | 11.07 | root | | group by:abc.client_info_new.aes_mobile, funcs:firstrow(abc.client_info_new.aes_mobile)->abc.client_info_new.aes_mobile |
| └─IndexHashJoin_22 | 11.07 | root | | inner join, inner:IndexLookUp_19, outer key:abc.activity_join.related_id, inner key:abc.client_info_new.related_id, equal cond:eq(abc.activity_join.related_id, abc.client_info_new.related_id) |
| ├─HashAgg_50(Build) | 1.00 | root | | group by:abc.activity_join.related_id, funcs:firstrow(abc.activity_join.related_id)->abc.activity_join.related_id |
| │ └─IndexLookUp_73 | 1.08 | root | | |
| │ ├─IndexRangeScan_70(Build) | 1.08 | cop[tikv] | table:activity_join, index:idx_account_active_rule(activity_id, join_role, account_id) | range:[1 "MGM_BE_INVITED" 231210010003249607,1 "MGM_BE_INVITED" 231210010003249607], keep order:false |
| │ └─Selection_72(Probe) | 1.08 | cop[tikv] | | not(isnull(abc.activity_join.related_id)) |
| │ └─TableRowIDScan_71 | 1.08 | cop[tikv] | table:activity_join | keep order:false |
| └─IndexLookUp_19(Probe) | 11.07 | root | | |
| ├─IndexRangeScan_17(Build) | 11.07 | cop[tikv] | table:client_info_new, index:related_id(related_id) | range: decided by [eq(abc.client_info_new.related_id, abc.activity_join.related_id)], keep order:false |
| └─TableRowIDScan_18(Probe) | 11.07 | cop[tikv] | table:client_info_new | keep order:false |
+----------------------------------------+---------+-----------+----------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.00 sec)
语句2中的related_id_collection查询结果就是语句1中的in值,为啥执行效率相差这么多,如何优化?