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

not compatible with MySQL when handling some subqueries with aggregation functions #17083

Open
qw4990 opened this issue May 11, 2020 · 2 comments
Assignees
Labels
component/expression help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@qw4990
Copy link
Contributor

qw4990 commented May 11, 2020

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?

CREATE TABLE t ( v decimal(20, 3) );
insert into t values (1);
select sum(v)/123*123 from t;  // MySQL & TiDB: 1.0000000
select x * 123 from (
  select sum(v)/123 as x from t
) t; // MySQL: 1.0000023, TiDB: 1.0000000

It seems a bug in MySQL since it loses precision.

2. What did you expect to see?

In MySQL:

mysql> select sum(v)/123*123 from t;
+----------------+
| sum(v)/123*123 |
+----------------+
|      1.0000000 |
+----------------+
1 row in set (0.00 sec)

mysql> select x * 123 from (
    ->   select sum(v)/123 as x from t
    -> ) t;
+-----------+
| x * 123   |
+-----------+
| 1.0000023 |
+-----------+
1 row in set (0.00 sec)

3. What did you see instead?

In TiDB:

mysql> select sum(v)/123*123 from t;
+----------------+
| sum(v)/123*123 |
+----------------+
|      1.0000000 |
+----------------+
1 row in set (0.00 sec)

mysql> select x * 123 from (
    ->   select sum(v)/123 as x from t
    -> ) t;
+-----------+
| x * 123   |
+-----------+
| 1.0000000 |
+-----------+
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)

mysql> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.10
Git Commit Hash: 75ff39ac142c7a1191988239358b1aa8e7ef9ace
Git Branch: HEAD
UTC Build Time: 2020-05-11 05:52:30
GoVersion: go version go1.13.1 darwin/amd64
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@qw4990 qw4990 added the type/bug The issue is confirmed as a bug. label May 11, 2020
@qw4990 qw4990 self-assigned this May 11, 2020
@SunRunAway SunRunAway added sig/execution SIG execution component/expression and removed sig/execution SIG execution labels May 11, 2020
@qw4990 qw4990 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Nov 9, 2020
@XuHuaiyu XuHuaiyu added the sig/execution SIG execution label Dec 21, 2020
@mmyj
Copy link
Member

mmyj commented Mar 23, 2021

/pick-up

@mmyj
Copy link
Member

mmyj commented Mar 23, 2021

/assign

@qw4990 qw4990 removed their assignment Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

5 participants