Skip to content

Commit

Permalink
Fixed alter online table for Aria tables
Browse files Browse the repository at this point in the history
fill_alter_table() always thought that index was changed because of
of a wrong check of block_size. Some engines had code to correct this
that should not be needed, Aria didn't and because of this some online
operations didn't work.

This code fixes the comparision of block_size to only compare if it's set.
  • Loading branch information
montywi committed Mar 29, 2018
1 parent 209375f commit c3f37c0
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 7 deletions.
78 changes: 78 additions & 0 deletions mysql-test/r/myisam.result
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions mysql-test/suite/maria/maria.result
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/maria/maria.test
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion mysql-test/t/myisam.test
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sql/handler.cc
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sql/handler.h
Expand Up @@ -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;
/**
Expand Down
20 changes: 17 additions & 3 deletions sql/sql_table.cc
Expand Up @@ -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<Key_part_spec> cols(key->columns), cols2(key->columns);
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion sql/sql_yacc.yy
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion sql/sql_yacc_ora.yy
Expand Up @@ -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
Expand Down

0 comments on commit c3f37c0

Please sign in to comment.