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

An incorrect query result #41878

Open
sayJason opened this issue Mar 2, 2023 · 3 comments · Fixed by #57343
Open

An incorrect query result #41878

sayJason opened this issue Mar 2, 2023 · 3 comments · Fixed by #57343
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.0 affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@sayJason
Copy link

sayJason commented Mar 2, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE t1 (c0 decimal(10,0));
INSERT INTO t1 VALUES (0);
SELECT c0 FROM t1 WHERE CAST(ATAN2(((t1.c0) IS NULL), (- (''))) AS TIME); -- actual: {}, expected: {0}

2. What did you expect to see? (Required)

The SELECT statement should return the value 0.

3. What did you see instead (Required)

The SELECT statement returns an empty set.

4. What is your TiDB version? (Required)

Release Version: v6.6.0
Edition: Community
Git Commit Hash: f4ca082
Git Branch: heads/refs/tags/v6.6.0
UTC Build Time: 2023-02-17 14:49:02
GoVersion: go1.19.5
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv

@sayJason sayJason added the type/bug The issue is confirmed as a bug. label Mar 2, 2023
@seiya-annie
Copy link

tried in mysql:

mysql> CREATE TABLE t1 (c0 decimal(10,0));
Query OK, 0 rows affected (0.01 sec)

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

mysql> SELECT c0 FROM t1 WHERE CAST(ATAN2(((t1.c0) IS NULL), (- (''))) AS TIME); 
+------+
| c0   |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Mar 3, 2023
@VelocityLight VelocityLight added the affects-7.1 This bug affects the 7.1.x(LTS) versions. label Apr 20, 2023
@ti-chi-bot ti-chi-bot added the affects-7.5 This bug affects the 7.5.x(LTS) versions. label Oct 23, 2023
@ti-chi-bot ti-chi-bot added the affects-8.1 This bug affects the 8.1.x(LTS) versions. label Apr 9, 2024
@yibin87
Copy link
Contributor

yibin87 commented Apr 30, 2024

The root cause is the ATAN2 function behaves differently in tidb and tikv, and tidb behaves the same as MySQL:

mysql> select ATAN2(((t1.c0) IS NULL), (- (''))) as a from t1;
+------+
| a    |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

mysql> set tidb_opt_projection_push_down = 'off';
Query OK, 0 rows affected (0.00 sec)

mysql> select ATAN2(((t1.c0) IS NULL), (- (''))) as a from t1;
+-------------------+
| a                 |
+-------------------+
| 3.141592653589793 |
+-------------------+
1 row in set (0.00 sec)

@ti-chi-bot ti-chi-bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@wshwsh12 wshwsh12 added affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. labels Nov 13, 2024
@ti-chi-bot ti-chi-bot bot removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.5 may-affects-6.1 labels Nov 13, 2024
@wshwsh12 wshwsh12 removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. labels Nov 13, 2024
@wshwsh12
Copy link
Contributor

This issue occurs because TiDB ignores the sign bit when encoding the floating-point constant -0 and pushing it down to TiKV. TiKV use the 0 to calcute the result and get wrong.
To fix this issue, the lowest-level encode/decode functions need to be modified, which would cause many behavioral changes. For example, incorrect results in hash aggregation and stream aggregation, as well as unstable sorting results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.0 affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants