Skip to content

optimizer cannot handle cases like ((a = 1 and b = 2 and c > 3) or (a = 4 and b = 5 and c > 6)) and d > 3 #41598

@xuyifangreeneyes

Description

@xuyifangreeneyes

Enhancement

mysql> create table t1(a int, b int, c int, d int, index idx(a, b, c));
Query OK, 0 rows affected (0.06 sec)

mysql> explain select * from t1 where (a = 1 and b = 2 and c > 3) or (a = 4 and b = 5 and c > 6)
    -> ;
+-------------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------------+
| id                            | estRows | task      | access object                | operator info                                                            |
+-------------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------------+
| IndexLookUp_10                | 0.67    | root      |                              |                                                                          |
| ├─IndexRangeScan_8(Build)     | 0.67    | cop[tikv] | table:t1, index:idx(a, b, c) | range:(1 2 3,1 2 +inf], (4 5 6,4 5 +inf], keep order:false, stats:pseudo |
| └─TableRowIDScan_9(Probe)     | 0.67    | cop[tikv] | table:t1                     | keep order:false, stats:pseudo                                           |
+-------------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------------+
3 rows in set (0.00 sec)

mysql> explain select * from t1 where ((a = 1 and b = 2 and c > 3) or (a = 4 and b = 5 and c > 6)) and d > 3;
+----------------------------+---------+-----------+------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
| id                         | estRows | task      | access object                | operator info                                                                                                                      |
+----------------------------+---------+-----------+------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
| IndexLookUp_12             | 0.22    | root      |                              |                                                                                                                                    |
| ├─Selection_10(Build)      | 0.22    | cop[tikv] |                              | or(and(eq(test.t1.a, 1), and(eq(test.t1.b, 2), gt(test.t1.c, 3))), and(eq(test.t1.a, 4), and(eq(test.t1.b, 5), gt(test.t1.c, 6)))) |
| │ └─IndexRangeScan_8       | 20.00   | cop[tikv] | table:t1, index:idx(a, b, c) | range:[1,1], [4,4], keep order:false, stats:pseudo                                                                                 |
| └─Selection_11(Probe)      | 0.22    | cop[tikv] |                              | gt(test.t1.d, 3)                                                                                                                   |
|   └─TableRowIDScan_9       | 0.22    | cop[tikv] | table:t1                     | keep order:false, stats:pseudo                                                                                                     |
+----------------------------+---------+-----------+------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
5 rows in set (0.00 sec)

The second query can also build (1 2 3,1 2 +inf], (4 5 6,4 5 +inf] but currently we only build [1,1], [4,4].

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions