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

wrong results when IF function along with float argument #11601

Closed
jingyugao opened this issue Aug 4, 2019 · 4 comments · Fixed by #15016
Closed

wrong results when IF function along with float argument #11601

jingyugao opened this issue Aug 4, 2019 · 4 comments · Fixed by #15016
Labels
component/expression good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/bug The issue is confirmed as a bug.

Comments

@jingyugao
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    SELECT IF(0.1, 1, 2) FROM t1;

  2. What did you expect to see?
    +---------------+
    | IF(0.1, 1, 2) |
    +---------------+
    | 1 |
    +---------------+
    1 row in set (0.00 sec)

  3. What did you see instead?
    +---------------+
    | IF(0.1, 1, 2) |
    +---------------+
    | 2 |
    +---------------+
    1 row in set (0.00 sec)

  4. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    Release Version: None
    Git Commit Hash: None
    Git Branch: None
    UTC Build Time: None
    GoVersion: None
    Race Enabled: false
    TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
    Check Table Before Drop: false

@jingyugao jingyugao added the type/bug The issue is confirmed as a bug. label Aug 4, 2019
@jingyugao
Copy link
Contributor Author

In tidb, almost all builtIn*Sig function use the result of evalInt to check true or false.
This is not ok when args is float64 which is less than 1, it will be convert to 0 by evalInt.
So we should replace evalInt with evalReal.(By the way,if the argis to small and is out of the float64 accuracy,such as 1e-1000, it should be converted to 0)

@zz-jason
Copy link
Member

zz-jason commented Aug 4, 2019

evalInt means this expression signature should return an int result. For this case, we should implement evalInt. But in order to get the correct result, we should calling args[0].EvalReal() instead of args[0].EvalInt().

@zz-jason zz-jason added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Aug 4, 2019
@jingyugao
Copy link
Contributor Author

evalInt means this expression signature should return an int result. For this case, we should implement evalInt. But in order to get the correct result, we should calling args[0].EvalReal() instead of args[0].EvalInt().

Yes,I have fix the logic op #11587 many builtinfunc doesnt implement evalReal, so it may be difficult to handle.

@SunRunAway
Copy link
Contributor

SunRunAway commented Mar 11, 2020

CASE has a similar problem, I've created another issue #15291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants