clockworklabs / SpacetimeDB

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

core: Make NDV non-zero #1985

Closed kim closed 1 week ago

kim commented 1 week ago

Change TxId::num_distinct_values to return Option<NonZeroU64>.

It will now return None if either the table doesn't exist, no index exists for the given column list, or the index is empty. Otherwise, Some non-zero number of distinct values is returned.

Fixes a division-by-zero bug in the query row estimation.

Expected complexity level and risk

1

Testing

No functional change, estimation::index_row_est is now statically guaranteed to not panic due to division-by-zero