jackkleeman commented on code in PR #17743:
URL: https://github.com/apache/datafusion/pull/17743#discussion_r2373022716


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1471,6 +1508,56 @@ impl<S: SimplifyInfo> TreeNodeRewriter for 
Simplifier<'_, S> {
                 // Do a first pass at simplification
                 out_expr.rewrite(self)?
             }
+            // CASE
+            //   WHEN X THEN true
+            //   WHEN Y THEN true
+            //   WHEN Z THEN false
+            //   ...
+            //   ELSE true
+            // END
+            //
+            // --->
+            //
+            // NOT(CASE
+            //   WHEN X THEN false
+            //   WHEN Y THEN false
+            //   WHEN Z THEN true
+            //   ...
+            //   ELSE false
+            // END)
+            //
+            // Note: the rationale for this rewrite is that the case can then 
be further

Review Comment:
   lets say we have:
   ```
   CASE
     WHEN col_1 THEN true
     WHEN col_2 THEN false
   ...
     WHEN col_99 THEN true
     ELSE true
   END
   ```
   none of the WHEN can be trimmed, so I am not sure those open prs will help. 
the naive disaggregation, if we removed the <3 limit will look like:
   ```
   col1 OR (not col_1 and col_2) or (not col_1 and not col_2 and col_3)... 
   ```
   which is a very long expression indeed (O(n^2) in the number of true 
branches). instead, if we invert, we can write an expression like this:
   ```
   not(not col_2)
   ```
   which is O(n^2) in the number of false branches (a much smaller number)
   



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

Reply via email to