You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/12/26 12:21:50 UTC

[GitHub] [spark] maropu commented on a change in pull request #27008: [SPARK-30353][SQL] Use constraints in SimplifyBinaryComparison optimization

maropu commented on a change in pull request #27008: [SPARK-30353][SQL] Use constraints in SimplifyBinaryComparison optimization
URL: https://github.com/apache/spark/pull/27008#discussion_r361444515
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
 ##########
 @@ -384,22 +384,40 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper {
 /**
  * Simplifies binary comparisons with semantically-equal expressions:
  * 1) Replace '<=>' with 'true' literal.
- * 2) Replace '=', '<=', and '>=' with 'true' literal if both operands are non-nullable.
- * 3) Replace '<' and '>' with 'false' literal if both operands are non-nullable.
+ * 2) Replace '=', '<=', and '>=' with 'true' literal
+ *    if both operands are non-nullable or in constraints.
+ * 3) Replace '<' and '>' with 'false' literal if both operands are non-nullable or in constraints.
  */
-object SimplifyBinaryComparison extends Rule[LogicalPlan] with PredicateHelper {
+object SimplifyBinaryComparison
+  extends Rule[LogicalPlan] with PredicateHelper with ConstraintHelper {
+
+  private def canSimplifyWithConstraints(
+      plan: LogicalPlan, left: Expression, right: Expression): Boolean = {
+    def canSimplify(left: Expression, right: Expression): Boolean = {
+      !left.nullable && !right.nullable && left.semanticEquals(right)
+    }
+
+    if (SQLConf.get.constraintPropagationEnabled) {
+      canSimplify(left, right) || plan.constraints.exists {
 
 Review comment:
   Can we limit this constrain check only in `Filter` plans?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org