Skip to content

planner: cannot use BatchPointGet if Plan Cache is enabled in some cases #42125

@qw4990

Description

@qw4990

Enhancement

As the case below, if we enable Plan Cache, the query cannot use BatchPointGet for safety, but BatchPointGet is much more efficient than IndexLookup in this case:

mysql> create table t (a int, b int, c int, unique key(a, b));
Query OK, 0 rows affected (0.02 sec)

mysql> explain select * from t where a=1 and b in (1, 2);
+-------------------+---------+------+------------------------+------------------------------+
| id                | estRows | task | access object          | operator info                |
+-------------------+---------+------+------------------------+------------------------------+
| Batch_Point_Get_5 | 2.00    | root | table:t, index:a(a, b) | keep order:false, desc:false |
+-------------------+---------+------+------------------------+------------------------------+
1 row in set (0.01 sec)

mysql> prepare st from 'select * from t where a=1 and b in (?, ?)';
Query OK, 0 rows affected (0.00 sec)

mysql> set @a=1, @b=2;
Query OK, 0 rows affected (0.00 sec)

mysql> execute st using @a, @b;
Empty set (0.01 sec)

mysql> explain for connection 2199023255955;
+-------------------------------+---------+---------+-----------+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+--------+------+
| id                            | estRows | actRows | task      | access object          | execution info                                                                                                                                                                                                           | operator info                                              | memory | disk |
+-------------------------------+---------+---------+-----------+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+--------+------+
| IndexLookUp_7                 | 2.00    | 0       | root      |                        | time:3.39ms, loops:1                                                                                                                                                                                                     |                                                            | N/A    | N/A  |
| ├─IndexRangeScan_5(Build)     | 2.00    | 0       | cop[tikv] | table:t, index:a(a, b) | time:3.2ms, loops:1, cop_task: {num: 1, max: 222µs, proc_keys: 0, rpc_num: 2, rpc_time: 258.3µs, copr_cache_hit_ratio: 0.00, build_task_duration: 27µs, max_distsql_concurrency: 1}, tikv_task:{time:186µs, loops:0}     | range:[1 1,1 1], [1 2,1 2], keep order:false, stats:pseudo | N/A    | N/A  |
| └─TableRowIDScan_6(Probe)     | 2.00    | 0       | cop[tikv] | table:t                |                                                                                                                                                                                                                          | keep order:false, stats:pseudo                             | N/A    | N/A  |
+-------------------------------+---------+---------+-----------+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+--------+------+
3 rows in set (0.00 sec)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions