1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
SET DEFAULT_STORAGE_ENGINE='tokudb';
DROP TABLE IF EXISTS foo;
drop procedure if exists p0;
drop procedure if exists p1;
drop function if exists f0;
set session tokudb_disable_slow_alter=ON;
create table foo (a int, b int, c int, key (b) clustering=yes)engine=TokuDB;
insert into foo values (1,10,100),(2,20,200),(3,30,300);
set autocommit=off;
insert into foo values (4,40,400);
alter table foo add column z int default 999 first;
explain select * from foo;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 4 Using index
select * from foo;
z a b c
999 1 10 100
999 2 20 200
999 3 30 300
999 4 40 400
explain select * from foo where b > 20;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 2 Using where; Using index
select* from foo where b > 10;
z a b c
999 2 20 200
999 3 30 300
999 4 40 400
set autocommit=on;
begin;
alter table foo drop column z;
explain select * from foo;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 4 Using index
select * from foo;
a b c
1 10 100
2 20 200
3 30 300
4 40 400
explain select * from foo where b > 20;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 2 Using where; Using index
select* from foo where b > 10;
a b c
2 20 200
3 30 300
4 40 400
lock tables foo write;
alter table foo add column z int;
explain select * from foo;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 4 Using index
select * from foo;
a b c z
1 10 100 NULL
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
explain select * from foo where b > 20;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 2 Using where; Using index
select* from foo where b > 10;
a b c z
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
unlock tables;
select * from foo;
a b c z
1 10 100 NULL
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
select * from foo where b > 10;
a b c z
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
create procedure p0()
begin
alter table foo drop column z;
explain select * from foo;
select * from foo;
explain select * from foo where b > 20;
select* from foo where b > 10;
end |
call p0();
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 4 Using index
a b c
1 10 100
2 20 200
3 30 300
4 40 400
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 2 Using where; Using index
a b c
2 20 200
3 30 300
4 40 400
explain select * from foo;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 4 Using index
select * from foo;
a b c
1 10 100
2 20 200
3 30 300
4 40 400
explain select * from foo where b > 20;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 2 Using where; Using index
select* from foo where b > 10;
a b c
2 20 200
3 30 300
4 40 400
create function f0() returns int
begin
alter table foo add column ggg int;
end|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
set autocommit=0;
create procedure p1()
begin
insert into foo values(5,50,500);
select * from foo;
savepoint x;
alter table foo add column g int;
explain select * from foo;
select * from foo;
select * from foo where b > 10;
explain select * from foo where b > 20;
end|
call p1();
a b c
1 10 100
2 20 200
3 30 300
4 40 400
5 50 500
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 5 Using index
a b c g
1 10 100 NULL
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
5 50 500 NULL
a b c g
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
5 50 500 NULL
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 3 Using where; Using index
set autocommit=on;
explain select * from foo;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo index NULL b 5 NULL 5 Using index
select * from foo;
a b c g
1 10 100 NULL
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
5 50 500 NULL
explain select * from foo where b > 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE foo range b b 5 NULL 4 Using where; Using index
select * from foo where b > 10;
a b c g
2 20 200 NULL
3 30 300 NULL
4 40 400 NULL
5 50 500 NULL
drop table foo;
drop procedure p0;
drop procedure p1;
|