diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index ef7737c6777cf..cbc475cfd8aa1 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -2043,6 +2043,84 @@ t1 CREATE TABLE `t1` ( KEY `b` (`b`(1000)) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=8192 drop table t1; +create table t1 (a int not null, b varchar(512), key (a), key(b)); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + KEY `a` (`a`), + KEY `b` (`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 key_block_size=2048; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=1024, + KEY `b` (`b`) KEY_BLOCK_SIZE=3072 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=2048 +alter table t1 add c int, add key (c); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=1024, + KEY `b` (`b`) KEY_BLOCK_SIZE=4096, + KEY `c` (`c`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=2048 +alter table t1 key_block_size=4096; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=1024, + KEY `b` (`b`), + KEY `c` (`c`) KEY_BLOCK_SIZE=2048 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=4096 +alter table t1 key_block_size=0; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=1024, + KEY `b` (`b`) KEY_BLOCK_SIZE=4096, + KEY `c` (`c`) KEY_BLOCK_SIZE=2048 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 add d int, add key (d); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + `d` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=1024, + KEY `b` (`b`) KEY_BLOCK_SIZE=4096, + KEY `c` (`c`) KEY_BLOCK_SIZE=2048, + KEY `d` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 key_block_size=8192; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(512) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + `d` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=1024, + KEY `b` (`b`) KEY_BLOCK_SIZE=4096, + KEY `c` (`c`) KEY_BLOCK_SIZE=2048, + KEY `d` (`d`) KEY_BLOCK_SIZE=1024 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=8192 +drop table t1; create table t1 (a int not null, b varchar(2048), key (a) key_block_size=1024, key(b)) key_block_size=8192; Warnings: Warning 1071 Specified key was too long; max key length is 1000 bytes diff --git a/mysql-test/suite/maria/maria.result b/mysql-test/suite/maria/maria.result index 805fb536848d8..bd2403ad46198 100644 --- a/mysql-test/suite/maria/maria.result +++ b/mysql-test/suite/maria/maria.result @@ -1904,7 +1904,28 @@ t1 CREATE TABLE `t1` ( KEY `b` (`b`(1000)) KEY_BLOCK_SIZE=8192, KEY `c` (`c`) KEY_BLOCK_SIZE=8192 ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=0 KEY_BLOCK_SIZE=2048 +alter table t1 key_block_size=4096; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(2048) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=8192, + KEY `b` (`b`(1000)) KEY_BLOCK_SIZE=8192, + KEY `c` (`c`) KEY_BLOCK_SIZE=8192 +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=0 KEY_BLOCK_SIZE=4096 alter table t1 key_block_size=0; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(2048) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `a` (`a`) KEY_BLOCK_SIZE=8192, + KEY `b` (`b`(1000)) KEY_BLOCK_SIZE=8192, + KEY `c` (`c`) KEY_BLOCK_SIZE=8192 +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=0 alter table t1 add d int, add key (d); show create table t1; Table Create Table diff --git a/mysql-test/suite/maria/maria.test b/mysql-test/suite/maria/maria.test index 34bd4a638bb93..e4f8d2427c431 100644 --- a/mysql-test/suite/maria/maria.test +++ b/mysql-test/suite/maria/maria.test @@ -1166,7 +1166,10 @@ alter table t1 key_block_size=2048; show create table t1; alter table t1 add c int, add key (c); show create table t1; +alter table t1 key_block_size=4096; +show create table t1; alter table t1 key_block_size=0; +show create table t1; alter table t1 add d int, add key (d); show create table t1; drop table t1; diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 450868721cd74..24f3ff783c9e4 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -1266,6 +1266,22 @@ create table t1 (a int not null, b varchar(2048), key (a), key(b)) key_block_siz show create table t1; drop table t1; +create table t1 (a int not null, b varchar(512), key (a), key(b)); +show create table t1; +alter table t1 key_block_size=2048; +show create table t1; +alter table t1 add c int, add key (c); +show create table t1; +alter table t1 key_block_size=4096; +show create table t1; +alter table t1 key_block_size=0; +show create table t1; +alter table t1 add d int, add key (d); +show create table t1; +alter table t1 key_block_size=8192; +show create table t1; +drop table t1; + create table t1 (a int not null, b varchar(2048), key (a) key_block_size=1024, key(b)) key_block_size=8192; show create table t1; drop table t1; @@ -1274,7 +1290,6 @@ create table t1 (a int not null, b int, key (a) key_block_size=1024, key(b) key_ show create table t1; drop table t1; - # Test limits and errors of key_block_size create table t1 (a int not null, key `a` (a) key_block_size=512); diff --git a/sql/handler.cc b/sql/handler.cc index e5362c7cf9c19..f60cd67edae5a 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -68,7 +68,7 @@ static handlerton *installed_htons[128]; #define BITMAP_STACKBUF_SIZE (128/8) KEY_CREATE_INFO default_key_create_info= -{ HA_KEY_ALG_UNDEF, 0, {NullS, 0}, {NullS, 0}, true }; +{ HA_KEY_ALG_UNDEF, 0, 0, {NullS, 0}, {NullS, 0}, true }; /* number of entries in handlertons[] */ ulong total_ha= 0; diff --git a/sql/handler.h b/sql/handler.h index 29a837b5ea8d3..01d243a4451f5 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -2347,6 +2347,7 @@ typedef struct st_key_create_information { enum ha_key_alg algorithm; ulong block_size; + uint flags; /* HA_USE.. flags */ LEX_CSTRING parser_name; LEX_CSTRING comment; /** diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0201a904058ee..99084152cf2f6 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3847,7 +3847,17 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, key->key_create_info.block_size : create_info->key_block_size); - if (key_info->block_size) + /* + Remember block_size for the future if the block size was given + either for key or table and it was given for the key during + create/alter table or we have an active key_block_size for the + table. + The idea is that table specific key_block_size > 0 will only affect + new keys and old keys will remember their original value. + */ + if (key_info->block_size && + ((key->key_create_info.flags & HA_USES_BLOCK_SIZE) || + create_info->key_block_size)) key_info->flags|= HA_USES_BLOCK_SIZE; List_iterator cols(key->columns), cols2(key->columns); @@ -8408,8 +8418,12 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, LEX_CSTRING tmp_name; bzero((char*) &key_create_info, sizeof(key_create_info)); key_create_info.algorithm= key_info->algorithm; - if (key_info->flags & HA_USES_BLOCK_SIZE) - key_create_info.block_size= key_info->block_size; + /* + We copy block size directly as some engines, like Area, sets this + automatically + */ + key_create_info.block_size= key_info->block_size; + key_create_info.flags= key_info->flags; // HA_USE_BLOCK_SIZE if (key_info->flags & HA_USES_PARSER) key_create_info.parser_name= *plugin_name(key_info->parser); if (key_info->flags & HA_USES_COMMENT) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index fc064748200e5..002ecc654787d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -69,6 +69,7 @@ #include "sql_sequence.h" #include "sql_tvc.h" #include "vers_utils.h" +#include "my_base.h" /* this is to get the bison compilation windows warnings out */ #ifdef _MSC_VER @@ -7518,7 +7519,10 @@ key_using_alg: all_key_opt: KEY_BLOCK_SIZE opt_equal ulong_num - { Lex->last_key->key_create_info.block_size= $3; } + { + Lex->last_key->key_create_info.block_size= $3; + Lex->last_key->key_create_info.flags|= HA_USES_BLOCK_SIZE; + } | COMMENT_SYM TEXT_STRING_sys { Lex->last_key->key_create_info.comment= $2; } | IDENT_sys equal TEXT_STRING_sys diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 3cc7b585ea447..2d171496337f5 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -7351,7 +7351,10 @@ key_using_alg: all_key_opt: KEY_BLOCK_SIZE opt_equal ulong_num - { Lex->last_key->key_create_info.block_size= $3; } + { + Lex->create_info.used_fields|= HA_USES_BLOCK_SIZE; + Lex->create_info.key_block_size= $3; + } | COMMENT_SYM TEXT_STRING_sys { Lex->last_key->key_create_info.comment= $2; } | IDENT_sys equal TEXT_STRING_sys