summaryrefslogtreecommitdiff
path: root/mysql-test/main/derived_split_innodb.result
blob: 5073aa84c1386710309107fa237f965b669d75b3 (plain)
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
#
# MDEV-16917: do not use splitting for derived with join cache
#
CREATE TABLE t1 (
n1 int(10) NOT NULL,
n2 int(10) NOT NULL,
c1 char(1) NOT NULL,
KEY c1 (c1),
KEY n1_c1_n2 (n1,c1,n2)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES (0, 2, 'a'), (1, 3, 'a');
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
EXPLAIN SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t
WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t1	index	c1,n1_c1_n2	n1_c1_n2	9	NULL	2	Using where; Using index
1	PRIMARY	<derived2>	ref	key0	key0	8	test.t1.n1,test.t1.n2	2	
2	LATERAL DERIVED	t1	ref	c1,n1_c1_n2	n1_c1_n2	4	test.t1.n1	1	Using where; Using index
SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t
WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
n1
0
1
DROP TABLE t1;
#
# MDEV-17211: splittable materialized derived joining 3 tables with
#             GROUP BY list containing fields from 2 of them
#
CREATE TABLE t1 (
id1 int, i1 int, id2 int,
PRIMARY KEY (id1), KEY (i1), KEY (id2)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,1,1);
CREATE TABLE t2 (id2 int, i2 int) ENGINE=InnoDB;
INSERT INTO t2  VALUES (1, 1);
CREATE TABLE t3 (id3 int, i3 int, PRIMARY KEY (id3)) ENGINE=InnoDB;
INSERT INTO t3 VALUES (1,1);
EXPLAIN SELECT id3
FROM (SELECT t3.id3, t2.i2, t1.id2  FROM t3,t1,t2
WHERE t3.i3=t1.id1 AND t2.id2=t1.id2
GROUP BY t3.id3, t1.id2) AS t,
t2
WHERE t2.id2=t.id2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	1	Using where
1	PRIMARY	<derived2>	ref	key0	key0	5	test.t2.id2	2	
2	DERIVED	t3	ALL	NULL	NULL	NULL	NULL	1	Using where; Using temporary; Using filesort
2	DERIVED	t1	eq_ref	PRIMARY,id2	PRIMARY	4	test.t3.i3	1	
2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
SELECT id3
FROM (SELECT t3.id3, t2.i2, t1.id2  FROM t3,t1,t2
WHERE t3.i3=t1.id1 AND t2.id2=t1.id2
GROUP BY t3.id3, t1.id2) AS t,
t2
WHERE t2.id2=t.id2;
id3
1
DROP TABLE t1,t2,t3;
#
# Bug mdev-17381: equi-join of derived table with join_cache_level=4
#
CREATE TABLE t1 (
id int NOT NULL,
amount decimal DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE t2 (
id int NOT NULL,
name varchar(50) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
INSERT INTO t1 VALUES
(1, 10.0000), (2, 20.0000), (3, 30.0000), (4, 40.0000),
(5, NULL), (6, NULL), (7, 70.0000), (8, 80.0000);
INSERT INTO t2 VALUES
(1,'A'), (2,'B'), (3,'C'), (4,'D'), (5, NULL), (6, NULL),
(7,'E'), (8,'F'), (9,'G'), (10,'H'), (11, NULL), (12, NULL);
set join_cache_level=4;
SELECT t2.id,t2.name,t.total_amt
FROM  t2
LEFT JOIN
(SELECT id, sum(amount) total_amt FROM t1 GROUP BY id) AS t
ON t2.id=t.id
WHERE t2.id < 3;
id	name	total_amt
1	A	10
2	B	20
EXPLAIN SELECT t2.id,t2.name,t.total_amt
FROM  t2
LEFT JOIN
(SELECT id, sum(amount) total_amt FROM t1 GROUP BY id) AS t
ON t2.id=t.id
WHERE t2.id < 3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t2	range	PRIMARY	PRIMARY	4	NULL	2	Using where
1	PRIMARY	<derived2>	ref	key0	key0	5	test.t2.id	2	
2	LATERAL DERIVED	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.id	1	
set join_cache_level=default;
DROP TABLE t1,t2;