慢查优化,不走索引

select * from user_risk where risk_value = (子查询) AND risk_item = 1 and risk_type = 1 and is_deleted = 0 and status = 1;

+-----------------------------+------------+---------+-----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+
| id                          | estRows    | actRows | task      | access object       | execution info                                                                                                                                                                                                                                                                                                                                               | operator info                                                                                                                                                        | memory  | disk    |
+-----------------------------+------------+---------+-----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+
| HashJoin_9                  | 2351569.96 | 1       | root      |                     | time:2.18s, loops:2, build_hash_table:{total:1.96ms, fetch:1.95ms, build:5.6µs}, probe:{concurrency:5, total:10.9s, max:2.18s, probe:438.6ms, fetch:10.5s}                                                                                                                                                                                                   | semi join, equal:[eq(user_risk.risk_value, user.mobile)]                                                                          | 25.7 KB | 0 Bytes |
| ├─Point_Get_21(Build)       | 1.00       | 1       | root      | table:user       | time:1.91ms, loops:2, Get:{num_rpc:1, total_time:1.87ms}, total_process_time: 1ms, tikv_wall_time: 1.68ms, scan_detail: {total_process_keys: 1, total_process_keys_size: 783, total_keys: 1, get_snapshot_time: 5.23µs, rocksdb: {block: {cache_hit_count: 12, read_count: 2, read_byte: 45.1 KB, read_time: 1.25ms}}}                                       | handle:210415010079291504                                                                                                                                            | N/A     | N/A     |
| └─TableReader_12(Probe)     | 2939462.44 | 2865758 | root      |                     | time:2.15s, loops:2819, cop_task: {num: 253, max: 1.23s, min: 1.47ms, avg: 91.9ms, p95: 301.2ms, max_proc_keys: 426539, p95_proc_keys: 109536, tot_proc: 21.4s, tot_wait: 385ms, rpc_num: 253, rpc_time: 23.3s, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}                                                                                         | data:Selection_11                                                                                                                                                    | 20.1 MB | N/A     |
|   └─Selection_11            | 2939462.44 | 2865758 | cop[tikv] |                     | tikv_task:{proc max:1.22s, min:0s, avg: 79.9ms, p80:129ms, p95:262ms, iters:9273, tasks:253}, scan_detail: {total_process_keys: 8450908, total_process_keys_size: 1666484336, total_keys: 8457484, get_snapshot_time: 129.5ms, rocksdb: {key_skipped_count: 8457547, block: {cache_hit_count: 2865, read_count: 27259, read_byte: 477.4 MB, read_time: 2s}}} | eq(user_risk.is_deleted, 0), eq(user_risk.risk_item, 1), eq(user_risk.risk_type, 1), eq(user_risk.status, 1) | N/A     | N/A     |
|     └─TableFullScan_10      | 8450909.00 | 8450908 | cop[tikv] | table:user_risk | tikv_task:{proc max:1.2s, min:0s, avg: 77.7ms, p80:126ms, p95:255ms, iters:9273, tasks:253}                                                                                                                                                                                                                                                                  | keep order:false                                                                                                                                                     | N/A     | N/A     |
+-----------------------------+------------+---------+-----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+
5 rows in set (2.19 sec)

select * from user_risk where risk_value = “xxx” AND risk_item = 1 and risk_type = 1 and is_deleted = 0 and status = 1;

+--------------------------------+---------+---------+-----------+---------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+---------+------+
| id                             | estRows | actRows | task      | access object                                                                                           | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                       | operator info                                                                           | memory  | disk |
+--------------------------------+---------+---------+-----------+---------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+---------+------+
| IndexLookUp_15                 | 1.06    | 1       | root      |                                                                                                         | time:5.1ms, loops:2, index_task: {total_time: 4.19ms, fetch_handle: 4.19ms, build: 592ns, wait: 675ns}, table_task: {total_time: 826.7µs, num: 1, concurrency: 5}, next: {wait_index: 4.32ms, wait_table_lookup_build: 0s, wait_table_lookup_resp: 759.1µs}                                                                                                                                                                                          |                                                                                         | 17.2 KB | N/A  |
| ├─IndexRangeScan_12(Build)     | 1.10    | 3       | cop[tikv] | table:user_risk, index:idx_risk_value(risk_item, risk_type, risk_value) | time:4.18ms, loops:3, cop_task: {num: 1, max: 1.05ms, proc_keys: 3, rpc_num: 2, rpc_time: 1.62ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, backoff{regionMiss: 2ms}, tikv_task:{time:1ms, loops:1}, scan_detail: {total_process_keys: 3, total_process_keys_size: 504, total_keys: 4, get_snapshot_time: 7.29µs, rocksdb: {key_skipped_count: 3, block: {cache_hit_count: 9, read_count: 1, read_byte: 27.9 KB, read_time: 449.5µs}}}   | range:[1 1 "xxx",1 1 "xxx"], keep order:false | N/A     | N/A  |
| └─Selection_14(Probe)          | 1.06    | 1       | cop[tikv] |                                                                                                         | time:741.8µs, loops:2, cop_task: {num: 1, max: 699.4µs, proc_keys: 3, rpc_num: 1, rpc_time: 684.7µs, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, tikv_task:{time:1ms, loops:1}, scan_detail: {total_process_keys: 3, total_process_keys_size: 540, total_keys: 3, get_snapshot_time: 7.2µs, rocksdb: {block: {cache_hit_count: 24, read_count: 2, read_byte: 41.2 KB, read_time: 21.4µs}}}                                                 | eq(user_risk.is_deleted, 0), eq(user_risk.status, 1)        | N/A     | N/A  |
|   └─TableRowIDScan_13          | 1.10    | 3       | cop[tikv] | table:user_risk                                                                                     | tikv_task:{time:1ms, loops:1}                                                                                                                                                                                                                                                                                                                                                                                                                        | keep order:false                                                                        | N/A     | N/A  |
+--------------------------------+---------+---------+-----------+---------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+---------+------+
4 rows in set (0.01 sec)