Loading myisam/mi_search.c +23 −9 Original line number Diff line number Diff line Loading @@ -316,19 +316,21 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, get_key_pack_length(kseg_len,length_pack,kseg); key_len_skip=length_pack+kseg_len; key_len_left=(int) key_len- (int) key_len_skip; /* If key_len is 0, then lenght_pack is 1, then key_len_left is -1. */ cmplen=(key_len_left>=0) ? kseg_len : key_len-length_pack; DBUG_PRINT("info",("key: '%.*s'",kseg_len,kseg)); /* Keys are compressed the following way: If the max length of first key segment <= 127 characters the prefix is If the max length of first key segment <= 127 bytes the prefix is 1 byte else it's 2 byte prefix The high bit is set if this is a prefix for the prev key length Packed length if the previous was a prefix byte [length] Length character of data next-key-seg Next key segments (prefix) length The high bit is set if this is a prefix for the prev key. [suffix length] Packed length of suffix if the previous was a prefix. (suffix) data Key data bytes (past the common prefix or whole segment). [next-key-seg] Next key segments (([packed length], data), ...) pointer Reference to the data file (last_keyseg->length). */ matched=0; /* how many char's from prefix were alredy matched */ Loading @@ -349,16 +351,23 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, if (packed) { if (suffix_len == 0) /* Same key */ if (suffix_len == 0) { /* == 0x80 or 0x8000, same key, prefix length == old key length. */ prefix_len=len; } else { /* > 0x80 or 0x8000, this is prefix lgt, packed suffix lgt follows. */ prefix_len=suffix_len; get_key_length(suffix_len,vseg); } } else { /* Not packed. No prefix used from last key. */ prefix_len=0; } len=prefix_len+suffix_len; seg_len_pack=get_pack_length(len); Loading Loading @@ -414,7 +423,12 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, uint left; uchar *k=kseg+prefix_len; left=(len>cmplen) ? cmplen-prefix_len : suffix_len; /* If prefix_len > cmplen then we are in the end-space comparison phase. Do not try to acces the key any more ==> left= 0. */ left= ((len <= cmplen) ? suffix_len : ((prefix_len < cmplen) ? cmplen - prefix_len : 0)); matched=prefix_len+left; Loading Loading @@ -451,7 +465,7 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, my_flag= -1; else { /* We have to compare k and vseg as if they where space extended */ /* We have to compare k and vseg as if they were space extended */ uchar *end= k+ (cmplen - len); for ( ; k < end && *k == ' '; k++) ; if (k == end) Loading @@ -470,7 +484,7 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, if ((nextflag & SEARCH_PREFIX) && key_len_left == 0) goto fix_flag; /* We have to compare k and vseg as if they where space extended */ /* We have to compare k and vseg as if they were space extended */ for (end=vseg + (len-cmplen) ; vseg < end && *vseg == (uchar) ' '; vseg++, matched++) ; Loading mysql-test/r/alter_table.result +15 −0 Original line number Diff line number Diff line Loading @@ -528,3 +528,18 @@ create table t1 ( a timestamp ); alter table t1 add unique ( a(1) ); ERROR HY000: Incorrect sub part key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique sub keys drop table t1; create database mysqltest1; create table t1 (c1 int); alter table t1 rename mysqltest1.t1; drop table t1; ERROR 42S02: Unknown table 't1' alter table mysqltest1.t1 rename t1; drop table t1; create table t1 (c1 int); use mysqltest1; drop database mysqltest1; alter table test.t1 rename t1; ERROR 3D000: No database selected alter table test.t1 rename test.t1; use test; drop table t1; mysql-test/r/innodb.result +16 −0 Original line number Diff line number Diff line Loading @@ -1658,3 +1658,19 @@ a_id b_list 3 NULL DROP TABLE t2; DROP TABLE t1; create temporary table t1 (a int) engine=innodb; insert into t1 values (4711); truncate t1; insert into t1 values (42); select * from t1; a 42 drop table t1; create table t1 (a int) engine=innodb; insert into t1 values (4711); truncate t1; insert into t1 values (42); select * from t1; a 42 drop table t1; mysql-test/r/key.result +16 −0 Original line number Diff line number Diff line Loading @@ -325,3 +325,19 @@ ERROR 42S21: Duplicate column name 'c1' alter table t1 add key (c1,c1,c2); ERROR 42S21: Duplicate column name 'c1' drop table t1; create table t1 ( c1 int, c2 varchar(20) not null, primary key (c1), key (c2(10)) ) engine=myisam; insert into t1 values (1,''); insert into t1 values (2,' \t\tTest String'); insert into t1 values (3,' \n\tTest String'); update t1 set c2 = 'New Test String' where c1 = 1; select * from t1; c1 c2 1 New Test String 2 Test String 3 Test String mysql-test/r/myisam.result +14 −0 Original line number Diff line number Diff line Loading @@ -595,3 +595,17 @@ show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 1 a 1 a A 8 NULL NULL YES BTREE drop table t1; create table t1 (c1 int); insert into t1 values (1),(2),(3),(4); checksum table t1; Table Checksum test.t1 149057747 delete from t1 where c1 = 1; create table t2 as select * from t1; checksum table t1; Table Checksum test.t1 984116287 checksum table t2; Table Checksum test.t2 984116287 drop table t1, t2; Loading
myisam/mi_search.c +23 −9 Original line number Diff line number Diff line Loading @@ -316,19 +316,21 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, get_key_pack_length(kseg_len,length_pack,kseg); key_len_skip=length_pack+kseg_len; key_len_left=(int) key_len- (int) key_len_skip; /* If key_len is 0, then lenght_pack is 1, then key_len_left is -1. */ cmplen=(key_len_left>=0) ? kseg_len : key_len-length_pack; DBUG_PRINT("info",("key: '%.*s'",kseg_len,kseg)); /* Keys are compressed the following way: If the max length of first key segment <= 127 characters the prefix is If the max length of first key segment <= 127 bytes the prefix is 1 byte else it's 2 byte prefix The high bit is set if this is a prefix for the prev key length Packed length if the previous was a prefix byte [length] Length character of data next-key-seg Next key segments (prefix) length The high bit is set if this is a prefix for the prev key. [suffix length] Packed length of suffix if the previous was a prefix. (suffix) data Key data bytes (past the common prefix or whole segment). [next-key-seg] Next key segments (([packed length], data), ...) pointer Reference to the data file (last_keyseg->length). */ matched=0; /* how many char's from prefix were alredy matched */ Loading @@ -349,16 +351,23 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, if (packed) { if (suffix_len == 0) /* Same key */ if (suffix_len == 0) { /* == 0x80 or 0x8000, same key, prefix length == old key length. */ prefix_len=len; } else { /* > 0x80 or 0x8000, this is prefix lgt, packed suffix lgt follows. */ prefix_len=suffix_len; get_key_length(suffix_len,vseg); } } else { /* Not packed. No prefix used from last key. */ prefix_len=0; } len=prefix_len+suffix_len; seg_len_pack=get_pack_length(len); Loading Loading @@ -414,7 +423,12 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, uint left; uchar *k=kseg+prefix_len; left=(len>cmplen) ? cmplen-prefix_len : suffix_len; /* If prefix_len > cmplen then we are in the end-space comparison phase. Do not try to acces the key any more ==> left= 0. */ left= ((len <= cmplen) ? suffix_len : ((prefix_len < cmplen) ? cmplen - prefix_len : 0)); matched=prefix_len+left; Loading Loading @@ -451,7 +465,7 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, my_flag= -1; else { /* We have to compare k and vseg as if they where space extended */ /* We have to compare k and vseg as if they were space extended */ uchar *end= k+ (cmplen - len); for ( ; k < end && *k == ' '; k++) ; if (k == end) Loading @@ -470,7 +484,7 @@ int _mi_prefix_search(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page, if ((nextflag & SEARCH_PREFIX) && key_len_left == 0) goto fix_flag; /* We have to compare k and vseg as if they where space extended */ /* We have to compare k and vseg as if they were space extended */ for (end=vseg + (len-cmplen) ; vseg < end && *vseg == (uchar) ' '; vseg++, matched++) ; Loading
mysql-test/r/alter_table.result +15 −0 Original line number Diff line number Diff line Loading @@ -528,3 +528,18 @@ create table t1 ( a timestamp ); alter table t1 add unique ( a(1) ); ERROR HY000: Incorrect sub part key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique sub keys drop table t1; create database mysqltest1; create table t1 (c1 int); alter table t1 rename mysqltest1.t1; drop table t1; ERROR 42S02: Unknown table 't1' alter table mysqltest1.t1 rename t1; drop table t1; create table t1 (c1 int); use mysqltest1; drop database mysqltest1; alter table test.t1 rename t1; ERROR 3D000: No database selected alter table test.t1 rename test.t1; use test; drop table t1;
mysql-test/r/innodb.result +16 −0 Original line number Diff line number Diff line Loading @@ -1658,3 +1658,19 @@ a_id b_list 3 NULL DROP TABLE t2; DROP TABLE t1; create temporary table t1 (a int) engine=innodb; insert into t1 values (4711); truncate t1; insert into t1 values (42); select * from t1; a 42 drop table t1; create table t1 (a int) engine=innodb; insert into t1 values (4711); truncate t1; insert into t1 values (42); select * from t1; a 42 drop table t1;
mysql-test/r/key.result +16 −0 Original line number Diff line number Diff line Loading @@ -325,3 +325,19 @@ ERROR 42S21: Duplicate column name 'c1' alter table t1 add key (c1,c1,c2); ERROR 42S21: Duplicate column name 'c1' drop table t1; create table t1 ( c1 int, c2 varchar(20) not null, primary key (c1), key (c2(10)) ) engine=myisam; insert into t1 values (1,''); insert into t1 values (2,' \t\tTest String'); insert into t1 values (3,' \n\tTest String'); update t1 set c2 = 'New Test String' where c1 = 1; select * from t1; c1 c2 1 New Test String 2 Test String 3 Test String
mysql-test/r/myisam.result +14 −0 Original line number Diff line number Diff line Loading @@ -595,3 +595,17 @@ show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 1 a 1 a A 8 NULL NULL YES BTREE drop table t1; create table t1 (c1 int); insert into t1 values (1),(2),(3),(4); checksum table t1; Table Checksum test.t1 149057747 delete from t1 where c1 = 1; create table t2 as select * from t1; checksum table t1; Table Checksum test.t1 984116287 checksum table t2; Table Checksum test.t2 984116287 drop table t1, t2;