Skip to content

Commit c78166d

Browse files
committed
Remove redundant conditions while combining filters
1 parent 2ef4c59 commit c78166d

File tree

1 file changed

+7
-4
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer

1 file changed

+7
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,15 @@ object CombineUnions extends Rule[LogicalPlan] {
819819
}
820820

821821
/**
822-
* Combines two adjacent [[Filter]] operators into one, merging the
823-
* conditions into one conjunctive predicate.
822+
* Combines two adjacent [[Filter]] operators into one, merging the non-redundant conditions into
823+
* one conjunctive predicate.
824824
*/
825-
object CombineFilters extends Rule[LogicalPlan] {
825+
object CombineFilters extends Rule[LogicalPlan] with PredicateHelper {
826826
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
827-
case ff @ Filter(fc, nf @ Filter(nc, grandChild)) => Filter(And(nc, fc), grandChild)
827+
case ff @ Filter(fc, nf @ Filter(nc, grandChild)) =>
828+
val ac = (ExpressionSet(splitConjunctivePredicates(nc)) --
829+
ExpressionSet(splitConjunctivePredicates(fc))).reduce(And)
830+
Filter(And(ac, fc), grandChild)
828831
}
829832
}
830833

0 commit comments

Comments
 (0)