-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
sig/plannerSIG: PlannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.The issue or PR belongs to an enhancement.
Description
Enhancement
Though users don't deliberately write redundant expressions in the SQL, there are still redundant expressions, such as those from generated SQLs.
In our current implementation, we have RemoveDupExprs()
and PropagateConstant()
for AND lists. However, the correspondence for the OR list is lacking. So, there could be redundant filters in the OR list in the final plan, which can sometimes cause an inefficient plan.
For example:
create table t(a int, b int, c int, index ia(a), index ib(b), index ic(c));
explain select * from t where a = 1 or a = 1 or b = 2 or b = 2 or c = 3 or c = 3;
> explain select * from t where a = 1 or a = 1 or b = 2 or b = 2 or c = 3 or c = 3;
+--------------------------------+---------+-----------+----------------------+---------------------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------------+---------+-----------+----------------------+---------------------------------------------+
| IndexMerge_15 | 29.97 | root | | type: union |
| ├─IndexRangeScan_8(Build) | 10.00 | cop[tikv] | table:t, index:ia(a) | range:[1,1], keep order:false, stats:pseudo |
| ├─IndexRangeScan_9(Build) | 10.00 | cop[tikv] | table:t, index:ia(a) | range:[1,1], keep order:false, stats:pseudo |
| ├─IndexRangeScan_10(Build) | 10.00 | cop[tikv] | table:t, index:ib(b) | range:[2,2], keep order:false, stats:pseudo |
| ├─IndexRangeScan_11(Build) | 10.00 | cop[tikv] | table:t, index:ib(b) | range:[2,2], keep order:false, stats:pseudo |
| ├─IndexRangeScan_12(Build) | 10.00 | cop[tikv] | table:t, index:ic(c) | range:[3,3], keep order:false, stats:pseudo |
| ├─IndexRangeScan_13(Build) | 10.00 | cop[tikv] | table:t, index:ic(c) | range:[3,3], keep order:false, stats:pseudo |
| └─TableRowIDScan_14(Probe) | 29.97 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+--------------------------------+---------+-----------+----------------------+---------------------------------------------+
Metadata
Metadata
Assignees
Labels
sig/plannerSIG: PlannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.The issue or PR belongs to an enhancement.