~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/suite/vcol/inc/vcol_select.inc

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:16:12 UTC
  • mfrom: (520.1.2 drizzle)
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016111612-5nei7m5subslx912
mergeĀ fromĀ head

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
################################################################################
 
2
# inc/vcol_select.inc                                                          #
 
3
#                                                                              #
 
4
# Purpose:                                                                     #
 
5
#  Testing different SELECTs.                                                  #
 
6
#                                                                              #
 
7
#                                                                              #
 
8
#------------------------------------------------------------------------------#
 
9
# Original Author: Andrey Zhakov                                               #
 
10
# Original Date: 2008-09-18                                                    #
 
11
# Change Author:                                                               #
 
12
# Change Date:                                                                 #
 
13
# Change:                                                                      #
 
14
################################################################################
 
15
 
 
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,
 
24
                 index (c));
 
25
insert into t1 (a) values (2), (1), (1), (3), (NULL);
 
26
 
 
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);
 
31
 
 
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);
 
39
 
 
40
 
 
41
--echo # select_type=SIMPLE, type=system
 
42
let $s = select * from t2;
 
43
eval $s;
 
44
eval explain $s;
 
45
 
 
46
let $s = select * from t2 where c=-1;
 
47
eval $s;
 
48
eval explain $s;
 
49
 
 
50
--echo # select_type=SIMPLE, type=ALL
 
51
let $s = select * from t1 where b=-1;
 
52
eval $s;
 
53
eval explain $s;
 
54
 
 
55
--echo # select_type=SIMPLE, type=const
 
56
let $s = select * from t3 where a=1;
 
57
eval $s;
 
58
eval explain $s;
 
59
 
 
60
--echo # select_type=SIMPLE, type=range
 
61
let $s = select * from t3 where c>=-1;
 
62
eval $s;
 
63
eval explain $s;
 
64
 
 
65
--echo # select_type=SIMPLE, type=ref
 
66
let $s = select * from t1,t3 where t1.c=t3.c and t3.c=-1;
 
67
eval $s;
 
68
eval explain $s;
 
69
 
 
70
--echo # select_type=PRIMARY, type=index,ALL
 
71
let $s = select * from t1 where b in (select c from t3);
 
72
eval $s;
 
73
eval explain $s;
 
74
 
 
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);
 
77
eval $s;
 
78
eval explain $s;
 
79
 
 
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;
 
83
eval $s;
 
84
eval explain $s;
 
85
 
 
86
--echo # select_type=DERIVED, type=system
 
87
let $s = select * from (select a,b,c from t1) as t11;
 
88
eval $s;
 
89
eval explain $s;
 
90
 
 
91
--echo ###
 
92
--echo ### Using aggregate functions with/without DISTINCT
 
93
--echo ###
 
94
--echo # SELECT COUNT(*) FROM tbl_name
 
95
let $s = select count(*) from t1;
 
96
eval $s;
 
97
eval explain $s;
 
98
 
 
99
--echo # SELECT COUNT(DISTINCT <non-vcol>) FROM tbl_name
 
100
let $s = select count(distinct a) from t1;
 
101
eval $s;
 
102
eval explain $s;
 
103
 
 
104
--echo # SELECT COUNT(DISTINCT <non-stored vcol>) FROM tbl_name
 
105
let $s = select count(distinct b) from t1;
 
106
eval $s;
 
107
eval explain $s;
 
108
 
 
109
--echo # SELECT COUNT(DISTINCT <stored vcol>) FROM tbl_name
 
110
let $s = select count(distinct c) from t1;
 
111
eval $s;
 
112
eval explain $s;
 
113
 
 
114
--echo ###
 
115
--echo ### filesort & range-based utils
 
116
--echo ###
 
117
--echo # SELECT * FROM tbl_name WHERE <vcol expr>
 
118
let $s = select * from t3 where c >= -2;
 
119
eval $s;
 
120
eval explain $s;
 
121
 
 
122
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr>
 
123
let $s = select * from t3 where a between 1 and 2;
 
124
eval $s;
 
125
eval explain $s;
 
126
 
 
127
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr>
 
128
let $s = select * from t3 where b between -2 and -1;
 
129
eval $s;
 
130
eval explain $s;
 
131
 
 
132
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr>
 
133
let $s = select * from t3 where c between -2 and -1;
 
134
eval $s;
 
135
eval explain $s;
 
136
 
 
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'`;
 
144
if (!$myisam_engine)
 
145
{
 
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;
 
148
  eval $s;
 
149
  eval explain $s;
 
150
}
 
151
 
 
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;
 
154
eval $s;
 
155
eval explain $s;
 
156
 
 
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;
 
159
eval $s;
 
160
eval explain $s;
 
161
 
 
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'`;
 
169
if (!$innodb_engine)
 
170
{
 
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;
 
173
  eval $s;
 
174
  eval explain $s;
 
175
}
 
176
 
 
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;
 
179
eval $s;
 
180
eval explain $s;
 
181
 
 
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;
 
184
eval $s;
 
185
eval explain $s;
 
186
 
 
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;
 
189
eval $s;
 
190
eval explain $s;
 
191
 
 
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;
 
194
eval $s;
 
195
eval explain $s;
 
196
 
 
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;
 
199
eval $s;
 
200
eval explain $s;
 
201
 
 
202
--echo # SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
 
203
let $s = select sum(c) from t1 group by c;
 
204
eval $s;
 
205
eval explain $s;
 
206
 
 
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;
 
209
eval $s;
 
210
eval explain $s;
 
211
 
 
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;
 
214
eval $s;
 
215
eval explain $s;
 
216