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
|
drop table if exists t1,t2;
#
# Bug #878769: valgrind complains when using join cache
# to join an InnoDB table without primary key
#
CREATE TABLE t1 (
col_int_key int(11), col_time_key time, col_varchar_key varchar(1),
KEY (col_int_key), KEY (col_varchar_key,col_int_key)
) ENGINE=InnoDB;
INSERT IGNORE INTO t1 VALUES
(7,'10:19:31','d'),(1,'14:40:36','r'),(7,'04:37:47','f'),(9,'19:34:06','y'),
(2,'00:00:00','m'),(4,'00:13:25','q'),(0,'03:47:16',NULL),(4,'01:41:48','d'),
(8,'00:00:00','g'),(NULL,'22:32:04','x'),(NULL,'16:44:14','f'),
(0,'17:38:37','p'),(NULL,'08:46:48','j'),(8,'14:11:27','c');
CREATE TABLE t2 (
col_int_nokey int(11), col_int_key int(11),
col_datetime_key datetime, col_datetime_nokey datetime,
col_varchar_key varchar(1), col_varchar_nokey varchar(1),
KEY (col_int_key), KEY (col_varchar_key,col_int_key)
);
INSERT IGNORE INTO t2 VALUES
(150,62,'2008-01-03 10:33:32','2008-01-03 10:33:32','v','v'),
(2,1,'2007-10-09 19:53:04','2007-10-09 19:53:04',NULL,NULL),
(5,0,'2001-11-08 21:02:12','2001-11-08 21:02:12','x','x'),
(3,7,'2003-04-01 00:00','2003-04-01 00:00','i','i'),
(1,7,'1900-01-01 00:00','1900-01-01 00:00:00','e','e'),
(NULL,7,'2005-04-04 01:21','2005-04-04 01:21','s','s'),
(2,1,'1900-01-01 00:00','1900-01-01 00:00','j','j'),
(8,0,'2004-04-28 21:44','2004-04-28 21:44','a','a'),
(6,8,'2001-04-18 00:00','2001-04-18 00:00:00','y','y'),
(8,1,'2008-12-18 19:39:55','2008-12-18 19:39:55',NULL,NULL),
(3,1,'2000-08-01 12:19:39','2000-08-01 12:19:39','r','r'),
(3,9,'2004-09-25 21:29:06','2004-09-25 21:29:06','v','v');
set session optimizer_switch='mrr=on,mrr_sort_keys=on';
set session join_cache_level=6;
EXPLAIN
SELECT t1.col_time_key, t1.col_varchar_key
FROM t2 STRAIGHT_JOIN t1 ON t1.col_int_key = t2.col_int_key
GROUP BY 1,2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index col_int_key col_int_key 5 NULL 12 Using where; Using index; Using temporary; Using filesort
1 SIMPLE t1 ref col_int_key col_int_key 5 test.t2.col_int_key 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
SELECT t1.col_time_key, t1.col_varchar_key
FROM t2 STRAIGHT_JOIN t1 ON t1.col_int_key = t2.col_int_key
GROUP BY 1,2;
col_time_key col_varchar_key
00:00:00 g
03:47:16 NULL
04:37:47 f
10:19:31 d
14:11:27 c
14:40:36 r
17:38:37 p
19:34:06 y
set session optimizer_switch=default;
set session join_cache_level=default;
DROP TABLE t1,t2;
|