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

Aggregating enum zero value gets different results from mysql #26885

Closed
wshwsh12 opened this issue Aug 4, 2021 · 0 comments · Fixed by #36208
Closed

Aggregating enum zero value gets different results from mysql #26885

wshwsh12 opened this issue Aug 4, 2021 · 0 comments · Fixed by #36208
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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@wshwsh12
Copy link
Contributor

wshwsh12 commented Aug 4, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
drop table t1;
CREATE TABLE t1 (c1 ENUM('a', '', 'b'));
INSERT INTO t1 (c1) VALUES ('b');
INSERT INTO t1 (c1) VALUES ('');
INSERT INTO t1 (c1) VALUES (0);
INSERT INTO t1 (c1) VALUES ('');
SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1 order by c1;

This situation can only occur with the following conditions:

  1. Enum type has '' name field.
  2. Illegal value/zero value is inserted in the data.
    So I think this problem is not very serious..

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

MySQL [test]> SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1 order by c1;
+--------+-----------+
| c1 + 0 | COUNT(c1) |
+--------+-----------+
|      0 |         1 |
|      2 |         2 |
|      3 |         1 |
+--------+-----------+
3 rows in set (0.000 sec)

3. What did you see instead (Required)

[tidb]> SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1 order by c1;
+--------+-----------+
| c1 + 0 | COUNT(c1) |
+--------+-----------+
|      2 |         3 |
|      3 |         1 |
+--------+-----------+
2 rows in set (0.001 sec)

// Different insert order will get different result. If I insert values(0) first, the result will be following:

[tidb]> SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1 order by c1;
+--------+-----------+
| c1 + 0 | COUNT(c1) |
+--------+-----------+
|      0 |         3 |
|      3 |         1 |
+--------+-----------+
2 rows in set (0.001 sec)

4. What is your TiDB version? (Required)

master, v5.0 v5.1, v4.0

@wshwsh12 wshwsh12 added type/bug The issue is confirmed as a bug. sig/execution SIG execution labels Aug 4, 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 5.4.x versions. labels Jan 11, 2022
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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 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.

4 participants