@@ -563,11 +563,14 @@ fn estimate_inner_join_cardinality(
563
563
. iter ( )
564
564
. zip ( right_stats. column_statistics . iter ( ) )
565
565
{
566
- // Break if any of statistics bounds are undefined
567
- if left_stat. min_value . get_value ( ) . is_none ( )
568
- || left_stat. max_value . get_value ( ) . is_none ( )
569
- || right_stat. min_value . get_value ( ) . is_none ( )
570
- || right_stat. max_value . get_value ( ) . is_none ( )
566
+ // Break if we don't have enough information to calculate a distinct count
567
+ // If distinct_count isn't provided directly, we need min and max to be provided
568
+ if ( left_stat. distinct_count . get_value ( ) . is_none ( )
569
+ && ( left_stat. min_value . get_value ( ) . is_none ( )
570
+ || left_stat. max_value . get_value ( ) . is_none ( ) ) )
571
+ || ( right_stat. distinct_count . get_value ( ) . is_none ( )
572
+ && ( right_stat. min_value . get_value ( ) . is_none ( )
573
+ || right_stat. max_value . get_value ( ) . is_none ( ) ) )
571
574
{
572
575
return None ;
573
576
}
@@ -2016,20 +2019,20 @@ mod tests {
2016
2019
) ,
2017
2020
// When we have distinct count.
2018
2021
(
2019
- ( 10 , Inexact ( 1 ) , Inexact ( 10 ) , Inexact ( 10 ) , Absent ) ,
2020
- ( 10 , Inexact ( 1 ) , Inexact ( 10 ) , Inexact ( 10 ) , Absent ) ,
2022
+ ( 10 , Absent , Absent , Inexact ( 10 ) , Absent ) ,
2023
+ ( 10 , Absent , Absent , Inexact ( 10 ) , Absent ) ,
2021
2024
Some ( Inexact ( 10 ) ) ,
2022
2025
) ,
2023
2026
// distinct(left) > distinct(right)
2024
2027
(
2025
- ( 10 , Inexact ( 1 ) , Inexact ( 10 ) , Inexact ( 5 ) , Absent ) ,
2026
- ( 10 , Inexact ( 1 ) , Inexact ( 10 ) , Inexact ( 2 ) , Absent ) ,
2028
+ ( 10 , Absent , Absent , Inexact ( 5 ) , Absent ) ,
2029
+ ( 10 , Absent , Absent , Inexact ( 2 ) , Absent ) ,
2027
2030
Some ( Inexact ( 20 ) ) ,
2028
2031
) ,
2029
2032
// distinct(right) > distinct(left)
2030
2033
(
2031
- ( 10 , Inexact ( 1 ) , Inexact ( 10 ) , Inexact ( 2 ) , Absent ) ,
2032
- ( 10 , Inexact ( 1 ) , Inexact ( 10 ) , Inexact ( 5 ) , Absent ) ,
2034
+ ( 10 , Absent , Absent , Inexact ( 2 ) , Absent ) ,
2035
+ ( 10 , Absent , Absent , Inexact ( 5 ) , Absent ) ,
2033
2036
Some ( Inexact ( 20 ) ) ,
2034
2037
) ,
2035
2038
// min(left) < 0 (range(left) > range(right))
@@ -2071,18 +2074,13 @@ mod tests {
2071
2074
) ,
2072
2075
// No min or max (or both).
2073
2076
(
2074
- ( 10 , Absent , Absent , Inexact ( 3 ) , Absent ) ,
2075
- ( 10 , Absent , Absent , Inexact ( 3 ) , Absent ) ,
2076
- None ,
2077
- ) ,
2078
- (
2079
- ( 10 , Inexact ( 2 ) , Absent , Inexact ( 3 ) , Absent ) ,
2080
- ( 10 , Absent , Inexact ( 5 ) , Inexact ( 3 ) , Absent ) ,
2077
+ ( 10 , Absent , Absent , Absent , Absent ) ,
2078
+ ( 10 , Absent , Absent , Absent , Absent ) ,
2081
2079
None ,
2082
2080
) ,
2083
2081
(
2084
- ( 10 , Absent , Inexact ( 3 ) , Inexact ( 3 ) , Absent ) ,
2085
- ( 10 , Inexact ( 1 ) , Absent , Inexact ( 3 ) , Absent ) ,
2082
+ ( 10 , Inexact ( 2 ) , Absent , Absent , Absent ) ,
2083
+ ( 10 , Absent , Inexact ( 5 ) , Absent , Absent ) ,
2086
2084
None ,
2087
2085
) ,
2088
2086
(
0 commit comments