[MDEV-9319] ALTER from a bigger to a smaller blob type truncates too much data Created: 2015-12-24  Updated: 2017-10-12  Resolved: 2015-12-29

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 5.5, 10.0, 10.1, 10.2
Fix Version/s: 5.5.48, 10.0.24, 10.1.11

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

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-13530 VARBINARY doesn't convert to to BLOB ... Closed

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a BLOB) ENGINE=MyISAM;
INSERT INTO t1 VALUES (REPEAT(0x61,65000));
SELECT LENGTH(a) FROM t1;
ALTER TABLE t1 MODIFY a TINYBLOB;
SELECT LENGTH(a) FROM t1;

returns 65000 before ALTER:

+-----------+
| LENGTH(a) |
+-----------+
|     65000 |
+-----------+

and returns 232 after ALTER:

+-----------+
| LENGTH(a) |
+-----------+
|       232 |
+-----------+

This looks wrong. The expected length after ALTER is 255.

It also does not produce any warnings on truncation. Probably it should.



 Comments   
Comment by Alexander Barkov [ 2015-12-24 ]

In case of a multi-byte TEXT field, truncation breaks characters apart:

SET NAMES utf8;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TEXT CHARACTER SET utf8) ENGINE=MyISAM;
INSERT INTO t1 VALUES (REPEAT('A',100));
SELECT OCTET_LENGTH(a) FROM t1;
ALTER TABLE t1 MODIFY a TINYTEXT CHARACTER SET utf8;
SELECT OCTET_LENGTH(a),a FROM t1;

+-----------------+----------------------------------------------+
| OCTET_LENGTH(a) | a                                            |
+-----------------+----------------------------------------------+
|              44 | AAAAAAAAAAAAAA??                 |
+-----------------+----------------------------------------------+

Notice the the garbage at the end.

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