Bug #101801 | Client parses results of long long type as bit type and displays wrong results | ||
---|---|---|---|
Submitted: | 30 Nov 2020 12:34 | Modified: | 30 Nov 2020 14:55 |
Reporter: | Hope Lee (OCA) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Command-line Clients | Severity: | S2 (Serious) |
Version: | 8.0.22 | OS: | CentOS |
Assigned to: | CPU Architecture: | Any |
[30 Nov 2020 12:34]
Hope Lee
[30 Nov 2020 13:13]
MySQL Verification Team
Hello Hope Lee , Thank you for the report and feedback. I'm not seeing any issues at my end while checking on 8.0.22. Am I missing anything? Please let us know. - bin/mysql -uroot -S /tmp/mysql_ushastry.sock --column-type-info Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database test; Query OK, 1 row affected (0.02 sec) mysql> use test Database changed mysql> CREATE TABLE t1(a BIT(3), b BIT(9), c INT, d INT); Query OK, 0 rows affected (0.06 sec) mysql> INSERT INTO t1 VALUES (b'111', b'111110101', 0, 1), (b'000', b'010000101', 1, 1); Query OK, 2 rows affected (0.01 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> SELECT MAX(CASE WHEN c = 0 THEN a ELSE b END) FROM t1 GROUP BY d; Field 1: `MAX(CASE WHEN c = 0 THEN a ELSE b END)` Catalog: `def` Database: `` Table: `` Org_table: `` Type: LONGLONG Collation: binary (63) Length: 9 Max_length: 3 Decimals: 0 Flags: UNSIGNED NUM +----------------------------------------+ | MAX(CASE WHEN c = 0 THEN a ELSE b END) | +----------------------------------------+ | 133 | +----------------------------------------+ 1 row in set (0.00 sec) regards, Umesh
[30 Nov 2020 13:23]
Hope Lee
Sorry, that's my fault to leave out something. Can you add an index and try again? Using the following SQL: CREATE INDEX i1 ON t1(d); root@localhost:test 8.0.22-rds-dev-debug> EXPLAIN SELECT MAX(CASE WHEN c = 0 THEN a ELSE b END) FROM t1 GROUP BY d; +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------+ | 1 | SIMPLE | t1 | NULL | index | i1 | i1 | 5 | NULL | 2 | 100.00 | NULL | +----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+-------+ 1 row in set, 1 warning (0.00 sec) root@localhost:test 8.0.22-rds-dev-debug> SELECT MAX(CASE WHEN c = 0 THEN a ELSE b END) FROM t1 GROUP BY d; +--------------------------------------------------------------------------------+ | MAX(CASE WHEN c = 0 THEN a ELSE b END) | +--------------------------------------------------------------------------------+ | 0x313333 | +--------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
[30 Nov 2020 14:55]
MySQL Verification Team
Thank you, Lee. Verified as described. regards, Umesh
[30 Nov 2020 14:58]
Frederic Descamps
Mmmm, something even more strange is when you use MySQL Shell: Without index: SQL SELECT MAX(CASE WHEN c = 0 THEN a ELSE b END) FROM test.t1 GROUP BY d; +----------------------------------------+ | MAX(CASE WHEN c = 0 THEN a ELSE b END) | +----------------------------------------+ | 133 | +----------------------------------------+ With the index: SQL SELECT MAX(CASE WHEN c = 0 THEN a ELSE b END) FROM test.t1 GROUP BY d; +----------------------------------------+ | MAX(CASE WHEN c = 0 THEN a ELSE b END) | +----------------------------------------+ | 307 | +----------------------------------------+