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_NULL Flag incorrectly set #18488

Closed
zhangysh1995 opened this issue Jul 10, 2020 · 4 comments · Fixed by #27697
Closed

NOT_NULL Flag incorrectly set #18488

zhangysh1995 opened this issue Jul 10, 2020 · 4 comments · Fixed by #27697
Assignees
Labels
severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug. type/regression

Comments

@zhangysh1995
Copy link

Bug Report

1. Minimal reproduce step (Required)

CREATE TABLE `test` (
            `iD` bigint(20) NOT NULL,
            `INT_TEST` int(11) DEFAULT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
INSERT INTO test VALUES (2, 10), (3, NULL);

 SELECT DISTINCT count(*), id + int_test as res FROM test  GROUP BY res ORDER BY res;

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

mysql>  SELECT DISTINCT count(*), id + int_test as res FROM test  GROUP BY res ORDER BY res;
+----------+-----+
| count(*) | res |
+----------+-----+
|        1 | NULL|
|        1 |  12 |
+----------+-----+
2 rows in set (0.01 sec)

3. What did you see instead (Required)

mysql>  SELECT DISTINCT count(*), id + int_test as res FROM test  GROUP BY res ORDER BY res;
+----------+-----+
| count(*) | res |
+----------+-----+
|        1 | NULL |
|        1 |  12 |
+----------+-----+
2 rows in set (0.01 sec)

4. Affected version (Required)

commit a9177fe846bf2638261f64514ab4ebd0155cc60c (HEAD -> master, origin/master, origin/HEAD)
Author: Boqin Qin <bobbqqin@bupt.edu.cn>
Date:   Mon Jul 6 19:28:12 2020 +0800

5. Root Cause Analysis

An extra space is printed.

@zhangysh1995 zhangysh1995 added the type/bug The issue is confirmed as a bug. label Jul 10, 2020
@ghost
Copy link

ghost commented Jul 10, 2020

Thank you for the bug report. I can reproduce:

mysql>  SELECT DISTINCT count(*), id + int_test as res FROM test  GROUP BY res ORDER BY res;
+----------+-----+
| count(*) | res |
+----------+-----+
|        1 | NULL |
|        1 |  12 |
+----------+-----+
2 rows in set (0.01 sec)

For context, here is the output with column-type-info enabled.

In MySQL 8.0:

mysql [localhost:8020] {msandbox} (test) > SELECT DISTINCT count(*), id + int_test as res FROM test  GROUP BY res ORDER BY res;
Field   1:  `count(*)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     21
Max_length: 1
Decimals:   0
Flags:      NOT_NULL NUM 

Field   2:  `res`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     21
Max_length: 2
Decimals:   0
Flags:      NUM 


+----------+------+
| count(*) | res  |
+----------+------+
|        1 | NULL |
|        1 |   12 |
+----------+------+
2 rows in set (0.00 sec)

In TiDB:

mysql> SELECT DISTINCT count(*), id + int_test as res FROM test  GROUP BY res ORDER BY res;
Field   1:  `count(*)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     21
Max_length: 1
Decimals:   0
Flags:      NOT_NULL BINARY NUM 

Field   2:  `res`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 2
Decimals:   0
Flags:      NOT_NULL BINARY NUM 


+----------+-----+
| count(*) | res |
+----------+-----+
|        1 | NULL |
|        1 |  12 |
+----------+-----+
2 rows in set (0.00 sec)

The bug is because TiDB sets the NOT_NULL flag incorrectly.

@fzhedu
Copy link
Contributor

fzhedu commented Jul 11, 2020

/label component/executor

@ghost
Copy link

ghost commented Aug 5, 2020

This is a regression between TiDB 3.1 and 4.0. I can reproduce on 4.0.1, but not on 3.1.2.

@ghost ghost added the type/regression label Aug 5, 2020
@ghost ghost changed the title [Non-critical] Displayed result is not well formatted NOT_NULL Flag incorrectly set Aug 6, 2020
@github-actions
Copy link

github-actions bot commented Sep 9, 2021

Please check whether the issue should be labeled with 'affects-x.y' or 'backport-x.y.z',
and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug. type/regression
Projects
None yet
5 participants