Commit 93cf297f authored by unknown's avatar unknown
Browse files

Cleanups during review stage

Added auto-correct of field length for enum/set tables for ALTER TABLE
This is becasue of a bug in previous MySQL 4.1 versions where the length for enum/set was set incorrectly after ALTER TABLE


mysql-test/r/rpl_start_stop_slave.result:
  Fixed wrong test
mysql-test/r/type_enum.result:
  Added test for wrong enum/set length after alter table
mysql-test/t/ps.test:
  removed empty line
mysql-test/t/type_enum.test:
  Added test for wrong enum/set length after alter table
sql/field.cc:
  Added auto-correct of field length for enum/set tables.
  This is becasue of a bug in previous MySQL 4.1 versions where the length for enum/set was set incorrectly after ALTER TABLE
sql/item_cmpfunc.cc:
  Simple optimization
sql/mysql_priv.h:
  Made local function global
sql/set_var.cc:
  Simple cleanup
sql/sql_table.cc:
  Simple cleanups & optimizations
parent b18b1be9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
slave stop;
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
slave start;
start slave;
stop slave;
create table t1(n int);
start slave;
+12 −0
Original line number Diff line number Diff line
@@ -1693,3 +1693,15 @@ oe
ue
ss
DROP TABLE t1;
create table t1 (a enum ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin);
insert into t1 values ('Y');
alter table t1 add b set ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin;
alter table t1 add c enum ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin;
select * from t1;
Catalog	Database	Table	Table_alias	Column	Column_alias	Name	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
def	test	t1	t1	a	a	254	3	1	Y	384	0	8
def	test	t1	t1	b	b	254	9	0	Y	2176	0	8
def	test	t1	t1	c	c	254	3	0	Y	384	0	8
a	b	c
Y	NULL	NULL
drop table t1;
+0 −1
Original line number Diff line number Diff line
@@ -471,4 +471,3 @@ execute stmt using @var, @var, @var;
set @var=null;
select @var is null, @var is not null, @var;
execute stmt using @var, @var, @var;
+13 −0
Original line number Diff line number Diff line
@@ -72,3 +72,16 @@ CREATE TABLE t1 (c enum('ae','oe','ue','ss') collate latin1_german2_ci);
INSERT INTO t1 VALUES (''),(''),(''),('');
SELECT * FROM t1;
DROP TABLE t1;

#
# Test bug where enum fields where extended for each ALTER TABLE
#

create table t1 (a enum ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin);
insert into t1 values ('Y');
alter table t1 add b set ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin;
alter table t1 add c enum ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin;
--enable_metadata
select * from t1;
--disable metadata
drop table t1;
+42 −18
Original line number Diff line number Diff line
@@ -5842,8 +5842,7 @@ bool Field_num::eq_def(Field *field)

void create_field::create_length_to_internal_length(void)
{
  switch (sql_type)
  {
  switch (sql_type) {
  case MYSQL_TYPE_TINY_BLOB:
  case MYSQL_TYPE_MEDIUM_BLOB:
  case MYSQL_TYPE_LONG_BLOB:
@@ -5854,10 +5853,33 @@ 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;
#ifdef CORRECT_CODE_BUT_CANT_YET_BE_USED
  case MYSQL_TYPE_ENUM:
  case MYSQL_TYPE_SET:
    length*= charset->mbmaxlen;
    break;
#else
    /*
      Because of a bug in MySQL 4.1 where length was extended for ENUM and SET
      fields for every ALTER TABLE, we have to recalculate lengths here
    */
  case MYSQL_TYPE_ENUM:
  {
    uint32 tot_length, max_length;
    calculate_interval_lengths(current_thd, interval,
                               &max_length, &tot_length);
    length= max_length * charset->mbmaxlen;
    break;
  }
  case MYSQL_TYPE_SET:
  {
    uint32 tot_length, max_length;
    calculate_interval_lengths(current_thd, interval,
                               &max_length, &tot_length);
    length= (tot_length + (interval->count - 1)) * charset->mbmaxlen;
    break;
  }
#endif
  default:
    /* do nothing */
    break;
@@ -6085,6 +6107,8 @@ create_field::create_field(Field *old_field,Field *orig_field)
      }
      length=(length+charset->mbmaxlen-1)/charset->mbmaxlen; // QQ: Probably not needed
      break;
    case MYSQL_TYPE_ENUM:
    case MYSQL_TYPE_SET:
    case FIELD_TYPE_STRING:
    case FIELD_TYPE_VAR_STRING:
      length=(length+charset->mbmaxlen-1)/charset->mbmaxlen;
Loading