jackkleeman commented on code in PR #17743:
URL: https://github.com/apache/datafusion/pull/17743#discussion_r2373030753
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1447,7 +1480,11 @@ impl<S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'_, S> {
when_then_expr,
else_expr,
}) if !when_then_expr.is_empty()
- && when_then_expr.len() < 3 // The rewrite is O(n²) so limit
to small number
+ // The rewrite is O(n²) in general so limit to small number of
when-thens that can be true
+ && (when_then_expr.len() < 3 // small number of input whens
+ // or all thens are literal bools and a small number of
them are true
Review Comment:
i think the comment about it being O(n^2) is very legit, and this is also
true in the literal bool case; the *thens* are literal bools but we dont know
anything about the *whens* and whether they might be reducible. Indeed, in my
target use case, the thens are not reducible at all and we definitely end up
with On^2 boolean expressions. The intent of this check is to maintain the '<3
when then' limitation, but just be cleverer about how we count when thens,
ignoring those where the then is a literal false
We could, if we wanted, split this out into a separate rewrite that removes
when_thens that have false thens. However, this is not as trivial as the
when=false trim PR, and I actually think it could lead to longer case
statements - you would have to fold in the when of the trimmed branch into all
the following whens, as they would not have matched if the trimmed when had
matched. Else is also complex in this case.
--
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]