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

Cannot build optimal range on index ab for c = 10 and (a = 'xx' or (a = 'kk' and b = 1)) #44389

Closed
xuyifangreeneyes opened this issue Jun 4, 2023 · 0 comments · Fixed by #44384
Assignees
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@xuyifangreeneyes
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t(id int, a varchar(100), b int, c int, index idx_ab(a, b));
explain select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1));

2. What did you expect to see? (Required)

mysql> explain select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1));
+-------------------------------+---------+-----------+-----------------------------+--------------------------------------------------------------------+
| id                            | estRows | task      | access object               | operator info                                                      |
+-------------------------------+---------+-----------+-----------------------------+--------------------------------------------------------------------+
| IndexLookUp_11                | 0.01    | root      |                             |                                                                    |
| ├─IndexRangeScan_8(Build)     | 10.10   | cop[tikv] | table:t, index:idx_ab(a, b) | range:["kk" 1,"kk" 1], ["xx","xx"], keep order:false, stats:pseudo |
| └─Selection_10(Probe)         | 0.01    | cop[tikv] |                             | eq(test.t.c, 10)                                                   |
|   └─TableRowIDScan_9          | 10.10   | cop[tikv] | table:t                     | keep order:false, stats:pseudo                                     |
+-------------------------------+---------+-----------+-----------------------------+--------------------------------------------------------------------+
4 rows in set (0.01 sec)

3. What did you see instead (Required)

mysql> explain select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1));
+----------------------------+---------+-----------+-----------------------------+------------------------------------------------------------------+
| id                         | estRows | task      | access object               | operator info                                                    |
+----------------------------+---------+-----------+-----------------------------+------------------------------------------------------------------+
| IndexLookUp_12             | 0.01    | root      |                             |                                                                  |
| ├─Selection_10(Build)      | 0.02    | cop[tikv] |                             | or(eq(test.t.a, "xx"), and(eq(test.t.a, "kk"), eq(test.t.b, 1))) |
| │ └─IndexRangeScan_8       | 20.00   | cop[tikv] | table:t, index:idx_ab(a, b) | range:["kk","kk"], ["xx","xx"], keep order:false, stats:pseudo   |
| └─Selection_11(Probe)      | 0.01    | cop[tikv] |                             | eq(test.t.c, 10)                                                 |
|   └─TableRowIDScan_9       | 0.02    | cop[tikv] | table:t                     | keep order:false, stats:pseudo                                   |
+----------------------------+---------+-----------+-----------------------------+------------------------------------------------------------------+
5 rows in set (0.01 sec)

4. What is your TiDB version? (Required)

master

@xuyifangreeneyes xuyifangreeneyes added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner severity/major labels Jun 4, 2023
@ti-chi-bot ti-chi-bot bot added 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 may-affects-7.1 labels Jun 4, 2023
@xuyifangreeneyes xuyifangreeneyes added affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 labels Jun 4, 2023
@ti-chi-bot ti-chi-bot bot removed may-affects-5.1 This bug maybe affects 5.1.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.2 This bug maybe affects 5.2.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 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.

1 participant