Tidb: Incorrect result when comparing a FLOAT/DOUBLE UNSIGNED with a negative number

Created on 2 Apr 2020  路  6Comments  路  Source: pingcap/tidb

Consider the following statements:

CREATE TABLE t0(c0 DOUBLE UNSIGNED UNIQUE);
INSERT INTO t0(c0) VALUES (0);
SELECT * FROM t0 WHERE t0.c0 = -1; -- expected: {}, actual: {0}

Unexpectedly, the SELECT fetches a row. It seems that DOUBLE and FLOAT is affected, but not INT and NUMERIC.

Environment:

mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                          |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-167-gaa7ef9c46
Git Commit Hash: aa7ef9c46435bb20d42fa0badcf09fc16f9609a9
Git Branch: master
UTC Build Time: 2020-04-02 09:15:47
GoVersion: go1.13.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
componenexpression need-more-info severitmajor siexecution typbug

Most helpful comment

Hi, is anyone working on this? I have a simple patch that seems can fix this issue, although I am not sure whether it will introduce other issues.
Maybe I can create a pull request if nobody working on this.

All 6 comments

Hi, is anyone working on this? I have a simple patch that seems can fix this issue, although I am not sure whether it will introduce other issues.
Maybe I can create a pull request if nobody working on this.

@sduzh Of course. I just found out where the problem is and have not submitted a PR. The problem is in the place you mentioned, welcome to submit PR!

@sduzh The problem is that this line of code incorrectly handles the overflow error. It causes the result to return 0. I am not sure whether your patch will introduce new problems, feel free to work on this issue. Thanks for your contribution!

I quit this issue.

In the master 93c3e6becd5929cc37901d78d1f679cbc5d86342, the result is correct.

mysql> CREATE TABLE t0(c0 DOUBLE UNSIGNED UNIQUE);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t0(c0) VALUES (0);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM t0 WHERE t0.c0 = -1;
Empty set (0.00 sec)

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: https://github.com/pingcap/tidb/issues/20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Was this page helpful?
0 / 5 - 0 ratings