mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 05:24:22 +01:00
### Follow SUM [spec](https://sqlite.org/lang_aggfunc.html) This PR updates the `SUM` aggregation logic to follow the [Kahan–Babushka–Neumaier summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm), consistent with SQLite’s implementation. It improves the numerical stability of floating-point summation.This fixes issue #2252 . I added a fuzz test to ensure the compatibility of the implementations I also fixed the return types for `SUM` to match SQLite’s documented behavior. This was previously discussed in [#2182](https://github.com/tursodatabase/turso/pull/2182), but part of the logic was later unintentionally overwritten by [#2265](https://github.com/tursodatabase/turso/pull/2265). I introduced two helper functions, `apply_kbn_step` and `apply_kbn_step_int`, in `vbde/execute.rs` to handle floating-point and integer accumulation respectively. However, I’m new to this codebase and would welcome constructive feedback on whether there’s a better place for these helpers. Reviewed-by: Preston Thorpe (@PThorpe92) Closes #2270