Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins: use intermediate decimal context for distributed aggregation #105694

Merged
merged 1 commit into from Jul 8, 2023

Conversation

DrewKimball
Copy link
Collaborator

Aggregate builtin functions round the final result using the default decimal precision. In some cases, one aggregate uses the result of another in its own calculations. This could previously cause slightly different results between local and distributed execution for aggregates that return decimal values.

This patch adds intermediateResult methods to the aggregates that are used in the intermediate calculations for other aggregates. This avoids the rounding of intermediate results, which ensures accurate results for distributed execution.

Fixes #94827

Release note (bug fix): Fixed a rounding error that could cause distributed execution for some decimal aggregate functions to return slightly inaccurate results in rare cases.

@DrewKimball DrewKimball requested review from yuzefovich and a team June 28, 2023 08:05
@DrewKimball DrewKimball requested a review from a team as a code owner June 28, 2023 08:05
@blathers-crl
Copy link

blathers-crl bot commented Jun 28, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Thanks!

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)

@DrewKimball DrewKimball force-pushed the aggregate-precision branch 2 times, most recently from ca0ceca to 768488c Compare July 6, 2023 05:01
Aggregate builtin functions round the final result using the default decimal
precision. In some cases, one aggregate uses the result of another in its
own calculations. This could previously cause slightly different results
between local and distributed execution for aggregates that return decimal
values.

This patch adds `intermediateResult` methods to the aggregates that are
used in the intermediate calculations for other aggregates. This avoids
the rounding of intermediate results, which ensures accurate results for
distributed execution.

Fixes cockroachdb#94827

Release note (bug fix): Fixed a rounding error that could cause distributed
execution for some decimal aggregate functions to return slightly
inaccurate results in rare cases.
@DrewKimball
Copy link
Collaborator Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 8, 2023

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql/physicalplan: TestSingleArgumentDistAggregateFunctions failed
3 participants