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

executor: refineArgs() bug fix when compare int with very small decimal #23694

Merged
merged 3 commits into from
Mar 30, 2021

Conversation

guo-shaoge
Copy link
Collaborator

@guo-shaoge guo-shaoge commented Mar 30, 2021

Signed-off-by: guo-shaoge shaoge1994@163.com

What problem does this PR solve?

Issue Number:
close #23623
close #23684

Problem Summary: In the following case, output of select stmt should be 2, but current result is 3.

Why: c1 is nullable, so we cannot assuse all value in c1 will be greater than the result of subquery, which is less than int32_min. Because result of null > xxx is NULL

drop table if exists t1;
create table t1(c1 int);
insert into t1 values(-2147483648), (-2147483648), (null);
select count(*) from t1 where c1 > (select sum(c1) from t1);

What is changed and how it works?

What's Changed: when refineArgs(), should check if column is nullable. If is nullable, we should not try to optimize compare expression.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Integration test

Side effects

  • Performance regression
    • Consumes more CPU: may cause performance regression compared when compare int_column with const if int_column is nullable.

Release note

  • fix bug when compare int_column with constant value

Signed-off-by: guo-shaoge <shaoge1994@163.com>
Signed-off-by: guo-shaoge <shaoge1994@163.com>
…3623_refine_arg_bug

Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge guo-shaoge requested a review from a team as a code owner March 30, 2021 10:52
@guo-shaoge guo-shaoge requested review from wshwsh12 and removed request for a team March 30, 2021 10:52
@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 30, 2021
@zz-jason zz-jason added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Mar 30, 2021
// Why check not null flag
// eg: int_col > const_val(which is less than min_int32)
// If int_col got null, compare result cannot be true
if arg0IsInt && !arg0IsCon && !arg1IsInt && arg1IsCon && mysql.HasNotNullFlag(arg0Type.Flag) {
arg1, isExceptional = RefineComparedConstant(ctx, *arg0Type, arg1, c.op)
finalArg1 = arg1
if isExceptional && arg1.GetType().EvalType() == types.ETInt {
Copy link
Contributor

Choose a reason for hiding this comment

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

If arg1 == false, can we ignore the not-null flag ?

Copy link
Collaborator Author

@guo-shaoge guo-shaoge Mar 30, 2021

Choose a reason for hiding this comment

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

select xxx where (col_int > (select sum(xx) xx) ) is null;

So need to distinguish null or false of GT expr.

@XuHuaiyu
Copy link
Contributor

CI needs to be fixed.

@ichn-hu ichn-hu mentioned this pull request Mar 30, 2021
@guo-shaoge guo-shaoge requested a review from a team as a code owner March 30, 2021 12:23
@guo-shaoge guo-shaoge requested review from eurekaka and removed request for a team March 30, 2021 12:23
@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 Mar 30, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

1 similar comment
@XuHuaiyu
Copy link
Contributor

/run-all-tests

@XuHuaiyu
Copy link
Contributor

/lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 30, 2021
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • lzmhhh123

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 writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 30, 2021
@lzmhhh123
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: a2d8a15

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 30, 2021
@ti-chi-bot ti-chi-bot merged commit 3ed4a23 into pingcap:master Mar 30, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 30, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #23705

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 30, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #23706

@guo-shaoge guo-shaoge deleted the issue-23623_refine_arg_bug branch March 30, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression needs-cherry-pick-release-5.0 priority/release-blocker This issue blocks a release. Please solve it ASAP. 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. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

executor: wrong results from subquery wrong result when including subquery
6 participants