[MDEV-12607] Hybrid functions create wrong VARBINARY length when mixing character and binary data Created: 2017-04-27  Updated: 2017-04-27  Resolved: 2017-04-27

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

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: datatype

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed

 Description   

I run this script in Linux console:

SET sql_mode='';
SET NAMES utf8;
CREATE OR REPLACE TABLE t1 AS SELECT COALESCE('ßa',_binary 'a');
SHOW WARNINGS;
SELECT * FROM t1;
SHOW CREATE TABLE t1;

Notice, it returns a warning:

+---------+------+------------------------------------------------------------------+
| Level   | Code | Message                                                          |
+---------+------+------------------------------------------------------------------+
| Warning | 1265 | Data truncated for column 'COALESCE('ßa',_binary 'a')' at row 1  |
+---------+------+------------------------------------------------------------------+

The data was indeed truncated:

+-----------------------------+
| COALESCE('ßa',_binary 'a')  |
+-----------------------------+
| ß                           |
+-----------------------------+

And the reason for truncation is a wrong field type:

+-------+-----------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                |
+-------+-----------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `COALESCE('ßa',_binary 'a')` varbinary(2) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=latin1  |
+-------+-----------------------------------------------------------------------------------------------------------------------------+

It should create VARBINARY(3):

SELECT OCTET_LENGTH('ßa');

+---------------------+
| OCTET_LENGTH('ßa')  |
+---------------------+
|                   3 |
+---------------------+


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