Skip to content

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

Closed
@xuyifangreeneyes

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

affects-5.1This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.affects-5.3This bug affects 5.3.x versions.affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.severity/majorsig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions