xudong963 opened a new issue, #23787: URL: https://github.com/apache/datafusion/issues/23787
## Describe the bug `estimate_inner_join_cardinality` multiplies two `usize` row counts before dividing by the join-key NDV. When the Cartesian-product intermediate exceeds `usize::MAX`, debug builds panic with `attempt to multiply with overflow`, even if applying the NDV divisor would produce a representable cardinality. In release builds, wrapping the intermediate can also yield an incorrect estimate. ## To Reproduce Estimate an inner join with these statistics: - Left row count: `usize::MAX / 2 + 1`, NDV: `1` - Right row count: `3`, NDV: `3` The calculation `(left_rows * right_rows) / 3` overflows during multiplication before normalization. ## Expected behavior Join cardinality estimation should not panic. It should preserve the accurate normalized value when it fits in `usize`, and produce a conservative inexact capped estimate when the final cardinality itself is not representable. ## Additional context Using a saturating `usize` multiplication before division avoids the panic but loses accuracy for representable normalized results, so the intermediate calculation needs wider arithmetic. -- 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]
