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
SELECT * FROM (VALUES (1)) AS t(x)
WHERE x BETWEEN -9223372036854775808 AND 9223372036854775807;
Actual behavior
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.
Describe the bug
Optimizer interval analysis panics when a
BETWEENpredicate spans thefull
i64range.Interval::cardinalityfinishes with.map(|result| result + 1)and the+ 1overflows when the inner rangealready equals
u64::MAX.To Reproduce
Actual behavior
Call path:
Interval::cardinality::{{closure}}→cardinality_ratio→
calculate_selectivity→shrink_boundaries→analyze.Expected behavior
Cardinality should saturate (e.g.
u64::MAX) or returnNone, 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.