diff --git a/src/query/service/src/sql/planner/optimizer/heuristic/decorrelate.rs b/src/query/service/src/sql/planner/optimizer/heuristic/decorrelate.rs index 9174ff0e356f..1a196cadc853 100644 --- a/src/query/service/src/sql/planner/optimizer/heuristic/decorrelate.rs +++ b/src/query/service/src/sql/planner/optimizer/heuristic/decorrelate.rs @@ -821,28 +821,22 @@ impl SubqueryRewriter { }) = predicate { if op == &ComparisonOp::Equal { - if let Scalar::BoundColumnRef(BoundColumnRef { - column: left_column, - }) = &**left + if let (Scalar::BoundColumnRef(left), Scalar::BoundColumnRef(right)) = + (&**left, &**right) { - if let Scalar::BoundColumnRef(BoundColumnRef { - column: right_column, - }) = &**right + if correlated_columns.contains(&left.column.index) + && !correlated_columns.contains(&right.column.index) { - if correlated_columns.contains(&left_column.index) - && !correlated_columns.contains(&right_column.index) - { - self.derived_columns - .insert(left_column.index, right_column.index); - } - if !correlated_columns.contains(&left_column.index) - && correlated_columns.contains(&right_column.index) - { - self.derived_columns - .insert(right_column.index, left_column.index); - } - return true; + self.derived_columns + .insert(left.column.index, right.column.index); } + if !correlated_columns.contains(&left.column.index) + && correlated_columns.contains(&right.column.index) + { + self.derived_columns + .insert(right.column.index, left.column.index); + } + return true; } } } diff --git a/src/query/service/src/sql/planner/optimizer/rule/rewrite/rule_eliminate_filter.rs b/src/query/service/src/sql/planner/optimizer/rule/rewrite/rule_eliminate_filter.rs index c35c5b92a0d9..01c2e44c51ec 100644 --- a/src/query/service/src/sql/planner/optimizer/rule/rewrite/rule_eliminate_filter.rs +++ b/src/query/service/src/sql/planner/optimizer/rule/rewrite/rule_eliminate_filter.rs @@ -30,7 +30,7 @@ pub struct RuleEliminateFilter { impl RuleEliminateFilter { pub fn new() -> Self { Self { - id: RuleID::EliminateEvalScalar, + id: RuleID::EliminateFilter, // Filter // \ // *