Commit f206a123 authored by bar@mysql.com's avatar bar@mysql.com

Bug#15581: COALESCE function truncates mutli-byte TINYTEXT values

field.cc:
  BLOB variations have number-in-bytes limit,
  unlike CHAR/VARCHAR which have number-of-characters limits.
  A tinyblob column can store up to 255 bytes.
  In the case of basic Latin letters (which use 1 byte per character)
  we can store up to 255 characters in a tinyblob column.
  When passing an utf8 tinyblob column as an argument into
  a function (e.g. COALESCE) we need to reserve 3*255 bytes.
  I.e. multiply length in bytes to mbcharlen for the character set.
  Although in reality a tinyblob column can never be 3*255 bytes long,
  we need to set max_length to multiply to make fix_length_and_dec()
  of the function-caller (e.g. COALESCE) calculate the correct max_length
  for the column being created.

ctype_utf8.result, ctype_utf8.test:
  Adding test case.
parent ea4c3481
......@@ -1070,3 +1070,11 @@ char(a)
1
2
drop table t1;
CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8);
INSERT INTO t1 VALUES(REPEAT('a', 100));
CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1;
SELECT LENGTH(bug) FROM t2;
LENGTH(bug)
100
DROP TABLE t2;
DROP TABLE t1;
......@@ -882,4 +882,14 @@ set names utf8;
select distinct char(a) from t1;
drop table t1;
#
# Bug#15581: COALESCE function truncates mutli-byte TINYTEXT values
#
CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8);
INSERT INTO t1 VALUES(REPEAT('a', 100));
CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1;
SELECT LENGTH(bug) FROM t2;
DROP TABLE t2;
DROP TABLE t1;
# End of 4.1 tests
......@@ -6949,11 +6949,11 @@ uint32 Field_blob::max_length()
switch (packlength)
{
case 1:
return 255;
return 255 * field_charset->mbmaxlen;
case 2:
return 65535;
return 65535 * field_charset->mbmaxlen;
case 3:
return 16777215;
return 16777215 * field_charset->mbmaxlen;
case 4:
return (uint32) 4294967295U;
default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment