`copr_cache_hit_ratio` may not correct
- Dominant language
- Go
- Stars
- 40.6k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
1. deploy a cluster and enable copr-cache
2. execute the sql
```sql
drop table if exists t, t1;
create table t (a int, b int);
create table t1(a int, b int);
insert into t values (1, 1),(2, 2), (3, 3);
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
insert into t1 values (1, 1),(2, 2), (3, 3);
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
explain analyze select * from t;
explain analyze select * from t;
select * from t;
explain analyze select * from t;
```
### 2. What did you expect to see? (Required)
the `copr_cache_hit_ratio` value of the second and third `explain analyze select * from t` should be `1.00`
```sql
explain analyze select * from t;
+-------------------+----------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+-------------------+----------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
| TableReader_5 | 98304.00 | 98304 | root | | time:5.2ms, loops:98, cop_task: {num: 10, max: 1.17ms, min: 258.5µs, avg: 477µs, p95: 1.17ms, max_proc_keys: 992, p95_proc_keys: 992, rpc_num: 10, rpc_time: 4.68ms, copr_cache_hit_ratio: 1.00, distsql_concurrency: 15} | data:TableFullScan_4 | 937.8 KB | N/A |
| └─TableFullScan_4 | 98304.00 | 98304 | cop[tikv] | table:t | tikv_task:{proc max:17ms, min:0s, avg: 5.2ms, p80:12ms, p95:17ms, iters:135, tasks:10}, scan_detail: {total_process_keys: 1696, total_process_keys_size: 69536, total_keys: 1699, get_snapshot_time: 273.7µs, rocksdb: {key_skipped_count: 1696, block: {cache_hit_count: 6}}} | keep order:false, stats:pseudo | N/A | N/A |
+-------------------+----------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
```
### 3. What did you see instead (Required)
some times the `copr_cache_hit_ratio` value of the second and third `explain analyze select * from t` not `1.00`
```sql
TiDB root@127.0.0.1:test> explain analyze select * from t;
+-------------------+----------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+-------------------+----------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
| TableReader_5 | 98304.00 | 98304 | root | | time:5.2ms, loops:98, cop_task: {num: 10, max: 1.17ms, min: 258.5µs, avg: 477µs, p95: 1.17ms, max_proc_keys: 992, p95_proc_keys: 992, rpc_num: 10, rpc_time: 4.68ms, copr_cache_hit_ratio: 0.70, distsql_concurrency: 15} | data:TableFullScan_4 | 937.8 KB | N/A |
| └─TableFullScan_4 | 98304.00 | 98304 | cop[tikv] | table:t | tikv_task:{proc max:17ms, min:0s, avg: 5.2ms, p80:12ms, p95:17ms, iters:135, tasks:10}, scan_detail: {total_process_keys: 1696, total_process_keys_size: 69536, total_keys: 1699, get_snapshot_time: 273.7µs, rocksdb: {key_skipped_count: 1696, block: {cache_hit_count: 6}}} | keep order:false, stats:pseudo | N/A | N/A |
+-------------------+----------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
```
### 4. What is your TiDB version? (Required)
```sql
TiDB root@127.0.0.1:test> select tidb_version()\G
***************************[ 1. row ]***************************
tidb_version() | Release Version: v6.4.0-alpha
Edition: Community
Git Commit Hash: 556daf722ecb538b0b20aa800185f995e8543a4f
Git Branch: heads/refs/tags/v6.4.0-alpha
UTC Build Time: 2022-10-07 14:26:04
GoVersion: go1.19.1
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
```
Contributor guide
Assessment
This issue has not been assessed yet.