morristai commented on PR #26634:
URL: https://github.com/apache/datafusion/pull/26634#issuecomment-6913294259

   @alamb There's something I'm unsure about, and I'd like to ask for your 
opinion.
   
   Currently, I let `BinaryExpr`'s `AND` and `OR` also return `short_circuits() 
== true`, consistent with `Expr::short_circuits`. However, I found they are 
different from `CASE` (it is not a per-row guarantee). `BinaryExpr` skips the 
right side only when no row needs it, or when at most 20% of the rows need it 
(`PRE_SELECTION_THRESHOLD`). Otherwise it evaluates the right side for every 
row.
   
   For example, `SELECT * FROM t WHERE v <= 100 OR CAST(s AS INT) >= 1` has no 
join. Every row where `s` is not a number has `v <= 100`, so the left side is 
true for those rows. It runs when 17% of the rows have a false left side; when 
33% do, `CAST` runs on all rows and fails.
   
   Therefore, there are 2 options I can think of right now:
   
   1. (current approach) Treat `AND`/`OR` as short-circuit. This rule won't 
cause queries that would normally run to fail, but the expressions under `OR` 
will no longer be pushed down.
   2. Just don't count them. The rule is simpler, and expressions under `OR` 
are still pushed down like on `main`. (But then the `OR` and nested `AND` 
examples in the issue are not bugs.)
   
   Which one do you think is better?


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