[MDEV-12505] Wrong data type for GREATEST(bit_column, int_column) Created: 2017-04-14  Updated: 2017-04-15  Resolved: 2017-04-15

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0
Fix Version/s: 10.1.8

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-8871 Wrong result for CREATE TABLE .. SELE... Closed
Relates
relates to MDEV-12506 Split Item_func_min_max::fix_length_a... Closed

 Description   

This problem was earlier fixed in 10.1 and is not really repeatable in 10.2.

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a BIT(64),b INT);
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF,-1);
SELECT a>b, GREATEST(a,b) FROM t1;

+------+---------------+
| a>b  | GREATEST(a,b) |
+------+---------------+
|    1 | -1            |
+------+---------------+

The value of the first column looks good, as BIT is treated like a unsigned number, according to design.
The value of the second column is wrong. It should return 18446744073709551615.

Now I do:

DROP TABLE IF EXISTS t2;
CREATE TABLE t2 AS SELECT COALESCE(a,b),GREATEST(a,b) FROM t1;
SELECT * FROM t2;

+----------------------+---------------+
| COALESCE(a,b)        | GREATEST(a,b) |
+----------------------+---------------+
| 18446744073709551615 |            -1 |
+----------------------+---------------+

The value of the first column with COALESCE is correct.
The value of the first column with GREATEST is wrong.

Now I check the table structure:

SHOW CREATE TABLE t2;

+-------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                       |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `COALESCE(a,b)` decimal(64,0) DEFAULT NULL,
  `GREATEST(a,b)` bigint(65) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------+

The data type of the first column with COALESCE is correct.
The data type of the second column with GREATEST is wrong.


Generated at Thu Feb 08 07:58:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.