Commit bf7a9ad2 authored by unknown's avatar unknown

Fixed bug #29205.

When a UNION statement forced conversion of an UTF8
charset value to a binary charset value, the byte
length of the result values was truncated to the
CHAR_LENGTH of the original UTF8 value.


sql/item.cc:
  Fixed bug #29205.
  The calculation of data length was modified in
  the Item_type_holder::join_types method to take into
  account possible conversion of a multibyte charset
  value to a binary charset value, when each
  multibyte character is converted into a sequence
  of bytes (not to a single byte of binary charset).
mysql-test/t/ctype_utf8.test:
  Updated test case for bug #29205.
mysql-test/r/ctype_utf8.result:
  Updated test case for bug #29205.
parent 8a8e2767
......@@ -1657,3 +1657,40 @@ colA colB colA colB
1 foo 1 foo
2 foo bar 2 foo bar
DROP TABLE t1, t2;
SELECT 'н1234567890' UNION SELECT _binary '1';
н1234567890
н1234567890
1
SELECT 'н1234567890' UNION SELECT 1;
н1234567890
н1234567890
1
SELECT '1' UNION SELECT 'н1234567890';
1
1
н1234567890
SELECT 1 UNION SELECT 'н1234567890';
1
1
н1234567890
CREATE TABLE t1 (c VARCHAR(11)) CHARACTER SET utf8;
CREATE TABLE t2 (b CHAR(1) CHARACTER SET binary, i INT);
INSERT INTO t1 (c) VALUES ('н1234567890');
INSERT INTO t2 (b, i) VALUES ('1', 1);
SELECT c FROM t1 UNION SELECT b FROM t2;
c
н1234567890
1
SELECT c FROM t1 UNION SELECT i FROM t2;
c
н1234567890
1
SELECT b FROM t2 UNION SELECT c FROM t1;
b
1
н1234567890
SELECT i FROM t2 UNION SELECT c FROM t1;
i
1
н1234567890
DROP TABLE t1, t2;
......@@ -1338,3 +1338,28 @@ INSERT INTO t2 (colA, colB) VALUES (1, 'foo'),(2, 'foo bar');
SELECT * FROM t1 JOIN t2 ON t1.colA=t2.colA AND t1.colB=t2.colB
WHERE t1.colA < 3;
DROP TABLE t1, t2;
#
# Bug#29205: truncation of UTF8 values when the UNION statement
# forces collation to the binary charset
#
SELECT 'н1234567890' UNION SELECT _binary '1';
SELECT 'н1234567890' UNION SELECT 1;
SELECT '1' UNION SELECT 'н1234567890';
SELECT 1 UNION SELECT 'н1234567890';
CREATE TABLE t1 (c VARCHAR(11)) CHARACTER SET utf8;
CREATE TABLE t2 (b CHAR(1) CHARACTER SET binary, i INT);
INSERT INTO t1 (c) VALUES ('н1234567890');
INSERT INTO t2 (b, i) VALUES ('1', 1);
SELECT c FROM t1 UNION SELECT b FROM t2;
SELECT c FROM t1 UNION SELECT i FROM t2;
SELECT b FROM t2 UNION SELECT c FROM t1;
SELECT i FROM t2 UNION SELECT c FROM t1;
DROP TABLE t1, t2;
......@@ -6595,9 +6595,15 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
expansion of the size of the values because of character set
conversions.
*/
max_length= max(old_max_chars * collation.collation->mbmaxlen,
display_length(item) / item->collation.collation->mbmaxlen *
collation.collation->mbmaxlen);
if (collation.collation != &my_charset_bin)
{
max_length= max(old_max_chars * collation.collation->mbmaxlen,
display_length(item) /
item->collation.collation->mbmaxlen *
collation.collation->mbmaxlen);
}
else
set_if_bigger(max_length, display_length(item));
break;
}
case REAL_RESULT:
......
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