Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index lookup query scan index may sent redundancy rpc when enable paging #53827

Closed
crazycs520 opened this issue Jun 5, 2024 · 0 comments · Fixed by #53828
Closed

index lookup query scan index may sent redundancy rpc when enable paging #53827

crazycs520 opened this issue Jun 5, 2024 · 0 comments · Fixed by #53828
Assignees
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@crazycs520
Copy link
Contributor

crazycs520 commented Jun 5, 2024

1. Minimal reproduce step (Required)

drop table if exists t;
create table t (id int key auto_increment, b int, c int, index idx (b));
insert into t () values (), (), (), (), (), (), (), ();
insert into t (b) select b from t;
insert into t (b) select b from t;
insert into t (b) select b from t;
insert into t (b) select b from t;
insert into t (b) select b from t;
insert into t (b) select b from t;
insert into t (b) select b from t;
update t set b = id, c = id;

-- set following variables to default value. 
set @@tidb_enable_paging=1;
set @@tidb_min_paging_size=128;
set @@tidb_max_chunk_size=1024;

explain analyze select * from t use index(idx);

2. What did you see instead (Required)

The IndexFullScan_4 executor sends 3 cop RPC to scan index, but actually, 1 RPC is enough, because IndexLookUp_6 only has 1 table_task, which means IndexLookUp_6 neet to fetch initBatchSize which value will be 1024(from tidb_max_chunk_size=1024) index, then build a table task to execution. Enable paging is used to save memory, but in this case, enable paging with default tidb_min_paging_size is not a good idea, it will introduce redundancy RPC.

> explain analyze select * from t use index(idx) where b>0 and b < 1024;
+---------------------------+---------+---------+-----------+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+---------+------+
| id                        | estRows | actRows | task      | access object         | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | operator info    | memory  | disk |
+---------------------------+---------+---------+-----------+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+---------+------+
| IndexLookUp_6             | 1024.00 | 1024    | root      |                       | time:5.93ms, loops:2, RU:3.923506, index_task: {total_time: 4.33ms, fetch_handle: 4.32ms, build: 1.04µs, wait: 10.7µs}, table_task: {total_time: 1.37ms, num: 1, concurrency: 5}, next: {wait_index: 4.5ms, wait_table_lookup_build: 123µs, wait_table_lookup_resp: 1.24ms}                                                                                                                                                                                                                                          |                  | 68.1 KB | N/A  |
| ├─IndexFullScan_4(Build)  | 1024.00 | 1024    | cop[tikv] | table:t, index:idx(b) | time:4.3ms, loops:2, cop_task: {num: 3, max: 2.61ms, min: 687.5µs, avg: 1.39ms, p95: 2.61ms, max_proc_keys: 480, p95_proc_keys: 480, tot_proc: 1.19ms, tot_wait: 208µs, copr_cache_hit_ratio: 0.00, build_task_duration: 53.2µs, max_distsql_concurrency: 1}, rpc_info:{Cop:{num_rpc:3, total_time:4.08ms}}, tikv_task:{proc max:0s, min:0s, avg: 0s, p80:0s, p95:0s, iters:11, tasks:3}, scan_detail: {total_process_keys: 1024, total_process_keys_size: 47104, total_keys: 3075, get_snapshot_time: 77.2µs, ro... | keep order:false | N/A     | N/A  |
| └─TableRowIDScan_5(Probe) | 1024.00 | 1024    | cop[tikv] | table:t               | time:1.21ms, loops:2, cop_task: {num: 1, max: 1.14ms, proc_keys: 1024, tot_proc: 716.8µs, tot_wait: 32µs, copr_cache_hit_ratio: 0.00, build_task_duration: 36.5µs, max_distsql_concurrency: 1}, rpc_info:{Cop:{num_rpc:1, total_time:1.13ms}}, tikv_task:{time:0s, loops:6}, scan_detail: {total_process_keys: 1024, total_process_keys_size: 43778, total_keys: 2049, get_snapshot_time: 11.5µs, rocksdb: {delete_skipped_count: 1024, key_skipped_count: 3072, block: {cache_hit_count: 2}}}, time_detail: {tot... | keep order:false | N/A     | N/A  |
+---------------------------+---------+---------+-----------+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+---------+------+
IndexFullScan_4(Build)  | 1024.00 |   ... rpc_info:{Cop:{num_rpc:3, ...

3. What did you expect to see?

IndexFullScan_4 only send 1 RPC.

IndexFullScan_4(Build)  | 1024.00 |   ... rpc_info:{Cop:{num_rpc:1, ...

4. What is your TiDB version? (Required)

nightly: a6e1a2e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
1 participant