-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
affects-5.4This bug affects the 5.4.x(LTS) versions.This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.epic/plan-cacheneeds-cherry-pick-release-5.4Should cherry pick this PR to release-5.4 branch.Should cherry pick this PR to release-5.4 branch.needs-cherry-pick-release-6.1Should cherry pick this PR to release-6.1 branch.Should cherry pick this PR to release-6.1 branch.needs-cherry-pick-release-6.5Should cherry pick this PR to release-6.5 branch.Should cherry pick this PR to release-6.5 branch.severity/majorsig/plannerSIG: PlannerSIG: Plannertype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.
Description
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
Labels
affects-5.4This bug affects the 5.4.x(LTS) versions.This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.epic/plan-cacheneeds-cherry-pick-release-5.4Should cherry pick this PR to release-5.4 branch.Should cherry pick this PR to release-5.4 branch.needs-cherry-pick-release-6.1Should cherry pick this PR to release-6.1 branch.Should cherry pick this PR to release-6.1 branch.needs-cherry-pick-release-6.5Should cherry pick this PR to release-6.5 branch.Should cherry pick this PR to release-6.5 branch.severity/majorsig/plannerSIG: PlannerSIG: Plannertype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.