Commit 467f5956 authored by unknown's avatar unknown
Browse files

CSC issue # 3299 fix:

ENUM and SET type didn't compute their length correctly.
That showed up for example while converting into a CHAR column.

parent e2cfe7b6
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
drop table if exists t1;
drop table if exists t2;
set names utf8;
select left(_utf8 0xD0B0D0B1D0B2,1);
left(_utf8 0xD0B0D0B1D0B2,1)
@@ -246,6 +247,28 @@ select 'zвасяz' rlike '[[:<:]]вася[[:>:]]';
CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8_unicode_ci);
ALTER TABLE t1 ADD COLUMN b CHAR(20);
DROP TABLE t1;
set names utf8;
create table t1 (a enum('aaaa','проба') character set utf8);
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` enum('aaaa','проба') character set utf8 default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values ('проба');
select * from t1;
a
проба
create table t2 select ifnull(a,a) from t1;
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `ifnull(a,a)` char(5) character set utf8 default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t2;
ifnull(a,a)
проба
drop table t1;
drop table t2;
create table t1 (c varchar(30) character set utf8, unique(c(10)));
insert into t1 values ('1'),('2'),('3'),('x'),('y'),('z');
insert into t1 values ('aaaaaaaaaa');
+16 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

--disable_warnings
drop table if exists t1;
drop table if exists t2;
--enable_warnings
set names utf8;

@@ -172,6 +173,20 @@ CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8_unicode_ci);
ALTER TABLE t1 ADD COLUMN b CHAR(20);
DROP TABLE t1;

# Customer Support Center issue # 3299 
# ENUM and SET multibyte fields computed their length wronly 
# when converted into a char field
set names utf8;
create table t1 (a enum('aaaa','проба') character set utf8);
show create table t1;
insert into t1 values ('проба');
select * from t1;
create table t2 select ifnull(a,a) from t1;
show create table t2;
select * from t2;
drop table t1;
drop table t2;

#
# Bug 4521: unique key prefix interacts poorly with utf8
# Check keys with prefix compression
@@ -220,3 +235,4 @@ insert into t1 values ('ꪪꪪ');
--error 1062
insert into t1 values ('ꪪꪪꪪ');
drop table t1;
+4 −0
Original line number Diff line number Diff line
@@ -5667,6 +5667,10 @@ void create_field::create_length_to_internal_length(void)
      pack_length= calc_pack_length(sql_type == FIELD_TYPE_VAR_STRING ?
				    FIELD_TYPE_STRING : sql_type, length);
      break;
    case MYSQL_TYPE_ENUM:
    case MYSQL_TYPE_SET:
      length*= charset->mbmaxlen;
      break;
    default:
      /* do nothing */
      break;
+8 −3
Original line number Diff line number Diff line
@@ -4381,7 +4381,10 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
      new_field->length=0;
      for (const char **pos=interval->type_names; *pos ; pos++)
      {
	new_field->length+=(uint) strip_sp((char*) *pos)+1;
        uint length= (uint) strip_sp((char*) *pos)+1;
        CHARSET_INFO *cs= thd->variables.character_set_client;
        length= cs->cset->numchars(cs, *pos, *pos+length);
        new_field->length+= length;
      }
      new_field->length--;
      set_if_smaller(new_field->length,MAX_FIELD_WIDTH-1);
@@ -4412,6 +4415,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
      for (const char **pos=interval->type_names+1; *pos ; pos++)
      {
        uint length=(uint) strip_sp((char*) *pos);
        CHARSET_INFO *cs= thd->variables.character_set_client;
        length= cs->cset->numchars(cs, *pos, *pos+length);
        set_if_bigger(new_field->length,length);
      }
      set_if_smaller(new_field->length,MAX_FIELD_WIDTH-1);