[GitHub] [spark] viirya commented on a diff in pull request #40446: [SPARK-42815][SQL] Subexpression elimination support shortcut expression

2023-03-15 Thread via GitHub


viirya commented on code in PR #40446:
URL: https://github.com/apache/spark/pull/40446#discussion_r1138097640


##
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala:
##
@@ -128,10 +131,23 @@ class EquivalentExpressions {
   // There are some special expressions that we should not recurse into all of 
its children.
   //   1. CodegenFallback: it's children will not be used to generate code 
(call eval() instead)
   //   2. ConditionalExpression: use its children that will always be 
evaluated.
-  private def childrenToRecurse(expr: Expression): Seq[Expression] = expr 
match {
-case _: CodegenFallback => Nil
-case c: ConditionalExpression => c.alwaysEvaluatedInputs
-case other => other.children
+  private def childrenToRecurse(expr: Expression): Seq[Expression] = {
+val alwaysEvaluated = expr match {
+  case _: CodegenFallback => Nil
+  case c: ConditionalExpression => c.alwaysEvaluatedInputs
+  case other => other.children
+}
+if (shortcut) {
+  // The subexpression may not need to eval even if it appears more than 
once.
+  // e.g., `if(or(a, and(b, b)))`, the expression `b` would be skipped if 
`a` is true.
+  alwaysEvaluated.map {
+case and: And => and.left
+case or: Or => or.left
+case other => other
+  }

Review Comment:
   Hmm, if other expression (e.g. `or.right`) is not added into recursing list, 
how can we look into if it needs to be eliminated? If `or.left` is false, it 
will be evaluated, isn't?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



[GitHub] [spark] viirya commented on a diff in pull request #40446: [SPARK-42815][SQL] Subexpression elimination support shortcut expression

2023-03-15 Thread via GitHub


viirya commented on code in PR #40446:
URL: https://github.com/apache/spark/pull/40446#discussion_r1138095296


##
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##
@@ -864,6 +864,14 @@ object SQLConf {
   .checkValue(_ >= 0, "The maximum must not be negative")
   .createWithDefault(100)
 
+  val SUBEXPRESSION_ELIMINATION_SKIP_FOR_SHORTCUT_EXPR =
+buildConf("spark.sql.subexpressionElimination.skipForShortcutExpr")
+  .internal()
+  .doc("When true, shortcut eliminate subexpression with `AND`, `OR`.")

Review Comment:
   The description is very unclear. Can you add some more?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]