Fix for bug#19236 bad COLUMNS.CHARACTER_MAXIMUM_LENGHT and CHARACTER_OCTET_LENGTH

parent d1417ad5
...@@ -1091,3 +1091,11 @@ group by column_type order by num; ...@@ -1091,3 +1091,11 @@ group by column_type order by num;
column_type group_concat(table_schema, '.', table_name) num column_type group_concat(table_schema, '.', table_name) num
varchar(20) information_schema.COLUMNS 1 varchar(20) information_schema.COLUMNS 1
varchar(7) information_schema.ROUTINES,information_schema.VIEWS 2 varchar(7) information_schema.ROUTINES,information_schema.VIEWS 2
create table t1(f1 char(1) not null, f2 char(9) not null)
default character set utf8;
select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from
information_schema.columns where table_schema='test' and table_name = 't1';
CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH
1 3
9 27
drop table t1;
...@@ -700,8 +700,8 @@ ERROR 42S22: Unknown column 't1.b' in 'on clause' ...@@ -700,8 +700,8 @@ ERROR 42S22: Unknown column 't1.b' in 'on clause'
select * from information_schema.statistics join information_schema.columns select * from information_schema.statistics join information_schema.columns
using(table_name,column_name) where table_name='user'; using(table_name,column_name) where table_name='user';
TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT
user Host NULL mysql 0 mysql PRIMARY 1 A NULL NULL NULL BTREE NULL mysql 1 NO char 20 60 NULL NULL utf8 utf8_bin char(60) PRI select,insert,update,references user Host NULL mysql 0 mysql PRIMARY 1 A NULL NULL NULL BTREE NULL mysql 1 NO char 60 180 NULL NULL utf8 utf8_bin char(60) PRI select,insert,update,references
user User NULL mysql 0 mysql PRIMARY 2 A 5 NULL NULL BTREE NULL mysql 2 NO char 5 16 NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references user User NULL mysql 0 mysql PRIMARY 2 A 5 NULL NULL BTREE NULL mysql 2 NO char 16 48 NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references
drop table t1; drop table t1;
drop table t2; drop table t2;
drop table t3; drop table t3;
......
...@@ -802,3 +802,12 @@ from information_schema.columns where ...@@ -802,3 +802,12 @@ from information_schema.columns where
table_schema='information_schema' and table_schema='information_schema' and
(column_type = 'varchar(7)' or column_type = 'varchar(20)') (column_type = 'varchar(7)' or column_type = 'varchar(20)')
group by column_type order by num; group by column_type order by num;
#
# Bug#19236 bad COLUMNS.CHARACTER_MAXIMUM_LENGHT and CHARACTER_OCTET_LENGTH
#
create table t1(f1 char(1) not null, f2 char(9) not null)
default character set utf8;
select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from
information_schema.columns where table_schema='test' and table_name = 't1';
drop table t1;
...@@ -2662,7 +2662,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables, ...@@ -2662,7 +2662,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
field->real_type() == MYSQL_TYPE_STRING) // For binary type field->real_type() == MYSQL_TYPE_STRING) // For binary type
{ {
uint32 octet_max_length= field->max_length(); uint32 octet_max_length= field->max_length();
if (octet_max_length != (uint32) 4294967295U) if (is_blob && octet_max_length != (uint32) 4294967295U)
octet_max_length /= field->charset()->mbmaxlen; octet_max_length /= field->charset()->mbmaxlen;
longlong char_max_len= is_blob ? longlong char_max_len= is_blob ?
(longlong) octet_max_length / field->charset()->mbminlen : (longlong) octet_max_length / field->charset()->mbminlen :
......
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