2
# Test of the MyISAM key cache
2
# Test of multiple key caches
5
5
drop table if exists t1, t2, t3;
8
SET @save_myisam_key_cache_size=@@myisam_key_cache_size;
9
SET @save_myisam_key_cache_block_size=@@myisam_key_cache_block_size;
10
SET @save_myisam_key_cache_division_limit=@@myisam_key_cache_division_limit;
11
SET @save_myisam_key_cache_age_threshold=@@myisam_key_cache_age_threshold;
8
SET @save_key_buffer=@@key_buffer_size;
13
# Show default variables for MyISAM key cache
14
SELECT @@myisam_key_cache_size;
15
SELECT @@myisam_key_cache_block_size;
16
SELECT @@myisam_key_cache_division_limit;
17
SELECT @@myisam_key_cache_age_threshold;
10
SELECT @@key_buffer_size, @@small.key_buffer_size;
19
12
# Change default key cache size
20
SET @@global.myisam_key_cache_size=16*1024*1024;
13
SET @@global.key_buffer_size=16*1024*1024;
14
SET @@global.default.key_buffer_size=16*1024*1024;
15
SET @@global.default.key_buffer_size=16*1024*1024;
22
# Drop Key Cache (warning generated)
23
SET @@global.myisam_key_cache_size=0;
17
SET @@global.small.key_buffer_size=1*1024*1024;
18
SET @@global.medium.key_buffer_size=4*1024*1024;
20
SET @@global.medium.key_buffer_size=0;
25
SET @@global.myisam_key_cache_size=0;
27
# Change default key cache size
28
SET @@global.myisam_key_cache_size=16*1024*1024;
22
SET @@global.medium.key_buffer_size=0;
30
24
# Print key buffer with different syntaxes
31
SHOW VARIABLES like "myisam_key_cache_size";
32
SELECT @@myisam_key_cache_size;
33
SELECT @@global.myisam_key_cache_size;
34
SELECT @@global.myisam_key_cache_size;
35
SELECT @@global.`myisam_key_cache_size`;
36
SELECT @@global.`myisam_key_cache_size`;
37
SELECT @@myisam_key_cache_size;
39
SET @@global.myisam_key_cache_size=@save_myisam_key_cache_size;
25
SHOW VARIABLES like "key_buffer_size";
26
SELECT @@key_buffer_size;
27
SELECT @@global.key_buffer_size;
28
SELECT @@global.default.key_buffer_size;
29
SELECT @@global.default.`key_buffer_size`;
30
SELECT @@global.`default`.`key_buffer_size`;
31
SELECT @@`default`.key_buffer_size;
33
SELECT @@small.key_buffer_size;
34
SELECT @@medium.key_buffer_size;
36
SET @@global.key_buffer_size=@save_key_buffer;
45
SELECT @@myisam_key_cache_size;
43
SELECT @@default.key_buffer_size;
46
45
SELECT @@skr.storage_engine="test";
48
select @@keycache1.myisam_key_cache_block_size;
51
show status like 'key_blocks_used';
47
select @@keycache1.key_cache_block_size;
48
select @@keycache1.key_buffer_size;
49
set global keycache1.key_cache_block_size=2048;
50
select @@keycache1.key_buffer_size;
51
select @@keycache1.key_cache_block_size;
52
set global keycache1.key_buffer_size=1*1024*1024;
53
select @@keycache1.key_buffer_size;
54
select @@keycache1.key_cache_block_size;
55
set global keycache2.key_buffer_size=4*1024*1024;
56
select @@keycache2.key_buffer_size;
57
select @@keycache2.key_cache_block_size;
58
set global keycache1.key_buffer_size=0;
59
select @@keycache1.key_buffer_size;
60
select @@keycache1.key_cache_block_size;
61
select @@key_buffer_size;
62
select @@key_cache_block_size;
64
set global keycache1.key_buffer_size=1024*1024;
66
create table t1 (p int primary key, a char(10)) delay_key_write=1;
67
create table t2 (p int primary key, i int, a char(10), key k1(i), key k2(a));
69
show status like 'key_blocks_used';
71
# Following results differs on 64 and 32 bit systems because of different
72
# pointer sizes, which takes up different amount of space in key cache
74
--replace_result 1812 KEY_BLOCKS_UNUSED 1793 KEY_BLOCKS_UNUSED 1674 KEY_BLOCKS_UNUSED 1818 KEY_BLOCKS_UNUSED 1824 KEY_BLOCKS_UNUSED
75
show status like 'key_blocks_unused';
77
insert into t1 values (1, 'qqqq'), (11, 'yyyy');
78
insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
79
(3, 1, 'yyyy'), (4, 3, 'zzzz');
83
update t1 set p=2 where p=1;
84
update t2 set i=2 where i=1;
86
show status like 'key_blocks_used';
87
--replace_result 1808 KEY_BLOCKS_UNUSED 1789 KEY_BLOCKS_UNUSED 1670 KEY_BLOCKS_UNUSED 1814 KEY_BLOCKS_UNUSED 1820 KEY_BLOCKS_UNUSED
88
show status like 'key_blocks_unused';
90
cache index t1 key (`primary`) in keycache1;
92
explain select p from t1;
94
explain select i from t2;
96
explain select count(*) from t1, t2 where t1.p = t2.i;
97
select count(*) from t1, t2 where t1.p = t2.i;
99
cache index t2 in keycache1;
100
update t2 set p=p+1000, i=2 where a='qqqq';
101
cache index t2 in keycache2;
102
insert into t2 values (2000, 3, 'yyyy');
103
cache index t2 in keycache1;
104
update t2 set p=3000 where a='zzzz';
106
explain select p from t2;
108
explain select i from t2;
110
explain select a from t2;
113
# Test some error conditions
115
cache index t1 in unknown_key_cache;
116
cache index t1 key (unknown_key) in keycache1;
118
select @@keycache2.key_buffer_size;
119
select @@keycache2.key_cache_block_size;
120
set global keycache2.key_buffer_size=0;
121
select @@keycache2.key_buffer_size;
122
select @@keycache2.key_cache_block_size;
123
set global keycache2.key_buffer_size=1024*1024;
124
select @@keycache2.key_buffer_size;
126
update t2 set p=4000 where a='zzzz';
129
set global keycache1.key_buffer_size=0;
132
explain select i from t2;
134
explain select a from t2;
140
# Use the 'small' key cache
141
create table t3 (like t1);
142
cache index t3 in small;
143
insert into t3 select * from t1;
144
cache index t3 in keycache2;
145
cache index t1,t2 in default;
148
show status like 'key_blocks_used';
149
--replace_result 1812 KEY_BLOCKS_UNUSED 1793 KEY_BLOCKS_UNUSED 1674 KEY_BLOCKS_UNUSED 1818 KEY_BLOCKS_UNUSED 1824 KEY_BLOCKS_UNUSED
150
show status like 'key_blocks_unused';
154
# We don't reset keycache2 as we want to ensure that mysqld will reset it
155
set global keycache2.key_buffer_size=0;
53
157
# Test to set up a too small size for a key cache (bug #2064)
54
set global myisam_key_cache_size=100;
158
set global keycache3.key_buffer_size=100;
159
set global keycache3.key_buffer_size=0;
161
# Test case for bug 6447
163
create table t1 (mytext text, FULLTEXT (mytext));
164
insert t1 values ('aaabbb');
167
set @my_key_cache_block_size= @@global.key_cache_block_size;
168
set GLOBAL key_cache_block_size=2048;
171
# Restore the changed variable value
172
set global key_cache_block_size= @my_key_cache_block_size;
57
# Bug #19079: corrupted index when myisam_key_cache_block_size is not multiple of
175
# Bug #19079: corrupted index when key_cache_block_size is not multiple of
58
176
# myisam_block_size
60
CREATE temporary TABLE t1(a int NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=MYISAM;
61
SET GLOBAL myisam_key_cache_block_size=1536;
178
CREATE TABLE t1(a int NOT NULL AUTO_INCREMENT PRIMARY KEY);
179
SET @my_key_cache_block_size= @@global.key_cache_block_size;
180
SET GLOBAL key_cache_block_size=1536;
62
181
INSERT INTO t1 VALUES (1);
63
SELECT @@myisam_key_cache_block_size;
182
SELECT @@key_cache_block_size;
67
CREATE TEMPORARY TABLE t1(a int NOT NULL AUTO_INCREMENT PRIMARY KEY, b int) ENGINE=MYISAM;
68
CREATE TEMPORARY TABLE t2(a int NOT NULL AUTO_INCREMENT PRIMARY KEY, b int) ENGINE=MYISAM;
69
SET GLOBAL myisam_key_cache_block_size=1536;
186
CREATE TABLE t1(a int NOT NULL AUTO_INCREMENT PRIMARY KEY, b int);
187
CREATE TABLE t2(a int NOT NULL AUTO_INCREMENT PRIMARY KEY, b int);
188
SET GLOBAL key_cache_block_size=1536;
70
189
INSERT INTO t1 VALUES (1,0);
71
190
INSERT INTO t2(b) SELECT b FROM t1;
72
191
INSERT INTO t1(b) SELECT b FROM t2;
113
238
('m', 'n', 'o'), ('n', 'o', 'p'), ('o', 'p', 'q'), ('p', 'q', 'r'),
114
239
('q', 'r', 's'), ('r', 's', 't'), ('s', 't', 'u'), ('t', 'u', 'v'),
115
240
('u', 'v', 'w'), ('v', 'w', 'x'), ('w', 'x', 'y'), ('x', 'y', 'z');
116
CREATE TABLE t2 AS SELECT * FROM t1;
117
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t2;
118
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t2;
119
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t2;
241
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
242
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
243
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
121
SHOW VARIABLES LIKE 'myisam_key_cache_block_size';
122
SET GLOBAL myisam_key_cache_block_size= @save_myisam_key_cache_block_size;
125
# Check division limit and age threshold
127
# Division Limit: Minimum 1, maximum 100
128
SET GLOBAL myisam_key_cache_division_limit= 0;
130
SELECT @@myisam_key_cache_division_limit;
132
SET GLOBAL myisam_key_cache_division_limit= 101;
134
SELECT @@myisam_key_cache_division_limit;
136
# Age Threshold: Minimum 100, maximum UINT32_MAX
137
SET GLOBAL myisam_key_cache_age_threshold= 98;
139
SELECT @@myisam_key_cache_age_threshold;
141
SET GLOBAL myisam_key_cache_age_threshold= 5000000000;
143
SELECT @@myisam_key_cache_age_threshold;
245
SHOW VARIABLES LIKE 'key_cache_block_size';
246
SET GLOBAL key_cache_block_size= @bug28478_key_cache_block_size;