-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19309][SQL] disable common subexpression elimination for conditional expressions #16659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,21 +74,26 @@ class EquivalentExpressions { | |
| // loop. So we can't evaluate sub-expressions containing `LambdaVariable` at the beginning. | ||
| expr.find(_.isInstanceOf[LambdaVariable]).isDefined | ||
|
|
||
| // There are some special expressions that we should not recurse into children. | ||
| // 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. conditional expressions: common subexpressions will always be evaluated at the | ||
| // beginning, so we should not recurse into condition expressions, | ||
| // whole children may not get accessed according to the condition. | ||
| val shouldRecurse = expr match { | ||
| case _: CodegenFallback => false | ||
| case _: If => false | ||
| case _: CaseWhenBase => false | ||
| case _: Coalesce => false | ||
| case _ => true | ||
| // 2. If: common subexpressions will always be evaluated at the beginning, but the true and | ||
| // false expressions in `If` may not get accessed, according to the predicate | ||
| // expression. We should only recurse into the predicate expression. | ||
| // 3. CaseWhen: like `If`, the children of `CaseWhen` only get accessed in a certain | ||
| // condition. We should only recurse into the first condition expression as it | ||
| // will always get accessed. | ||
| // 4. Coalesce: it's also a conditional expression, we should only recurse into the first | ||
| // children, because others may not get accessed. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although Could you update the comments?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| def childrenToRecurse: Seq[Expression] = expr match { | ||
| case _: CodegenFallback => Nil | ||
| case i: If => i.predicate :: Nil | ||
| case c: CaseWhenBase => c.children.head :: Nil | ||
|
||
| case c: Coalesce => c.children.head :: Nil | ||
| case other => other.children | ||
| } | ||
|
|
||
| if (!skip && !addExpr(expr) && shouldRecurse) { | ||
| expr.children.foreach(addExprTree) | ||
| if (!skip && !addExpr(expr)) { | ||
| childrenToRecurse.foreach(addExprTree) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CaseWhencould be very deep.Compared with the previous impl, will we miss some expression elimination chances?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm,
CaseWhenimplementsCodegenFallback. Thus, the previous impl skips it.