[MDEV-10309] COALESCE(12345678900) makes a column of a wrong type and truncates the data Created: 2016-06-29  Updated: 2017-06-19  Resolved: 2017-05-27

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.1, 10.2
Fix Version/s: 10.3.1

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-10317 EXCTACT(MINUTE_MICROSECOND) truncates... Closed
relates to MCOL-80 EXTRACT() function returned assertion... Closed

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 AS SELECT 12345678900 AS c1, COALESCE(12345678900) AS c2;
SELECT * FROM t1;
SHOW CREATE TABLE t1;

+-------------+------------+
| c1          | c2         |
+-------------+------------+
| 12345678900 | 2147483647 |
+-------------+------------+

+-------+----------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                   |
+-------+----------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `c1` bigint(11) NOT NULL,
  `c2` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------

The expected result to create a BIGINT column for both expressions, and return 12345678900 for both columns.



 Comments   
Comment by Alexander Barkov [ 2016-06-30 ]

The same problem is repeatable with smaller numbers:

CREATE OR REPLACE TABLE t1 AS SELECT 2147483648 AS c1, COALESCE(2147483648) AS c2;
SHOW CREATE TABLE t1;
SELECT * FROM t1;

+-------+----------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                   |
+-------+----------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `c1` bigint(10) NOT NULL,
  `c2` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------------------------------+

+------------+------------+
| c1         | c2         |
+------------+------------+
| 2147483648 | 2147483647 |
+------------+------------+

Notice, the data type and the value for c2 is wrong.

Comment by Alexander Barkov [ 2017-05-27 ]

Previous fixes in Type_handler
(see the patch for MDEV-12875, MDEV-12886, MDEV-12916)
fixed this problem as well. Adding only the test from the report.

Pushed into bb-10.2-ext.

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