Skip to content
Permalink
Browse files
MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for mult…
…i-byte character sets

Field_varstring::sql_type() did not calculate character length correctly.
Using char_length() instead of the bad code.
  • Loading branch information
abarkov committed Jul 24, 2018
1 parent a86a02a commit f74d2a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
@@ -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))

0 comments on commit f74d2a9

Please sign in to comment.