← Back to team overview

maria-developers team mailing list archive

Please review MDEV-16134 Wrong I_S.COLUMNS.CHARACTER_XXX_LENGTH value for compressed columns

 

Hi Sergey,

Please review a patch for MDEV-16134.

Thanks!
diff --git a/mysql-test/main/column_compression.result b/mysql-test/main/column_compression.result
index c521a20..f4eb046 100644
--- a/mysql-test/main/column_compression.result
+++ b/mysql-test/main/column_compression.result
@@ -1403,3 +1403,19 @@ SELECT CHAR_LENGTH(a), CHAR_LENGTH(b), LEFT(a, 10), LEFT(b, 10) FROM t1;
 CHAR_LENGTH(a)	CHAR_LENGTH(b)	LEFT(a, 10)	LEFT(b, 10)
 254	254	aaaaaaaaaa	aaaaaaaaaa
 DROP TABLE t1;
+#
+# MDEV-16134 Wrong I_S.COLUMNS.CHARACTER_XXX_LENGTH value for compressed columns
+#
+CREATE TABLE t1
+(
+a VARCHAR(10) CHARACTER SET latin1 COMPRESSED,
+b VARCHAR(10) CHARACTER SET utf8 COMPRESSED
+);
+SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH
+FROM INFORMATION_SCHEMA.COLUMNS
+WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1' AND COLUMN_NAME IN ('a','b')
+ORDER BY COLUMN_NAME;
+COLUMN_NAME	CHARACTER_MAXIMUM_LENGTH	CHARACTER_OCTET_LENGTH
+a	10	10
+b	10	30
+DROP TABLE t1;
diff --git a/mysql-test/main/column_compression.test b/mysql-test/main/column_compression.test
index 5590c99..cdd9adb 100644
--- a/mysql-test/main/column_compression.test
+++ b/mysql-test/main/column_compression.test
@@ -120,3 +120,19 @@ CREATE TABLE t1(a TINYTEXT COMPRESSED, b TINYTEXT) CHARACTER SET utf8;
 INSERT INTO t1 VALUES (REPEAT(_latin1'a', 254), REPEAT(_latin1'a', 254));
 SELECT CHAR_LENGTH(a), CHAR_LENGTH(b), LEFT(a, 10), LEFT(b, 10) FROM t1;
 DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-16134 Wrong I_S.COLUMNS.CHARACTER_XXX_LENGTH value for compressed columns
+--echo #
+
+CREATE TABLE t1
+(
+  a VARCHAR(10) CHARACTER SET latin1 COMPRESSED,
+  b VARCHAR(10) CHARACTER SET utf8 COMPRESSED
+);
+SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH
+FROM INFORMATION_SCHEMA.COLUMNS
+WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1' AND COLUMN_NAME IN ('a','b')
+ORDER BY COLUMN_NAME;
+DROP TABLE t1;
diff --git a/sql/field.h b/sql/field.h
index 50ee5b7..baed151 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1737,7 +1737,7 @@ class Field_str :public Field {
   Information_schema_character_attributes
     information_schema_character_attributes() const
   {
-    return Information_schema_character_attributes(field_length,
+    return Information_schema_character_attributes(max_display_length(),
                                                    char_length());
   }
   friend class Create_field;
@@ -3448,6 +3448,10 @@ class Field_varstring_compressed: public Field_varstring {
     str.append(STRING_WITH_LEN(" /*!100301 COMPRESSED*/"));
   }
   uint32 max_display_length() const { return field_length - 1; }
+  uint32 char_length() const
+  {
+    return (field_length - 1) / field_charset->mbmaxlen;
+  }
   int cmp_max(const uchar *a_ptr, const uchar *b_ptr, uint max_len);
 
   /*