1
################################################################################
2
# inc/vcol_select.inc #
5
# Testing different SELECTs. #
8
#------------------------------------------------------------------------------#
9
# Original Author: Andrey Zhakov #
10
# Original Date: 2008-09-18 #
14
################################################################################
16
# Table t1 is used below to test:
17
# - Join type of ALL (sequential scan of the entire table)
18
# - Join type of Index
19
# - Join type of Range
20
# - Join type of Ref_or_null
21
create table t1 (a int,
22
b virtual int as (-a),
23
c virtual int as (-a) stored,
25
insert into t1 (a) values (2), (1), (1), (3), (NULL);
27
# Table t2 is used below to test:
28
# - Join type of system and const
29
create table t2 like t1;
30
insert into t2 (a) values (1);
32
# Table t3 is used below to test
33
# - Join type of Eq_ref with a unique virtual column
34
# - Join type of Const
35
create table t3 (a int primary key,
36
b virtual int as (-a),
37
c virtual int as (-a) stored unique);
38
insert into t3 (a) values (2),(1),(3);
41
--echo # select_type=SIMPLE, type=system
42
let $s = select * from t2;
46
let $s = select * from t2 where c=-1;
50
--echo # select_type=SIMPLE, type=ALL
51
let $s = select * from t1 where b=-1;
55
--echo # select_type=SIMPLE, type=const
56
let $s = select * from t3 where a=1;
60
--echo # select_type=SIMPLE, type=range
61
let $s = select * from t3 where c>=-1;
65
--echo # select_type=SIMPLE, type=ref
66
let $s = select * from t1,t3 where t1.c=t3.c and t3.c=-1;
70
--echo # select_type=PRIMARY, type=index,ALL
71
let $s = select * from t1 where b in (select c from t3);
75
--echo # select_type=PRIMARY, type=range,ref
76
let $s = select * from t1 where c in (select c from t3 where c between -2 and -1);
80
--echo # select_type=UNION, type=system
81
--echo # select_type=UNION RESULT, type=<union1,2>
82
let $s = select * from t1 union select * from t2;
86
--echo # select_type=DERIVED, type=system
87
let $s = select * from (select a,b,c from t1) as t11;
92
--echo ### Using aggregate functions with/without DISTINCT
94
--echo # SELECT COUNT(*) FROM tbl_name
95
let $s = select count(*) from t1;
99
--echo # SELECT COUNT(DISTINCT <non-vcol>) FROM tbl_name
100
let $s = select count(distinct a) from t1;
104
--echo # SELECT COUNT(DISTINCT <non-stored vcol>) FROM tbl_name
105
let $s = select count(distinct b) from t1;
109
--echo # SELECT COUNT(DISTINCT <stored vcol>) FROM tbl_name
110
let $s = select count(distinct c) from t1;
115
--echo ### filesort & range-based utils
117
--echo # SELECT * FROM tbl_name WHERE <vcol expr>
118
let $s = select * from t3 where c >= -2;
122
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr>
123
let $s = select * from t3 where a between 1 and 2;
127
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr>
128
let $s = select * from t3 where b between -2 and -1;
132
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr>
133
let $s = select * from t3 where c between -2 and -1;
137
#### Remove for MyISAM due to a bug
138
#### when all the three records are returned (a=1,2,3)
139
#### instead of just two (a=1,2).
140
#### This bug is presumably in base SQL routines as the same happens
141
#### with this table:
142
#### create table t4 (a int primary key, b int, c int unique);
143
let $myisam_engine = `SELECT @@session.storage_engine='myisam'`;
146
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr> ORDER BY <non-indexed vcol>
147
let $s = select * from t3 where a between 1 and 2 order by b;
152
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr> ORDER BY <indexed vcol>
153
let $s = select * from t3 where a between 1 and 2 order by c;
157
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <non-vcol>
158
let $s = select * from t3 where b between -2 and -1 order by a;
162
#### Remove for MyISAM due to a bug
163
#### when all the three records are returned (a=1,2,3)
164
#### instead of just two (a=1,2).
165
#### This bug is presumably in base SQL routines as the same happens
166
#### with this table:
167
#### create table t4 (a int primary key, b int, c int unique);
168
let $innodb_engine = `SELECT @@session.storage_engine='innodb'`;
171
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <non-vcol>
172
let $s = select * from t3 where c between -2 and -1 order by a;
177
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <non-indexed vcol>
178
let $s = select * from t3 where b between -2 and -1 order by b;
182
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <non-indexed vcol>
183
let $s = select * from t3 where c between -2 and -1 order by b;
187
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <indexed vcol>
188
let $s = select * from t3 where b between -2 and -1 order by c;
192
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <indexed vcol>
193
let $s = select * from t3 where c between -2 and -1 order by c;
197
--echo # SELECT sum(<non-indexed vcol>) FROM tbl_name GROUP BY <non-indexed vcol>
198
let $s = select sum(b) from t1 group by b;
202
--echo # SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
203
let $s = select sum(c) from t1 group by c;
207
--echo # SELECT sum(<non-indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
208
let $s = select sum(b) from t1 group by c;
212
--echo # SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <non-indexed vcol>
213
let $s = select sum(c) from t1 group by b;