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

count() is incompatible with mysql and tidb #23549

Closed
wan1y opened this issue Mar 25, 2021 · 6 comments
Closed

count() is incompatible with mysql and tidb #23549

wan1y opened this issue Mar 25, 2021 · 6 comments
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 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. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug. type/compatibility

Comments

@wan1y
Copy link

wan1y commented Mar 25, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t1`  (
  `COL1` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
insert into t1 values("tidb");

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

mysql:
mysql> select col1 from t1 group by col1 having count(col1) = "1e64";
Empty set

3. What did you see instead (Required)

tidb:
mysql> select col1 from t1 group by col1 having count(col1) = "1e20";
Empty set

mysql> select col1 from t1 group by col1 having count(col1) = "1e64";
+------+
| col1 |
+------+
| tidb |
+------+
1 row in set (0.59 sec)

4. What is your TiDB version? (Required)

Release Version: v4.0.0-beta.2-2444-g5715eefd2-dirty
Edition: Community
Git Commit Hash: 5715eefd2b2febdd6e3b64413bb066f4d425a3dc
Git Branch: master
UTC Build Time: 2021-03-24 14:28:28
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@wan1y wan1y added type/bug The issue is confirmed as a bug. type/compatibility labels Mar 25, 2021
@morgo
Copy link
Contributor

morgo commented Mar 26, 2021

Verified as described. My client returned a warning for this statement though:

mysql> select col1 from t1 group by col1 having count(col1) = "1e64";
+------+
| col1 |
+------+
| tidb |
+------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1690 | BIGINT value is out of range in '1e64' |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)

@jebter jebter added the sig/execution SIG execution label Dec 7, 2021
@XuHuaiyu
Copy link
Contributor

count(col1) = "1e64" is rewritten to eq(Column#3, 1)

 desc select col1 from t1 group by col1 having count(col1) = "1e64";
+------------------------------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------+
| id                           | estRows | task      | access object | operator info                                                                                          |
+------------------------------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------+
| Projection_6                 | 0.80    | root      |               | test.t1.col1                                                                                           |
| └─Selection_7                | 0.80    | root      |               | eq(Column#3, 1)                                                                                        |
|   └─HashAgg_10               | 1.00    | root      |               | group by:test.t1.col1, funcs:count(test.t1.col1)->Column#3, funcs:firstrow(test.t1.col1)->test.t1.col1 |
|     └─TableReader_15         | 1.00    | root      |               | data:TableFullScan_14                                                                                  |
|       └─TableFullScan_14     | 1.00    | cop[tikv] | table:t1      | keep order:false, stats:pseudo                                                                         |
+------------------------------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------+
5 rows in set, 1 warning (0.00 sec)

@XuHuaiyu XuHuaiyu added sig/planner SIG: Planner and removed sig/execution SIG execution labels Dec 14, 2021
@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. labels Jan 11, 2022
@time-and-fate
Copy link
Member

This issue is introduced by #23281. Obviously, it's not directly related to this issue. The root cause and how to fix it need further investigation.

@time-and-fate
Copy link
Member

As XuHuaiyu said above, the result is wrong because the 1e64 becomes 1 in the query plan.

The direct reason for the 1e64 becoming 1 is this line of code:

return validFloat[:eIdx], nil

Changing it to return validFloat, nil seems a reasonable fix, but it's not easy to estimate the influence of this change, and I'm not sure if this change is correct.
I tried this fix in #34453, but one unit test case failed. I believe the test case itself is questionable but I'm not sure.

@VelocityLight VelocityLight added the affects-6.1 This bug affects the 6.1.x(LTS) versions. label May 20, 2022
@VelocityLight VelocityLight added the affects-6.5 This bug affects the 6.5.x(LTS) versions. label Dec 2, 2022
@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
@qw4990
Copy link
Contributor

qw4990 commented Apr 28, 2024

Can't reproduce this, this issue might have been fixed by some other PR:

mysql> select col1 from t1 group by col1 having count(col1) = "1e64";
Empty set (0.00 sec)

mysql> select col1 from t1 group by col1 having count(col1) = "1e20";
Empty set (0.00 sec)

@qw4990 qw4990 closed this as completed Apr 28, 2024
@winoros winoros removed the affects-8.1 This bug affects the 8.1.x(LTS) versions. label Jun 4, 2024
@qw4990 qw4990 assigned qw4990 and unassigned time-and-fate Jul 1, 2024
@qw4990
Copy link
Contributor

qw4990 commented Jul 8, 2024

Fixed by #47803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 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. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug. type/compatibility
Projects
None yet
Development

No branches or pull requests

9 participants