sql: match precision of decimal operations to other databases#168724
sql: match precision of decimal operations to other databases#168724bghal wants to merge 1 commit intocockroachdb:masterfrom
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
672c69d to
2258804
Compare
The lower precision resulted in errors in intermediary calculations. This changes moves the precision to 38, which matches the precision of Oracle and SQL Server which, besides DB2, have the least precision of the reference databases. Fixes: cockroachdb#168373 Release note (sql change): Decimal expressions evaluate with a higher precision which prevents errors in intermediary calculations.
2258804 to
0a6d5ee
Compare
|
Thanks for looking into this issue. There are a few things that are worth discussing before going with this. CockroachDB targets PostgreSQL compatibility as our main reference, not Oracle/SQL Server. When picking a precision, the question to ask first is "what does PG do?" rather than averaging across reference databases. Today's precision-20 default already aligns very closely with PG. I tested a bit and looked at the code, and PG doesn't actually use a fixed precision. It dynamically selects a result scale targeting at least 16 significant digits via
Most cases are byte-identical. After this PR they'd all jump to 38 digits, which would be quite a meaningful divergence from PG. We would give up on some PG parity that CRDB already has. There also could be a performance cost to consider.
Could you run the existing micro-benchmarks ( This is a pretty big change with lots of observable effects, so it deserves some consensus between Product and various Engineering teams. The underlying bug in #168373 is real, but a more targeted fix (e.g. only bumping precision for the specific aggregation paths that need more headroom) might be the right approach rather than a global default change. Happy to discuss more offline. |
The lower precision resulted in errors in
intermediary calculations. This changes moves the
precision to 38, which matches the precision of
Oracle and SQL Server which, besides DB2, have the
least precision of the reference databases.
Fixes: #168373
Release note (sql change): Decimal expressions
evaluate with a higher precision which prevents
errors in intermediary calculations.