Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.0(EOL), 10.1(EOL), 10.2(EOL)
Description
CREATE OR REPLACE TABLE t1 (a INT, b INT UNSIGNED);
|
INSERT INTO t1 VALUES (0x7FFFFFFF,0xFFFFFFFF);
|
CREATE OR REPLACE TABLE t2 AS SELECT a FROM t1 UNION SELECT b FROM t1;
|
SHOW CREATE TABLE t2;
|
SELECT * FROM t2;
|
returns
+-------+---------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+---------------------------------------------------------------------------------------+
|
| t2 | CREATE TABLE `t2` (
|
`a` int(11) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+---------------------------------------------------------------------------------------+
|
This is wrong, as huge positive unsigned values are converted to negative values:
+------------+
|
| a |
|
+------------+
|
| 2147483647 |
|
| -1 |
|
+------------+
|
Note, unlike UNION, hybrid functions aggregate data types correctly:
CREATE OR REPLACE TABLE t1 (a INT, b INT UNSIGNED);
|
INSERT INTO t1 VALUES (0x7FFFFFFF,0xFFFFFFFF);
|
CREATE OR REPLACE TABLE t2 AS SELECT COALESCE(a,b), COALESCE(b,a) FROM t1;
|
SHOW CREATE TABLE t2;
|
SELECT * FROM t2;
|
returns
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| t2 | CREATE TABLE `t2` (
|
`COALESCE(a,b)` decimal(10,0) DEFAULT NULL,
|
`COALESCE(b,a)` decimal(10,0) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
|
and the values are preserved:
+---------------+---------------+
|
| COALESCE(a,b) | COALESCE(b,a) |
|
+---------------+---------------+
|
| 2147483647 | 4294967295 |
|
+---------------+---------------+
|
Attachments
Issue Links
- blocks
-
MDEV-4912 Data type plugin API version 1
- Closed
- is duplicated by
-
MDEV-14933 Wrong result caused by UNSIGNED column and UNION ALL
- Closed
- relates to
-
MDEV-12775 Reuse data type aggregation code for hybrid functions and UNION
- Closed