summaryrefslogtreecommitdiff
path: root/mysql-test/suite/vcol/r/vcol_select_myisam.result
blob: 4dee9f4fca6fb5d819f08983fecc8c4bf5f039b9 (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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
SET @@session.storage_engine = 'MyISAM';
create table t1 (a int,
b int as (-a),
c int as (-a) persistent,
index (c));
insert into t1 (a) values (2), (1), (1), (3), (NULL);
create table t2 like t1;
insert into t2 (a) values (1);
create table t3 (a int primary key, 
b int as (-a),
c int as (-a) persistent unique);
insert into t3 (a) values (2),(1),(3);
# select_type=SIMPLE, type=system
select * from t2;
a	b	c
1	-1	-1
explain select * from t2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	1	
select * from t2 where c=-1;
a	b	c
1	-1	-1
explain select * from t2 where c=-1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	system	c	NULL	NULL	NULL	1	
# select_type=SIMPLE, type=ALL
select * from t1 where b=-1;
a	b	c
1	-1	-1
1	-1	-1
explain select * from t1 where b=-1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
# select_type=SIMPLE, type=const
select * from t3 where a=1;
a	b	c
1	-1	-1
explain select * from t3 where a=1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	const	PRIMARY	PRIMARY	4	const	1	
# select_type=SIMPLE, type=range
select * from t3 where c>=-1;
a	b	c
1	-1	-1
explain select * from t3 where c>=-1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	c	c	5	NULL	2	Using index condition
# select_type=SIMPLE, type=ref
select * from t1,t3 where t1.c=t3.c and t3.c=-1;
a	b	c	a	b	c
1	-1	-1	1	-1	-1
1	-1	-1	1	-1	-1
explain select * from t1,t3 where t1.c=t3.c and t3.c=-1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	const	c	c	5	const	1	
1	SIMPLE	t1	ref	c	c	5	const	2	
# select_type=PRIMARY, type=index,ALL
select * from t1 where b in (select c from t3);
a	b	c
2	-2	-2
1	-1	-1
1	-1	-1
3	-3	-3
explain select * from t1 where b in (select c from t3);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t3	index	c	c	5	NULL	3	Using index
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where; Using join buffer (flat, BNL join)
# select_type=PRIMARY, type=range,ref
select * from t1 where c in (select c from t3 where c between -2 and -1);
a	b	c
2	-2	-2
1	-1	-1
1	-1	-1
explain select * from t1 where c in (select c from t3 where c between -2 and -1);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t3	index	c	c	5	NULL	3	Using where; Using index
1	PRIMARY	t1	ref	c	c	5	test.t3.c	2	
# select_type=UNION, type=system
# select_type=UNION RESULT, type=<union1,2>
select * from t1 union select * from t2;
a	b	c
2	-2	-2
1	-1	-1
3	-3	-3
NULL	NULL	NULL
explain select * from t1 union select * from t2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	
2	UNION	t2	system	NULL	NULL	NULL	NULL	1	
NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
# select_type=DERIVED, type=system
set @tmp_optimizer_switch=@@optimizer_switch;
set optimizer_switch='derived_merge=off,derived_with_keys=off';
select * from (select a,b,c from t1) as t11;
a	b	c
2	-2	-2
1	-1	-1
1	-1	-1
3	-3	-3
NULL	NULL	NULL
explain select * from (select a,b,c from t1) as t11;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	5	
2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	5	
set optimizer_switch=@tmp_optimizer_switch;
###
### Using aggregate functions with/without DISTINCT
###
# SELECT COUNT(*) FROM tbl_name
select count(*) from t1;
count(*)
5
explain select count(*) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
# SELECT COUNT(DISTINCT <non-vcol>) FROM tbl_name
select count(distinct a) from t1;
count(distinct a)
3
explain select count(distinct a) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
# SELECT COUNT(DISTINCT <non-stored vcol>) FROM tbl_name
select count(distinct b) from t1;
count(distinct b)
3
explain select count(distinct b) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
# SELECT COUNT(DISTINCT <stored vcol>) FROM tbl_name
select count(distinct c) from t1;
count(distinct c)
3
explain select count(distinct c) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	c	5	NULL	6	Using index for group-by (scanning)
###
### filesort & range-based utils
###
# SELECT * FROM tbl_name WHERE <vcol expr>
select * from t3 where c >= -2;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where c >= -2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	c	c	5	NULL	2	Using index condition
# SELECT * FROM tbl_name WHERE <non-vcol expr>
select * from t3 where a between 1 and 2;
a	b	c
1	-1	-1
2	-2	-2
explain select * from t3 where a between 1 and 2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	PRIMARY	PRIMARY	4	NULL	1	Using index condition
# SELECT * FROM tbl_name WHERE <non-indexed vcol expr>
select * from t3 where b between -2 and -1;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where b between -2 and -1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	3	Using where
# SELECT * FROM tbl_name WHERE <indexed vcol expr>
select * from t3 where c between -2 and -1;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where c between -2 and -1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	c	c	5	NULL	1	Using index condition
# SELECT * FROM tbl_name WHERE <non-vcol expr> ORDER BY <indexed vcol>
select * from t3 where a between 1 and 2 order by c;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where a between 1 and 2 order by c;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	PRIMARY	PRIMARY	4	NULL	1	Using index condition; Using filesort
# SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <non-vcol>
select * from t3 where b between -2 and -1 order by a;
a	b	c
1	-1	-1
2	-2	-2
explain select * from t3 where b between -2 and -1 order by a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	3	Using where; Using filesort
# SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <non-vcol>
select * from t3 where c between -2 and -1 order by a;
a	b	c
1	-1	-1
2	-2	-2
explain select * from t3 where c between -2 and -1 order by a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	c	c	5	NULL	1	Using index condition; Using filesort
# SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <non-indexed vcol>
select * from t3 where b between -2 and -1 order by b;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where b between -2 and -1 order by b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	3	Using where; Using filesort
# SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <non-indexed vcol>
select * from t3 where c between -2 and -1 order by b;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where c between -2 and -1 order by b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	c	c	5	NULL	1	Using index condition; Using filesort
# SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <indexed vcol>
select * from t3 where b between -2 and -1 order by c;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where b between -2 and -1 order by c;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	3	Using where; Using filesort
# SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <indexed vcol>
select * from t3 where c between -2 and -1 order by c;
a	b	c
2	-2	-2
1	-1	-1
explain select * from t3 where c between -2 and -1 order by c;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	range	c	c	5	NULL	1	Using index condition
# SELECT sum(<non-indexed vcol>) FROM tbl_name GROUP BY <non-indexed vcol>
select sum(b) from t1 group by b;
sum(b)
NULL
-3
-2
-2
explain select sum(b) from t1 group by b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using temporary; Using filesort
# SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
select sum(c) from t1 group by c;
sum(c)
NULL
-3
-2
-2
explain select sum(c) from t1 group by c;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	c	5	NULL	5	Using index
# SELECT sum(<non-indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
select sum(b) from t1 group by c;
sum(b)
NULL
-3
-2
-2
explain select sum(b) from t1 group by c;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using temporary; Using filesort
# SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <non-indexed vcol>
select sum(c) from t1 group by b;
sum(c)
NULL
-3
-2
-2
explain select sum(c) from t1 group by b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using temporary; Using filesort
#
# Bug #806057: join with USING over a virtual column 
#
CREATE TABLE t1 (b int);
INSERT INTO t1 VALUES (NULL),( 78), (185), (0), (154);
CREATE TABLE t2 (a int, b int AS (a) VIRTUAL);
INSERT INTO t2 VALUES (187,187), (9,9), (187,187);
Warnings:
Warning	1906	The value specified for generated column 'b' in table 't2' ignored
Warning	1906	The value specified for generated column 'b' in table 't2' ignored
Warning	1906	The value specified for generated column 'b' in table 't2' ignored
EXPLAIN EXTENDED
SELECT * FROM t1 JOIN t2 USING (b);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where; Using join buffer (flat, BNL join)
Warnings:
Note	1003	select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`b` = `test`.`t2`.`b`
SELECT * FROM t1 JOIN t2 USING (b);
b	a
EXPLAIN EXTENDED
SELECT * FROM t1 NATURAL JOIN t2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where; Using join buffer (flat, BNL join)
Warnings:
Note	1003	select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`b` = `test`.`t2`.`b`
SELECT * FROM t1 NATURAL JOIN t2;
b	a
DROP TABLE t1,t2;