Skip to content

Commit 8f7a54a

Browse files
committed
add test
1 parent 49193a2 commit 8f7a54a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/query/catalog/src/statistics/basic_statistics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl BasicColumnStatistics {
131131
})
132132
}
133133

134+
// Inspired by duckdb (https://github.com/duckdb/duckdb/blob/main/src/storage/statistics/distinct_statistics.cpp#L55-L69)
134135
fn estimate_ndv(ndv: u64, stats_row_count: u64, num_rows: u64) -> u64 {
135136
if stats_row_count == 0 || ndv == 0 {
136137
return num_rows;
@@ -161,5 +162,6 @@ mod tests {
161162
assert_eq!(BasicColumnStatistics::estimate_ndv(0, 1, 3), 3);
162163
assert_eq!(BasicColumnStatistics::estimate_ndv(1, 1, 3), 3);
163164
assert_eq!(BasicColumnStatistics::estimate_ndv(12, 100, 3000), 17);
165+
assert_eq!(BasicColumnStatistics::estimate_ndv(6000, 10000, 1000000), 219840);
164166
}
165167
}

0 commit comments

Comments
 (0)