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: fix incorrect result of logical operators #12173

Merged
merged 3 commits into from
Oct 14, 2019
Merged

expression: fix incorrect result of logical operators #12173

merged 3 commits into from
Oct 14, 2019

Conversation

sduzh
Copy link
Contributor

@sduzh sduzh commented Sep 12, 2019

What problem does this PR solve?

Fix #11199
Fix #11188

TiDB> SELECT NULL OR 0.00000001000000000000;
+--------------------------------+
| NULL OR 0.00000001000000000000 |
+--------------------------------+
|                              1 |
+--------------------------------+
1 row in set (0.00 sec)

TiDB> SELECT 0 OR 0.00000001000000000000;
+-----------------------------+
| 0 OR 0.00000001000000000000 |
+-----------------------------+
|                           1 |
+-----------------------------+
1 row in set (0.00 sec)

TiDB> SELECT 0 OR "0.01a";
+--------------+
| 0 OR "0.01a" |
+--------------+
|            1 |
+--------------+
1 row in set, 1 warning (0.00 sec)

What is changed and how it works?

Wrap the input parameters of the builtin ANDOR and XOR operators with IS TRUE function before cast them to int type.

Check List

Tests

  • Unit test

Code changes

Side effects

Related changes

Release note

  • fix incorrect result of logical operators (OR, AND)

@sre-bot sre-bot added the contribution This PR is from a community contributor. label Sep 12, 2019
@codecov
Copy link

codecov bot commented Sep 12, 2019

Codecov Report

Merging #12173 into master will decrease coverage by 0.0466%.
The diff coverage is n/a.

@@               Coverage Diff                @@
##             master     #12173        +/-   ##
================================================
- Coverage   79.9183%   79.8717%   -0.0467%     
================================================
  Files           462        462                
  Lines        104892     105101       +209     
================================================
+ Hits          83828      83946       +118     
- Misses        14910      14990        +80     
- Partials       6154       6165        +11

@zz-jason
Copy link
Member

@sduzh should we directly modify builtinLogicOrSig to return 1 when the two input parameters are null and 1?

@sduzh
Copy link
Contributor Author

sduzh commented Sep 18, 2019

@sduzh should we directly modify builtinLogicOrSig to return 1 when the two input parameters are null and 1?

@zz-jason Sorry, I didn't understand what you mean. Isn't this the current implementation?

expression/builtin_op.go Outdated Show resolved Hide resolved
expression/expression.go Outdated Show resolved Hide resolved
expression/expression.go Outdated Show resolved Hide resolved
expression/expression.go Outdated Show resolved Hide resolved
expression/builtin_op.go Outdated Show resolved Hide resolved
Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

Hi, your PR looks really awesome. It would be better to take another look at other logical functions (https://dev.mysql.com/doc/refman/8.0/en/logical-operators.html), and fix them together.
Thanks again.

@sduzh sduzh closed this Oct 1, 2019
@sduzh sduzh reopened this Oct 1, 2019
@CLAassistant
Copy link

CLAassistant commented Oct 1, 2019

CLA assistant check
All committers have signed the CLA.

@sduzh sduzh changed the title expression: fix incorrect OR result (#11199) expression: fix incorrect result of logical operators (#11199) Oct 1, 2019
Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@XuHuaiyu XuHuaiyu changed the title expression: fix incorrect result of logical operators (#11199) expression: fix incorrect result of logical operators Oct 9, 2019
XuHuaiyu
XuHuaiyu previously approved these changes Oct 9, 2019
Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. labels Oct 9, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Oct 9, 2019

Your auto merge job has been accepted, waiting for 12558, 12564, 12551, 12552, 12553

@qw4990 qw4990 removed their request for review October 9, 2019 08:48
@sre-bot
Copy link
Contributor

sre-bot commented Oct 9, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Oct 9, 2019

@sduzh merge failed.

@sduzh sduzh deleted the issue-11199 branch October 14, 2019 13:37
SunRunAway added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
zimulala added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
SunRunAway added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
eurekaka added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
eurekaka added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
eurekaka added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
eurekaka added a commit to SunRunAway/tidb that referenced this pull request Oct 18, 2019
@cyliu0 cyliu0 mentioned this pull request Nov 6, 2019
XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. 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.

Result of function OR is not correct. Function NOT/IF returns incorrect result with decimal argument
8 participants