planner: extract common leading predicates in DNF and push them to IndexScan to filter out unnecessary data earlier
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
See the example below, we can only deal with predicates about `c` on the table side now, since these predicates are in a DNF with some other columns that are not in the index:
```
create table t (a int, b int, c int, d int, key abc(a, b, c));
explain select * from t where a>1 and a<10 and b=1 and (c=1 or (c=2 and d=3));
+----------------------------+---------+-----------+-----------------------------+------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------+---------+-----------+-----------------------------+------------------------------------------------------------+
| IndexLookUp_13 | 1.00 | root | | |
| ├─Selection_11(Build) | 1.00 | cop[tikv] | | eq(test.t.b, 1) |
| │ └─IndexRangeScan_9 | 250.00 | cop[tikv] | table:t, index:abc(a, b, c) | range:(1,10), keep order:false, stats:pseudo |
| └─Selection_12(Probe) | 1.00 | cop[tikv] | | or(eq(test.t.c, 1), and(eq(test.t.c, 2), eq(test.t.d, 3))) |
| └─TableRowIDScan_10 | 1.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+----------------------------+---------+-----------+-----------------------------+------------------------------------------------------------+
```
Actually, we could extract some common leading predicates from that DNF, for example `c=1 or c=2` and then push it into `IndexScan` to filter our some unnecessary data earlier:
Contributor guide
Assessment
This issue has not been assessed yet.