Skip to content

Commit c3f37c0

Browse files
committed
Fixed alter online table for Aria tables
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.
1 parent 209375f commit c3f37c0

File tree

9 files changed

+146
-7
lines changed

9 files changed

+146
-7
lines changed

mysql-test/r/myisam.result

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,84 @@ t1 CREATE TABLE `t1` (
20432043
KEY `b` (`b`(1000))
20442044
) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=8192
20452045
drop table t1;
2046+
create table t1 (a int not null, b varchar(512), key (a), key(b));
2047+
show create table t1;
2048+
Table Create Table
2049+
t1 CREATE TABLE `t1` (
2050+
`a` int(11) NOT NULL,
2051+
`b` varchar(512) DEFAULT NULL,
2052+
KEY `a` (`a`),
2053+
KEY `b` (`b`)
2054+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2055+
alter table t1 key_block_size=2048;
2056+
show create table t1;
2057+
Table Create Table
2058+
t1 CREATE TABLE `t1` (
2059+
`a` int(11) NOT NULL,
2060+
`b` varchar(512) DEFAULT NULL,
2061+
KEY `a` (`a`) KEY_BLOCK_SIZE=1024,
2062+
KEY `b` (`b`) KEY_BLOCK_SIZE=3072
2063+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=2048
2064+
alter table t1 add c int, add key (c);
2065+
show create table t1;
2066+
Table Create Table
2067+
t1 CREATE TABLE `t1` (
2068+
`a` int(11) NOT NULL,
2069+
`b` varchar(512) DEFAULT NULL,
2070+
`c` int(11) DEFAULT NULL,
2071+
KEY `a` (`a`) KEY_BLOCK_SIZE=1024,
2072+
KEY `b` (`b`) KEY_BLOCK_SIZE=4096,
2073+
KEY `c` (`c`)
2074+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=2048
2075+
alter table t1 key_block_size=4096;
2076+
show create table t1;
2077+
Table Create Table
2078+
t1 CREATE TABLE `t1` (
2079+
`a` int(11) NOT NULL,
2080+
`b` varchar(512) DEFAULT NULL,
2081+
`c` int(11) DEFAULT NULL,
2082+
KEY `a` (`a`) KEY_BLOCK_SIZE=1024,
2083+
KEY `b` (`b`),
2084+
KEY `c` (`c`) KEY_BLOCK_SIZE=2048
2085+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=4096
2086+
alter table t1 key_block_size=0;
2087+
show create table t1;
2088+
Table Create Table
2089+
t1 CREATE TABLE `t1` (
2090+
`a` int(11) NOT NULL,
2091+
`b` varchar(512) DEFAULT NULL,
2092+
`c` int(11) DEFAULT NULL,
2093+
KEY `a` (`a`) KEY_BLOCK_SIZE=1024,
2094+
KEY `b` (`b`) KEY_BLOCK_SIZE=4096,
2095+
KEY `c` (`c`) KEY_BLOCK_SIZE=2048
2096+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2097+
alter table t1 add d int, add key (d);
2098+
show create table t1;
2099+
Table Create Table
2100+
t1 CREATE TABLE `t1` (
2101+
`a` int(11) NOT NULL,
2102+
`b` varchar(512) DEFAULT NULL,
2103+
`c` int(11) DEFAULT NULL,
2104+
`d` int(11) DEFAULT NULL,
2105+
KEY `a` (`a`) KEY_BLOCK_SIZE=1024,
2106+
KEY `b` (`b`) KEY_BLOCK_SIZE=4096,
2107+
KEY `c` (`c`) KEY_BLOCK_SIZE=2048,
2108+
KEY `d` (`d`)
2109+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2110+
alter table t1 key_block_size=8192;
2111+
show create table t1;
2112+
Table Create Table
2113+
t1 CREATE TABLE `t1` (
2114+
`a` int(11) NOT NULL,
2115+
`b` varchar(512) DEFAULT NULL,
2116+
`c` int(11) DEFAULT NULL,
2117+
`d` int(11) DEFAULT NULL,
2118+
KEY `a` (`a`) KEY_BLOCK_SIZE=1024,
2119+
KEY `b` (`b`) KEY_BLOCK_SIZE=4096,
2120+
KEY `c` (`c`) KEY_BLOCK_SIZE=2048,
2121+
KEY `d` (`d`) KEY_BLOCK_SIZE=1024
2122+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 KEY_BLOCK_SIZE=8192
2123+
drop table t1;
20462124
create table t1 (a int not null, b varchar(2048), key (a) key_block_size=1024, key(b)) key_block_size=8192;
20472125
Warnings:
20482126
Warning 1071 Specified key was too long; max key length is 1000 bytes

mysql-test/suite/maria/maria.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,28 @@ t1 CREATE TABLE `t1` (
19041904
KEY `b` (`b`(1000)) KEY_BLOCK_SIZE=8192,
19051905
KEY `c` (`c`) KEY_BLOCK_SIZE=8192
19061906
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=0 KEY_BLOCK_SIZE=2048
1907+
alter table t1 key_block_size=4096;
1908+
show create table t1;
1909+
Table Create Table
1910+
t1 CREATE TABLE `t1` (
1911+
`a` int(11) NOT NULL,
1912+
`b` varchar(2048) DEFAULT NULL,
1913+
`c` int(11) DEFAULT NULL,
1914+
KEY `a` (`a`) KEY_BLOCK_SIZE=8192,
1915+
KEY `b` (`b`(1000)) KEY_BLOCK_SIZE=8192,
1916+
KEY `c` (`c`) KEY_BLOCK_SIZE=8192
1917+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=0 KEY_BLOCK_SIZE=4096
19071918
alter table t1 key_block_size=0;
1919+
show create table t1;
1920+
Table Create Table
1921+
t1 CREATE TABLE `t1` (
1922+
`a` int(11) NOT NULL,
1923+
`b` varchar(2048) DEFAULT NULL,
1924+
`c` int(11) DEFAULT NULL,
1925+
KEY `a` (`a`) KEY_BLOCK_SIZE=8192,
1926+
KEY `b` (`b`(1000)) KEY_BLOCK_SIZE=8192,
1927+
KEY `c` (`c`) KEY_BLOCK_SIZE=8192
1928+
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=0
19081929
alter table t1 add d int, add key (d);
19091930
show create table t1;
19101931
Table Create Table

mysql-test/suite/maria/maria.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,10 @@ alter table t1 key_block_size=2048;
11661166
show create table t1;
11671167
alter table t1 add c int, add key (c);
11681168
show create table t1;
1169+
alter table t1 key_block_size=4096;
1170+
show create table t1;
11691171
alter table t1 key_block_size=0;
1172+
show create table t1;
11701173
alter table t1 add d int, add key (d);
11711174
show create table t1;
11721175
drop table t1;

mysql-test/t/myisam.test

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,22 @@ create table t1 (a int not null, b varchar(2048), key (a), key(b)) key_block_siz
12661266
show create table t1;
12671267
drop table t1;
12681268

1269+
create table t1 (a int not null, b varchar(512), key (a), key(b));
1270+
show create table t1;
1271+
alter table t1 key_block_size=2048;
1272+
show create table t1;
1273+
alter table t1 add c int, add key (c);
1274+
show create table t1;
1275+
alter table t1 key_block_size=4096;
1276+
show create table t1;
1277+
alter table t1 key_block_size=0;
1278+
show create table t1;
1279+
alter table t1 add d int, add key (d);
1280+
show create table t1;
1281+
alter table t1 key_block_size=8192;
1282+
show create table t1;
1283+
drop table t1;
1284+
12691285
create table t1 (a int not null, b varchar(2048), key (a) key_block_size=1024, key(b)) key_block_size=8192;
12701286
show create table t1;
12711287
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_
12741290
show create table t1;
12751291
drop table t1;
12761292

1277-
12781293
# Test limits and errors of key_block_size
12791294

12801295
create table t1 (a int not null, key `a` (a) key_block_size=512);

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static handlerton *installed_htons[128];
6868
#define BITMAP_STACKBUF_SIZE (128/8)
6969

7070
KEY_CREATE_INFO default_key_create_info=
71-
{ HA_KEY_ALG_UNDEF, 0, {NullS, 0}, {NullS, 0}, true };
71+
{ HA_KEY_ALG_UNDEF, 0, 0, {NullS, 0}, {NullS, 0}, true };
7272

7373
/* number of entries in handlertons[] */
7474
ulong total_ha= 0;

sql/handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,7 @@ typedef struct st_key_create_information
23472347
{
23482348
enum ha_key_alg algorithm;
23492349
ulong block_size;
2350+
uint flags; /* HA_USE.. flags */
23502351
LEX_CSTRING parser_name;
23512352
LEX_CSTRING comment;
23522353
/**

sql/sql_table.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,17 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
38473847
key->key_create_info.block_size :
38483848
create_info->key_block_size);
38493849

3850-
if (key_info->block_size)
3850+
/*
3851+
Remember block_size for the future if the block size was given
3852+
either for key or table and it was given for the key during
3853+
create/alter table or we have an active key_block_size for the
3854+
table.
3855+
The idea is that table specific key_block_size > 0 will only affect
3856+
new keys and old keys will remember their original value.
3857+
*/
3858+
if (key_info->block_size &&
3859+
((key->key_create_info.flags & HA_USES_BLOCK_SIZE) ||
3860+
create_info->key_block_size))
38513861
key_info->flags|= HA_USES_BLOCK_SIZE;
38523862

38533863
List_iterator<Key_part_spec> cols(key->columns), cols2(key->columns);
@@ -8408,8 +8418,12 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
84088418
LEX_CSTRING tmp_name;
84098419
bzero((char*) &key_create_info, sizeof(key_create_info));
84108420
key_create_info.algorithm= key_info->algorithm;
8411-
if (key_info->flags & HA_USES_BLOCK_SIZE)
8412-
key_create_info.block_size= key_info->block_size;
8421+
/*
8422+
We copy block size directly as some engines, like Area, sets this
8423+
automatically
8424+
*/
8425+
key_create_info.block_size= key_info->block_size;
8426+
key_create_info.flags= key_info->flags; // HA_USE_BLOCK_SIZE
84138427
if (key_info->flags & HA_USES_PARSER)
84148428
key_create_info.parser_name= *plugin_name(key_info->parser);
84158429
if (key_info->flags & HA_USES_COMMENT)

sql/sql_yacc.yy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "sql_sequence.h"
7070
#include "sql_tvc.h"
7171
#include "vers_utils.h"
72+
#include "my_base.h"
7273

7374
/* this is to get the bison compilation windows warnings out */
7475
#ifdef _MSC_VER
@@ -7518,7 +7519,10 @@ key_using_alg:
75187519

75197520
all_key_opt:
75207521
KEY_BLOCK_SIZE opt_equal ulong_num
7521-
{ Lex->last_key->key_create_info.block_size= $3; }
7522+
{
7523+
Lex->last_key->key_create_info.block_size= $3;
7524+
Lex->last_key->key_create_info.flags|= HA_USES_BLOCK_SIZE;
7525+
}
75227526
| COMMENT_SYM TEXT_STRING_sys
75237527
{ Lex->last_key->key_create_info.comment= $2; }
75247528
| IDENT_sys equal TEXT_STRING_sys

sql/sql_yacc_ora.yy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7351,7 +7351,10 @@ key_using_alg:
73517351

73527352
all_key_opt:
73537353
KEY_BLOCK_SIZE opt_equal ulong_num
7354-
{ Lex->last_key->key_create_info.block_size= $3; }
7354+
{
7355+
Lex->create_info.used_fields|= HA_USES_BLOCK_SIZE;
7356+
Lex->create_info.key_block_size= $3;
7357+
}
73557358
| COMMENT_SYM TEXT_STRING_sys
73567359
{ Lex->last_key->key_create_info.comment= $2; }
73577360
| IDENT_sys equal TEXT_STRING_sys

0 commit comments

Comments
 (0)