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

Fix function mod decimal scale overflow #2462

Merged
merged 4 commits into from
Jul 22, 2021
Merged

Fix function mod decimal scale overflow #2462

merged 4 commits into from
Jul 22, 2021

Conversation

riteme
Copy link
Contributor

@riteme riteme commented Jul 22, 2021

What problem does this PR solve?

Problem Summary: #2402 (issue #2318) will overflow in decimal modulo.

What is changed and how it works?

What's Changed: This PR fixes the issue by assign modulo operation to need_promote_type in DecimalBinaryOperation.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch:

Check List

Tests

  • Unit test

Side effects

Release note

  • Fix an overflow bug in decimal MOD(N, M).

else
// assert that negation of std::numeric_limits<From>::min() will not result in overflow.
// TODO: find credible source that describes numeric limits of boost multiprecision *checked* integers.
static_assert(-std::numeric_limits<From>::max() == std::numeric_limits<From>::min());
Copy link
Contributor

Choose a reason for hiding this comment

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

interestring, I thought -std::numeric_limits<From>::max() should be larger than std::numeric_limits<From>::min() by 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also surprised by the fact. I guess Boost made a deliberate decision on checked fixed precision integers. But I didn't find any evidence in Boost multiprecision doc.

By contrast, Boost says unchecked integers use 2's complement representation in their documents: https://www.boost.org/doc/libs/1_76_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/cpp_int.html

@ti-srebot
Copy link
Collaborator

@fuzhe1989, Thanks for your review. The bot only counts LGTMs from Reviewers and higher roles, but you're still welcome to leave your comments. See the corresponding SIG page for more information. Related SIG: tiflash(slack).

@fuzhe1989
Copy link
Contributor

/run-all-tests

@riteme
Copy link
Contributor Author

riteme commented Jul 22, 2021

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 22, 2021
@ti-srebot
Copy link
Collaborator

/run-all-tests

@ti-srebot ti-srebot merged commit c407b16 into pingcap:master Jul 22, 2021
@riteme riteme added type/bug-fix PR that fixes a bug needs-cherry-pick-release-5.0 PR which needs to be cherry-picked to release-5.0 needs-cherry-pick-release-5.1 PR which needs to be cherry-picked to release-5.1 labels Aug 4, 2021
@ti-srebot
Copy link
Collaborator

cherry pick to release-5.0 in PR #2608

@ti-srebot
Copy link
Collaborator

cherry pick to release-5.1 in PR #2609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 PR which needs to be cherry-picked to release-5.0 needs-cherry-pick-release-5.1 PR which needs to be cherry-picked to release-5.1 status/can-merge Indicates a PR has been approved by a committer. type/bug-fix PR that fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants