72
alter table t1 engine=innodb;
66
alter table t1 engine=myisam;
73
67
explain select * from t1 where a in (869751,736494,226312,802616);
74
68
id select_type table type possible_keys key key_len ref rows Extra
75
1 SIMPLE t1 index uniq_id uniq_id 4 NULL 5 Using where; Using index
69
1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 Using where; Using index
77
create temporary table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y))
71
create table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y))
79
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
80
74
select * from t1 where x=1;
84
78
select * from t1,t1 as t2 where t1.x=t2.y;
85
ERROR HY000: Can't reopen table: 't1'
86
86
explain select * from t1,t1 as t2 where t1.x=t2.y;
87
ERROR HY000: Can't reopen table: 't1'
87
id select_type table type possible_keys key key_len ref rows Extra
88
1 SIMPLE t1 ALL x NULL NULL NULL 6
89
1 SIMPLE t2 eq_ref y y 4 test.t1.x 1
89
create temporary table t1 (a int) engine=MEMORY;
91
create table t1 (a int) engine=heap;
90
92
insert into t1 values(1);
91
93
select max(a) from t1;
95
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0, key using HASH (a), key using HASH (b) ) ENGINE=MEMORY;
97
CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using HASH (a), key using HASH (b) ) ENGINE=HEAP;
96
98
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
97
99
select * from t1 where a=1;
218
220
insert into t1 values ('aaah', 'prefill-hash=6',0);
219
221
explain select * from t1 where a='aaaa';
220
222
id select_type table type possible_keys key key_len ref rows Extra
221
1 SIMPLE t1 ref a a 34 const 2 Using where
223
1 SIMPLE t1 ref a a 8 const 2 Using where
222
224
explain select * from t1 where a='aaab';
223
225
id select_type table type possible_keys key key_len ref rows Extra
224
1 SIMPLE t1 ref a a 34 const 2 Using where
226
1 SIMPLE t1 ref a a 8 const 2 Using where
225
227
explain select * from t1 where a='aaac';
226
228
id select_type table type possible_keys key key_len ref rows Extra
227
1 SIMPLE t1 ref a a 34 const 2 Using where
229
1 SIMPLE t1 ref a a 8 const 2 Using where
228
230
explain select * from t1 where a='aaad';
229
231
id select_type table type possible_keys key key_len ref rows Extra
230
1 SIMPLE t1 ref a a 34 const 2 Using where
232
1 SIMPLE t1 ref a a 8 const 2 Using where
231
233
insert into t1 select * from t1;
232
ERROR HY000: Can't reopen table: 't1'
234
explain select * from t1 where a='aaaa';
235
id select_type table type possible_keys key key_len ref rows Extra
236
1 SIMPLE t1 ref a a 34 const 2 Using where
237
explain select * from t1 where a='aaab';
238
id select_type table type possible_keys key key_len ref rows Extra
239
1 SIMPLE t1 ref a a 34 const 2 Using where
240
explain select * from t1 where a='aaac';
241
id select_type table type possible_keys key key_len ref rows Extra
242
1 SIMPLE t1 ref a a 34 const 2 Using where
243
explain select * from t1 where a='aaad';
244
id select_type table type possible_keys key key_len ref rows Extra
245
1 SIMPLE t1 ref a a 34 const 2 Using where
247
explain select * from t1 where a='aaaa';
248
id select_type table type possible_keys key key_len ref rows Extra
249
1 SIMPLE t1 ref a a 34 const 2 Using where
250
explain select * from t1 where a='aaab';
251
id select_type table type possible_keys key key_len ref rows Extra
252
1 SIMPLE t1 ref a a 34 const 2 Using where
253
explain select * from t1 where a='aaac';
254
id select_type table type possible_keys key key_len ref rows Extra
255
1 SIMPLE t1 ref a a 34 const 2 Using where
256
explain select * from t1 where a='aaad';
257
id select_type table type possible_keys key key_len ref rows Extra
258
1 SIMPLE t1 ref a a 34 const 2 Using where
259
create temporary table t2 as select * from t1;
235
explain select * from t1 where a='aaaa';
236
id select_type table type possible_keys key key_len ref rows Extra
237
1 SIMPLE t1 ref a a 8 const 2 Using where
238
explain select * from t1 where a='aaab';
239
id select_type table type possible_keys key key_len ref rows Extra
240
1 SIMPLE t1 ref a a 8 const 2 Using where
241
explain select * from t1 where a='aaac';
242
id select_type table type possible_keys key key_len ref rows Extra
243
1 SIMPLE t1 ref a a 8 const 2 Using where
244
explain select * from t1 where a='aaad';
245
id select_type table type possible_keys key key_len ref rows Extra
246
1 SIMPLE t1 ref a a 8 const 2 Using where
248
explain select * from t1 where a='aaaa';
249
id select_type table type possible_keys key key_len ref rows Extra
250
1 SIMPLE t1 ref a a 8 const 2 Using where
251
explain select * from t1 where a='aaab';
252
id select_type table type possible_keys key key_len ref rows Extra
253
1 SIMPLE t1 ref a a 8 const 2 Using where
254
explain select * from t1 where a='aaac';
255
id select_type table type possible_keys key key_len ref rows Extra
256
1 SIMPLE t1 ref a a 8 const 2 Using where
257
explain select * from t1 where a='aaad';
258
id select_type table type possible_keys key key_len ref rows Extra
259
1 SIMPLE t1 ref a a 8 const 2 Using where
260
create table t2 as select * from t1;
261
262
insert into t1 select * from t2;
262
263
explain select * from t1 where a='aaaa';
263
264
id select_type table type possible_keys key key_len ref rows Extra
264
1 SIMPLE t1 ref a a 34 const 2 Using where
265
1 SIMPLE t1 ref a a 8 const 2 Using where
265
266
explain select * from t1 where a='aaab';
266
267
id select_type table type possible_keys key key_len ref rows Extra
267
1 SIMPLE t1 ref a a 34 const 2 Using where
268
1 SIMPLE t1 ref a a 8 const 2 Using where
268
269
explain select * from t1 where a='aaac';
269
270
id select_type table type possible_keys key key_len ref rows Extra
270
1 SIMPLE t1 ref a a 34 const 2 Using where
271
1 SIMPLE t1 ref a a 8 const 2 Using where
271
272
explain select * from t1 where a='aaad';
272
273
id select_type table type possible_keys key key_len ref rows Extra
273
1 SIMPLE t1 ref a a 34 const 2 Using where
274
1 SIMPLE t1 ref a a 8 const 2 Using where
274
275
drop table t1, t2;
275
create temporary table t1 (
276
id int not null primary key auto_increment,
277
id int unsigned not null primary key auto_increment,
277
278
name varchar(20) not null,
278
279
index heap_idx(name),
279
280
index btree_idx using btree(name)
281
create temporary table t2 (
282
id int not null primary key auto_increment,
283
id int unsigned not null primary key auto_increment,
283
284
name varchar(20) not null,
284
285
index btree_idx using btree(name),
285
286
index heap_idx(name)
287
288
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'),
288
289
('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'),
289
290
('Emily'), ('Mike');
290
291
insert into t2 select * from t1;
291
292
explain select * from t1 where name='matt';
292
293
id select_type table type possible_keys key key_len ref rows Extra
293
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
294
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
294
295
explain select * from t2 where name='matt';
295
296
id select_type table type possible_keys key key_len ref rows Extra
296
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
297
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
297
298
explain select * from t1 where name='Lilu';
298
299
id select_type table type possible_keys key key_len ref rows Extra
299
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
300
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
300
301
explain select * from t2 where name='Lilu';
301
302
id select_type table type possible_keys key key_len ref rows Extra
302
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
303
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
303
304
explain select * from t1 where name='Phil';
304
305
id select_type table type possible_keys key key_len ref rows Extra
305
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
306
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
306
307
explain select * from t2 where name='Phil';
307
308
id select_type table type possible_keys key key_len ref rows Extra
308
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
309
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
309
310
explain select * from t1 where name='Lilu';
310
311
id select_type table type possible_keys key key_len ref rows Extra
311
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
312
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
312
313
explain select * from t2 where name='Lilu';
313
314
id select_type table type possible_keys key key_len ref rows Extra
314
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
315
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
315
316
insert into t1 (name) select name from t2;
316
317
insert into t1 (name) select name from t2;
317
318
insert into t1 (name) select name from t2;
325
326
explain select * from t1 ignore index (btree_idx) where name='matt';
326
327
id select_type table type possible_keys key key_len ref rows Extra
327
1 SIMPLE t1 ref heap_idx heap_idx 82 const 9 Using where
329
Table Unique Key_name Seq_in_index Column_name
331
t1 NO heap_idx 1 name
332
t1 NO btree_idx 1 name
334
Table Unique Key_name Seq_in_index Column_name
336
t1 NO heap_idx 1 name
337
t1 NO btree_idx 1 name
338
create temporary table t3
328
1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where
330
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
331
t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH
332
t1 1 heap_idx 1 name NULL 13 NULL NULL HASH
333
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
335
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
336
t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH
337
t1 1 heap_idx 1 name NULL 13 NULL NULL HASH
338
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
340
341
a varchar(20) not null,
341
342
b varchar(20) not null,
344
345
insert into t3 select name, name from t1;
345
346
show index from t3;
346
Table Unique Key_name Seq_in_index Column_name
347
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
348
t3 1 a 1 a NULL NULL NULL NULL HASH
349
t3 1 a 2 b NULL 13 NULL NULL HASH
349
350
show index from t3;
350
Table Unique Key_name Seq_in_index Column_name
351
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
352
t3 1 a 1 a NULL NULL NULL NULL HASH
353
t3 1 a 2 b NULL 13 NULL NULL HASH
353
354
explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name;
354
355
id select_type table type possible_keys key key_len ref rows Extra
355
1 SIMPLE t1 ref heap_idx heap_idx 82 const 9 Using where
356
1 SIMPLE t3 ref a a 164 func,const 7 Using where
356
1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where
357
1 SIMPLE t3 ref a a 44 func,const 7 Using where
357
358
drop table t1, t2, t3;
358
359
create temporary table t1 ( a int, index (a) ) engine=memory;
359
360
insert into t1 values (1),(2),(3),(4),(5);