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

expression: check Overflow int128 #4762

Merged
merged 9 commits into from
May 20, 2022
Merged

Conversation

fzhedu
Copy link
Contributor

@fzhedu fzhedu commented Apr 25, 2022

What problem does this PR solve?

Issue Number: close #4512

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 25, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • LittleFall
  • yibin87

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 25, 2022
@fuzhe1989
Copy link
Contributor

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 26, 2022
Copy link
Contributor

@yibin87 yibin87 left a comment

Choose a reason for hiding this comment

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

It'll be nice to explain why muloverflow affects comparasion result.

@fzhedu
Copy link
Contributor Author

fzhedu commented May 12, 2022

consider port https://github.com/ClickHouse/ClickHouse/blob/master/base/base/arithmeticOverflow.h to TiFlash?

https://github.com/ClickHouse/ClickHouse/blob/master/base/base/arithmeticOverflow.h#L179
/// Overflow check is not implemented for big integers.

but here needs to checkout overflow.

@fzhedu
Copy link
Contributor Author

fzhedu commented May 12, 2022

It'll be nice to explain why muloverflow affects comparasion result.

a git positive value becomes negective, so the compare resultes are wrong.

Copy link
Contributor

@yibin87 yibin87 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 12, 2022
unsigned __int128 a = (x > 0) ? x : -x;
unsigned __int128 b = (y > 0) ? y : -y;
return (a * b) / b != a;
return res/x != y; /// whether overflow int128
Copy link
Contributor

Choose a reason for hiding this comment

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

How about add some unit test for this overflow check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 13, 2022
Comment on lines 46 to 48
/// 2^254 << 1 = 2^255
is_overflow = common::mulOverflow(int_254, Int256(2), res256);
ASSERT_EQ(is_overflow, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LittleFall is this as expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is expected, the max limit of signed Int256 is (1<<255)-1

Copy link
Contributor

Choose a reason for hiding this comment

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

According to the boost doc and implement, the Int256 in boost includes 256bit data and 1bit sign, so the max/min value is different from our expectation.

https://www.boost.org/doc/libs/1_60_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/cpp_int.html

Copy link
Contributor

@LittleFall LittleFall May 16, 2022

Choose a reason for hiding this comment

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

after discussion, this won't affect our current logic. the unexpected common::mulOverflow only has one caller https://github.com/pingcap/tiflash/blob/master/dbms/src/Core/DecimalComparison.h#L153-L169, and it won't break too.

by the way, we need some comments on this function.

@@ -129,6 +127,6 @@ inline bool mulOverflow(Int256 x, Int256 y, Int256 & res)
{
return true;
}
return false;
return res >= Int256((Int256(0x1) << 255)); /// whether overflow int256
Copy link
Contributor

Choose a reason for hiding this comment

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

Why need add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ti-chi-bot ti-chi-bot added 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 needs-cherry-pick-release-5.2 PR which needs to be cherry-picked to release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.0 Type: Need cherry pick to release-6.0 and removed do-not-merge/needs-triage-completed labels May 16, 2022
@ti-chi-bot ti-chi-bot removed the status/LGT1 Indicates that a PR has LGTM 1. label May 16, 2022
Signed-off-by: fzhedu <fzhedu@gmail.com>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label May 20, 2022
@fzhedu
Copy link
Contributor Author

fzhedu commented May 20, 2022

/merge

@ti-chi-bot
Copy link
Member

@fzhedu: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: d688bb8

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 20, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented May 20, 2022

Coverage for changed files

Filename                                                                                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/jenkins/agent/workspace/tiflash-build-common/tiflash/libs/libcommon/include/common/arithmeticOverflow.h          21                 9    57.14%          13                 9    30.77%          56                33    41.07%           4                 1    75.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                                                  21                 9    57.14%          13                 9    30.77%          56                33    41.07%           4                 1    75.00%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18224      9787             46.30%    204122  97976        52.00%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit 71613fd into pingcap:master May 20, 2022
ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 20, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4942.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4943.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4944.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 20, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4945.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 20, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4946.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request May 20, 2022
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4947.

ti-chi-bot added a commit that referenced this pull request Jun 16, 2022
ti-chi-bot added a commit that referenced this pull request Jun 16, 2022
ti-chi-bot added a commit that referenced this pull request Jun 16, 2022
ti-chi-bot added a commit that referenced this pull request Jun 16, 2022
ti-chi-bot added a commit that referenced this pull request Jun 17, 2022
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 needs-cherry-pick-release-5.2 PR which needs to be cherry-picked to release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.0 Type: Need cherry pick to release-6.0 release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scan-filter results is wrong
7 participants