Avoid unnecessary RPC requests for point-get query
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
```sql
test> create table t1 (id int key, b int, c int, unique index(b));
Query OK, 0 rows affected
Time: 0.042s
test> insert into t1 values (1,1,1);
Query OK, 1 row affected
Time: 0.006s
test> explain analyze select id from t1 where b=1;
+-------------+---------+---------+------+----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+--------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+-------------+---------+---------+------+----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+--------+------+
| Point_Get_1 | 1.00 | 1 | root | table:t1, index:b(b) | time:3.73ms, open:2.54µs, close:9.71µs, loops:2, RU:1.29, Get:{num_rpc:2, total_time:3.53ms}, time_detail: {total_process_time: 1.01ms, total_wait_time: 559.6µs, total_kv_read_wall_time: 1.61ms, tikv_wall_time: 1.97ms}, scan_detail: {total_process_keys: 2, total_process_keys_size: 85, total_keys: 2, get_snapshot_time: 276.8µs, rocksdb: {block: {}}} | | N/A | N/A |
+-------------+---------+---------+------+----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+--------+------+
1 row in set
Time: 0.012s
test> show create table t1;
+-------+-------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------+
| t1 | CREATE TABLE `t1` ( |
| | `id` int NOT NULL, |
| | `b` int DEFAULT NULL, |
| | `c` int DEFAULT NULL, |
| | PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, |
| | UNIQUE KEY `b` (`b`) |
| | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+
1 row in set
Time: 0.005s
```
The query `select id from t1 where b=1` sends 2 rpc to fetch result, actually it only need to send 1 rpc, since the first rpc to read index key/value, it already contains the id value, since the column `id` is the `handle` of table `t1`, then no need to send the second rpc to read row key/value.
### Version
```sql
test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------+
| Release Version: v9.0.0-beta.1.pre-434-gddfd52a815 |
| Edition: Community |
| Git Commit Hash: ddfd52a8151b7562236441532848d57a4f4f1eb3 |
| Git Branch: HEAD |
| UTC Build Time: 2025-03-18 08:35:15 |
| GoVersion: go1.23.7 |
| Race Enabled: false |
| Check Table Before Drop: false |
| Store: tikv |
+-----------------------------------------------------------+
```
Contributor guide
Assessment
This issue has not been assessed yet.