clockworklabs / SpacetimeDB

Multiplayer at the speed of light
https://spacetimedb.com
Other
4.41k stars 110 forks source link

Avoid div-by-zero in row count estimations for empty tables #1992

Closed gefjon closed 1 week ago

gefjon commented 1 week ago

Description of Changes

Forward-port of #1991 , an 0.11.1 hotfix for the BitCraft alpha, into master.

What was happening was, num_distinct_values on an empty table returned 0, which index_row_est then used as a divisor, leading to a panic. It seems reasonably clear to me that the correct estimate of distinct values in an empty index is 0, not bottom, so adjusting num_distinct_values to return Option<NonZeroU64>, and then making index_row_est return 0 in that case, seems an obvious fix.

API and ABI breaking changes

None

Expected complexity level and risk

1

Testing

Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected!

kim commented 1 week ago

1985 and #1986 addressed the same, you may want to pick #1986 as a regression test

gefjon commented 1 week ago

1985 and #1986 addressed the same, you may want to pick #1986 as a regression test

Ah, I didn't realize we already had patches against master for this. Will close.