[MDEV-9745] Crash with CASE WHEN TRUE THEN COALESCE(CAST(NULL AS UNSIGNED)) ELSE 4 END Created: 2016-03-16  Updated: 2016-04-20  Resolved: 2016-04-20

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

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: upstream-not-affected

Issue Links:
Relates
relates to MDEV-9653 Assertion `length || !scale' failed i... Closed
Sprint: 5.5.49

 Description   

This script crashes the server:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 SELECT CASE WHEN TRUE THEN COALESCE(CAST(NULL AS UNSIGNED)) ELSE 4 END AS a;

The problem is not repeatable in MySQL-5.7.11.

It seems it's trying to create a DECIMAL(0,0) column. If I change the script slightly:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 SELECT CASE WHEN TRUE THEN COALESCE(CAST(NULL AS UNSIGNED)) ELSE 40 END AS a;
SHOW CREATE TABLE t1;

it does not crash, but the result is incorrect:

+-------+--------------------------------------------------------------------------------------------+
| Table | Create Table                                                                               |
+-------+--------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` decimal(1,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------+

The field data type DECIMAL(1,0) is too small. It should probably be DECIMAL(2,0).

MySQL-5.7.11 creates a DECIMAL(2,0) column.


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