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

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

Closed
qw4990 opened this issue Mar 12, 2023 · 1 comment · Fixed by #42194
Closed

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

qw4990 opened this issue Mar 12, 2023 · 1 comment · Fixed by #42194
Assignees
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 epic/plan-cache needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Mar 12, 2023

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)
@qw4990 qw4990 added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner epic/plan-cache labels Mar 12, 2023
@qw4990
Copy link
Contributor Author

qw4990 commented Mar 12, 2023

I'll improve this soon.

@qw4990 qw4990 added needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. labels Mar 14, 2023
@qw4990 qw4990 added type/bug The issue is confirmed as a bug. severity/major labels Mar 14, 2023
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Mar 14, 2023
@qw4990 qw4990 removed type/enhancement The issue or PR belongs to an enhancement. may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.1 may-affects-6.5 labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 epic/plan-cache needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants