@@ -138,6 +138,8 @@ pub struct PartitionData {
138138pub enum Cardinality {
139139 /// Unknown number of rows
140140 Unknown ,
141+ /// The exact number of rows.
142+ Exact ( u64 ) ,
141143 /// An estimate of the number of rows.
142144 Estimate ( u64 ) ,
143145}
@@ -478,12 +480,18 @@ pub fn statistics(bind_data: &TableFunctionBind, column_index: usize) -> Option<
478480/// here.
479481const DEFAULT_SELECTIVITY : f64 = 0.2 ;
480482pub fn cardinality ( bind_data : & TableFunctionBind ) -> Cardinality {
483+ let has_non_optional_filter = bind_data. has_non_optional_filter . load ( Ordering :: Relaxed ) ;
481484 match bind_data. data_source . row_count ( ) {
482- Precision :: Exact ( v) | Precision :: Inexact ( v) => {
483- if !bind_data. has_non_optional_filter . load ( Ordering :: Relaxed ) {
484- // Although we may have an exact upper bound here, reporting
485- // it as exact has a negative performance impact on tpcds as
486- // it's not a real post-filter calculation.
485+ Precision :: Exact ( v) => {
486+ if !has_non_optional_filter {
487+ return Cardinality :: Exact ( v) ;
488+ }
489+ let post_cardinality = v as f64 * DEFAULT_SELECTIVITY ;
490+ let post_cardinality: u64 = post_cardinality. as_ ( ) ;
491+ Cardinality :: Estimate ( max ( 1 , post_cardinality) )
492+ }
493+ Precision :: Inexact ( v) => {
494+ if !has_non_optional_filter {
487495 return Cardinality :: Estimate ( v) ;
488496 }
489497 let post_cardinality = v as f64 * DEFAULT_SELECTIVITY ;
0 commit comments