Commit f74d2a9f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for multi-byte character sets

Field_varstring::sql_type() did not calculate character length correctly.
Using char_length() instead of the bad code.
parent a86a02a8
......@@ -1472,3 +1472,17 @@ SELECT LEFT(a, 10), LENGTH(a) FROM t1;
LEFT(a, 10) LENGTH(a)
aaaaaaaaaa 255
DROP TABLE t1;
#
# MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for multi-byte character sets
#
CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) CHARACTER SET utf8 COMPRESSED);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(1000) /*!100301 COMPRESSED*/ CHARACTER SET utf8 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
COLUMN_TYPE
varchar(1000) /*!100301 COMPRESSED*/
DROP TABLE t1;
......@@ -170,3 +170,14 @@ CREATE TABLE t1(a TINYTEXT COMPRESSED);
INSERT INTO t1 VALUES(REPEAT('a', 255));
SELECT LEFT(a, 10), LENGTH(a) FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for multi-byte character sets
--echo #
CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) CHARACTER SET utf8 COMPRESSED);
SHOW CREATE TABLE t1;
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
DROP TABLE t1;
......@@ -7715,10 +7715,9 @@ void Field_varstring::sql_type(String &res) const
size_t length;
length= cs->cset->snprintf(cs,(char*) res.ptr(),
res.alloced_length(), "%s(%d)",
res.alloced_length(), "%s(%u)",
(has_charset() ? "varchar" : "varbinary"),
(int) field_length / charset()->mbmaxlen -
MY_TEST(compression_method()));
(uint) char_length());
res.length(length);
if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
has_charset() && (charset()->state & MY_CS_BINSORT))
......
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