[MDEV-20712] Wrong data type for CAST(@a AS BINARY) for a numeric variable Created: 2019-10-01  Updated: 2019-10-01  Resolved: 2019-10-01

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.5.0

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

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

 Description   

I run this script:

SET NAMES latin1;
SET @a=2;
CREATE OR REPLACE TABLE t1 AS SELECT CAST(1 AS BINARY), CAST(@a AS BINARY), CAST(@b:=3 AS BINARY);
SHOW CREATE TABLE t1;

+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                       |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `CAST(1 AS BINARY)` varbinary(1) DEFAULT NULL,
  `CAST(@a AS BINARY)` varbinary(20) DEFAULT NULL,
  `CAST(@b:=3 AS BINARY)` varbinary(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Looks fine so far.

Now I change the character set to utf8:

SET NAMES utf8;
SET @a=2;
CREATE OR REPLACE TABLE t1 AS SELECT CAST(1 AS BINARY), CAST(@a AS BINARY), CAST(@b:=3 AS BINARY);
SHOW CREATE TABLE t1;

+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                       |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `CAST(1 AS BINARY)` varbinary(1) DEFAULT NULL,
  `CAST(@a AS BINARY)` varbinary(60) DEFAULT NULL,
  `CAST(@b:=3 AS BINARY)` varbinary(3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Notice, the data type has changed for the second and the third columns.
Looks wrong. The behaviour of numeric user variables should not depend on the character set.


Generated at Thu Feb 08 09:01:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.