Skip to content

Commit 81781ff

Browse files
committed
Safeguard against potential inexact row count being smaller than exact null count
1 parent 8a4bad4 commit 81781ff

File tree

1 file changed

+6
-1
lines changed
  • datafusion/physical-plan/src/joins

1 file changed

+6
-1
lines changed

datafusion/physical-plan/src/joins/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,12 @@ fn max_distinct_count(
955955
let result = match num_rows {
956956
Precision::Absent => Precision::Absent,
957957
Precision::Inexact(count) => {
958-
Precision::Inexact(count - stats.null_count.get_value().unwrap_or(&0))
958+
// To safeguard against inexact number of rows (e.g. 0) being smaller than
959+
// an exact null count we need to do a checked subtraction.
960+
match count.checked_sub(*stats.null_count.get_value().unwrap_or(&0)) {
961+
None => Precision::Inexact(0),
962+
Some(non_null_count) => Precision::Inexact(non_null_count),
963+
}
959964
}
960965
Precision::Exact(count) => {
961966
let count = count - stats.null_count.get_value().unwrap_or(&0);

0 commit comments

Comments
 (0)