Dandandan opened a new issue, #22232:
URL: https://github.com/apache/datafusion/issues/22232
### Describe the bug
Optimizer interval analysis panics when a `BETWEEN` predicate spans the
full `i64` range. `Interval::cardinality` finishes with
`.map(|result| result + 1)` and the `+ 1` overflows when the inner range
already equals `u64::MAX`.
### To Reproduce
```sql
SELECT * FROM (VALUES (1)) AS t(x)
WHERE x BETWEEN -9223372036854775808 AND 9223372036854775807;
```
### Actual behavior
```text
thread 'main' panicked at
datafusion/expr-common/src/interval_arithmetic.rs:968:23:
attempt to add with overflow
```
Call path: `Interval::cardinality::{{closure}}` → `cardinality_ratio`
→ `calculate_selectivity` → `shrink_boundaries` → `analyze`.
### Expected behavior
Cardinality should saturate (e.g. `u64::MAX`) or return `None`, not panic.
### Notes
Source:
https://github.com/apache/datafusion/blob/53.1.0/datafusion/expr-common/src/interval_arithmetic.rs#L968
Related but distinct from closed #16736 (float subtract overflow in the
same module).
Found via LLM-guided fuzz testing on DataFusion 53.1.0.
--
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]