sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this file is testing SELECT statements that contain
|
sl@0
|
13 |
# aggregate min() and max() functions and which are handled as
|
sl@0
|
14 |
# as a special case.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: minmax.test,v 1.21 2008/07/08 18:05:26 drh Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
set testdir [file dirname $argv0]
|
sl@0
|
19 |
source $testdir/tester.tcl
|
sl@0
|
20 |
|
sl@0
|
21 |
do_test minmax-1.0 {
|
sl@0
|
22 |
execsql {
|
sl@0
|
23 |
BEGIN;
|
sl@0
|
24 |
CREATE TABLE t1(x, y);
|
sl@0
|
25 |
INSERT INTO t1 VALUES(1,1);
|
sl@0
|
26 |
INSERT INTO t1 VALUES(2,2);
|
sl@0
|
27 |
INSERT INTO t1 VALUES(3,2);
|
sl@0
|
28 |
INSERT INTO t1 VALUES(4,3);
|
sl@0
|
29 |
INSERT INTO t1 VALUES(5,3);
|
sl@0
|
30 |
INSERT INTO t1 VALUES(6,3);
|
sl@0
|
31 |
INSERT INTO t1 VALUES(7,3);
|
sl@0
|
32 |
INSERT INTO t1 VALUES(8,4);
|
sl@0
|
33 |
INSERT INTO t1 VALUES(9,4);
|
sl@0
|
34 |
INSERT INTO t1 VALUES(10,4);
|
sl@0
|
35 |
INSERT INTO t1 VALUES(11,4);
|
sl@0
|
36 |
INSERT INTO t1 VALUES(12,4);
|
sl@0
|
37 |
INSERT INTO t1 VALUES(13,4);
|
sl@0
|
38 |
INSERT INTO t1 VALUES(14,4);
|
sl@0
|
39 |
INSERT INTO t1 VALUES(15,4);
|
sl@0
|
40 |
INSERT INTO t1 VALUES(16,5);
|
sl@0
|
41 |
INSERT INTO t1 VALUES(17,5);
|
sl@0
|
42 |
INSERT INTO t1 VALUES(18,5);
|
sl@0
|
43 |
INSERT INTO t1 VALUES(19,5);
|
sl@0
|
44 |
INSERT INTO t1 VALUES(20,5);
|
sl@0
|
45 |
COMMIT;
|
sl@0
|
46 |
SELECT DISTINCT y FROM t1 ORDER BY y;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
} {1 2 3 4 5}
|
sl@0
|
49 |
|
sl@0
|
50 |
do_test minmax-1.1 {
|
sl@0
|
51 |
set sqlite_search_count 0
|
sl@0
|
52 |
execsql {SELECT min(x) FROM t1}
|
sl@0
|
53 |
} {1}
|
sl@0
|
54 |
do_test minmax-1.2 {
|
sl@0
|
55 |
set sqlite_search_count
|
sl@0
|
56 |
} {19}
|
sl@0
|
57 |
do_test minmax-1.3 {
|
sl@0
|
58 |
set sqlite_search_count 0
|
sl@0
|
59 |
execsql {SELECT max(x) FROM t1}
|
sl@0
|
60 |
} {20}
|
sl@0
|
61 |
do_test minmax-1.4 {
|
sl@0
|
62 |
set sqlite_search_count
|
sl@0
|
63 |
} {19}
|
sl@0
|
64 |
do_test minmax-1.5 {
|
sl@0
|
65 |
execsql {CREATE INDEX t1i1 ON t1(x)}
|
sl@0
|
66 |
set sqlite_search_count 0
|
sl@0
|
67 |
execsql {SELECT min(x) FROM t1}
|
sl@0
|
68 |
} {1}
|
sl@0
|
69 |
do_test minmax-1.6 {
|
sl@0
|
70 |
set sqlite_search_count
|
sl@0
|
71 |
} {1}
|
sl@0
|
72 |
do_test minmax-1.7 {
|
sl@0
|
73 |
set sqlite_search_count 0
|
sl@0
|
74 |
execsql {SELECT max(x) FROM t1}
|
sl@0
|
75 |
} {20}
|
sl@0
|
76 |
do_test minmax-1.8 {
|
sl@0
|
77 |
set sqlite_search_count
|
sl@0
|
78 |
} {0}
|
sl@0
|
79 |
do_test minmax-1.9 {
|
sl@0
|
80 |
set sqlite_search_count 0
|
sl@0
|
81 |
execsql {SELECT max(y) FROM t1}
|
sl@0
|
82 |
} {5}
|
sl@0
|
83 |
do_test minmax-1.10 {
|
sl@0
|
84 |
set sqlite_search_count
|
sl@0
|
85 |
} {19}
|
sl@0
|
86 |
|
sl@0
|
87 |
do_test minmax-1.21 {
|
sl@0
|
88 |
execsql {SELECT min(x) FROM t1 WHERE x=5}
|
sl@0
|
89 |
} {5}
|
sl@0
|
90 |
do_test minmax-1.22 {
|
sl@0
|
91 |
execsql {SELECT min(x) FROM t1 WHERE x>=5}
|
sl@0
|
92 |
} {5}
|
sl@0
|
93 |
do_test minmax-1.23 {
|
sl@0
|
94 |
execsql {SELECT min(x) FROM t1 WHERE x>=4.5}
|
sl@0
|
95 |
} {5}
|
sl@0
|
96 |
do_test minmax-1.24 {
|
sl@0
|
97 |
execsql {SELECT min(x) FROM t1 WHERE x<4.5}
|
sl@0
|
98 |
} {1}
|
sl@0
|
99 |
|
sl@0
|
100 |
do_test minmax-2.0 {
|
sl@0
|
101 |
execsql {
|
sl@0
|
102 |
CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
|
sl@0
|
103 |
INSERT INTO t2 SELECT * FROM t1;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
set sqlite_search_count 0
|
sl@0
|
106 |
execsql {SELECT min(a) FROM t2}
|
sl@0
|
107 |
} {1}
|
sl@0
|
108 |
do_test minmax-2.1 {
|
sl@0
|
109 |
set sqlite_search_count
|
sl@0
|
110 |
} {0}
|
sl@0
|
111 |
do_test minmax-2.2 {
|
sl@0
|
112 |
set sqlite_search_count 0
|
sl@0
|
113 |
execsql {SELECT max(a) FROM t2}
|
sl@0
|
114 |
} {20}
|
sl@0
|
115 |
do_test minmax-2.3 {
|
sl@0
|
116 |
set sqlite_search_count
|
sl@0
|
117 |
} {0}
|
sl@0
|
118 |
|
sl@0
|
119 |
do_test minmax-3.0 {
|
sl@0
|
120 |
ifcapable subquery {
|
sl@0
|
121 |
execsql {INSERT INTO t2 VALUES((SELECT max(a) FROM t2)+1,999)}
|
sl@0
|
122 |
} else {
|
sl@0
|
123 |
db function max_a_t2 {execsql {SELECT max(a) FROM t2}}
|
sl@0
|
124 |
execsql {INSERT INTO t2 VALUES(max_a_t2()+1,999)}
|
sl@0
|
125 |
}
|
sl@0
|
126 |
set sqlite_search_count 0
|
sl@0
|
127 |
execsql {SELECT max(a) FROM t2}
|
sl@0
|
128 |
} {21}
|
sl@0
|
129 |
do_test minmax-3.1 {
|
sl@0
|
130 |
set sqlite_search_count
|
sl@0
|
131 |
} {0}
|
sl@0
|
132 |
do_test minmax-3.2 {
|
sl@0
|
133 |
ifcapable subquery {
|
sl@0
|
134 |
execsql {INSERT INTO t2 VALUES((SELECT max(a) FROM t2)+1,999)}
|
sl@0
|
135 |
} else {
|
sl@0
|
136 |
db function max_a_t2 {execsql {SELECT max(a) FROM t2}}
|
sl@0
|
137 |
execsql {INSERT INTO t2 VALUES(max_a_t2()+1,999)}
|
sl@0
|
138 |
}
|
sl@0
|
139 |
set sqlite_search_count 0
|
sl@0
|
140 |
ifcapable subquery {
|
sl@0
|
141 |
execsql { SELECT b FROM t2 WHERE a=(SELECT max(a) FROM t2) }
|
sl@0
|
142 |
} else {
|
sl@0
|
143 |
execsql { SELECT b FROM t2 WHERE a=max_a_t2() }
|
sl@0
|
144 |
}
|
sl@0
|
145 |
} {999}
|
sl@0
|
146 |
do_test minmax-3.3 {
|
sl@0
|
147 |
set sqlite_search_count
|
sl@0
|
148 |
} {0}
|
sl@0
|
149 |
|
sl@0
|
150 |
ifcapable {compound && subquery} {
|
sl@0
|
151 |
do_test minmax-4.1 {
|
sl@0
|
152 |
execsql {
|
sl@0
|
153 |
SELECT coalesce(min(x+0),-1), coalesce(max(x+0),-1) FROM
|
sl@0
|
154 |
(SELECT * FROM t1 UNION SELECT NULL as 'x', NULL as 'y')
|
sl@0
|
155 |
}
|
sl@0
|
156 |
} {1 20}
|
sl@0
|
157 |
do_test minmax-4.2 {
|
sl@0
|
158 |
execsql {
|
sl@0
|
159 |
SELECT y, coalesce(sum(x),0) FROM
|
sl@0
|
160 |
(SELECT null AS x, y+1 AS y FROM t1 UNION SELECT * FROM t1)
|
sl@0
|
161 |
GROUP BY y ORDER BY y;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
} {1 1 2 5 3 22 4 92 5 90 6 0}
|
sl@0
|
164 |
do_test minmax-4.3 {
|
sl@0
|
165 |
execsql {
|
sl@0
|
166 |
SELECT y, count(x), count(*) FROM
|
sl@0
|
167 |
(SELECT null AS x, y+1 AS y FROM t1 UNION SELECT * FROM t1)
|
sl@0
|
168 |
GROUP BY y ORDER BY y;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
} {1 1 1 2 2 3 3 4 5 4 8 9 5 5 6 6 0 1}
|
sl@0
|
171 |
} ;# ifcapable compound
|
sl@0
|
172 |
|
sl@0
|
173 |
# Make sure the min(x) and max(x) optimizations work on empty tables
|
sl@0
|
174 |
# including empty tables with indices. Ticket #296.
|
sl@0
|
175 |
#
|
sl@0
|
176 |
do_test minmax-5.1 {
|
sl@0
|
177 |
execsql {
|
sl@0
|
178 |
CREATE TABLE t3(x INTEGER UNIQUE NOT NULL);
|
sl@0
|
179 |
SELECT coalesce(min(x),999) FROM t3;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
} {999}
|
sl@0
|
182 |
do_test minmax-5.2 {
|
sl@0
|
183 |
execsql {
|
sl@0
|
184 |
SELECT coalesce(min(rowid),999) FROM t3;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
} {999}
|
sl@0
|
187 |
do_test minmax-5.3 {
|
sl@0
|
188 |
execsql {
|
sl@0
|
189 |
SELECT coalesce(max(x),999) FROM t3;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
} {999}
|
sl@0
|
192 |
do_test minmax-5.4 {
|
sl@0
|
193 |
execsql {
|
sl@0
|
194 |
SELECT coalesce(max(rowid),999) FROM t3;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
} {999}
|
sl@0
|
197 |
do_test minmax-5.5 {
|
sl@0
|
198 |
execsql {
|
sl@0
|
199 |
SELECT coalesce(max(rowid),999) FROM t3 WHERE rowid<25;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
} {999}
|
sl@0
|
202 |
|
sl@0
|
203 |
# Make sure the min(x) and max(x) optimizations work when there
|
sl@0
|
204 |
# is a LIMIT clause. Ticket #396.
|
sl@0
|
205 |
#
|
sl@0
|
206 |
do_test minmax-6.1 {
|
sl@0
|
207 |
execsql {
|
sl@0
|
208 |
SELECT min(a) FROM t2 LIMIT 1
|
sl@0
|
209 |
}
|
sl@0
|
210 |
} {1}
|
sl@0
|
211 |
do_test minmax-6.2 {
|
sl@0
|
212 |
execsql {
|
sl@0
|
213 |
SELECT max(a) FROM t2 LIMIT 3
|
sl@0
|
214 |
}
|
sl@0
|
215 |
} {22}
|
sl@0
|
216 |
do_test minmax-6.3 {
|
sl@0
|
217 |
execsql {
|
sl@0
|
218 |
SELECT min(a) FROM t2 LIMIT 0,100
|
sl@0
|
219 |
}
|
sl@0
|
220 |
} {1}
|
sl@0
|
221 |
do_test minmax-6.4 {
|
sl@0
|
222 |
execsql {
|
sl@0
|
223 |
SELECT max(a) FROM t2 LIMIT 1,100
|
sl@0
|
224 |
}
|
sl@0
|
225 |
} {}
|
sl@0
|
226 |
do_test minmax-6.5 {
|
sl@0
|
227 |
execsql {
|
sl@0
|
228 |
SELECT min(x) FROM t3 LIMIT 1
|
sl@0
|
229 |
}
|
sl@0
|
230 |
} {{}}
|
sl@0
|
231 |
do_test minmax-6.6 {
|
sl@0
|
232 |
execsql {
|
sl@0
|
233 |
SELECT max(x) FROM t3 LIMIT 0
|
sl@0
|
234 |
}
|
sl@0
|
235 |
} {}
|
sl@0
|
236 |
do_test minmax-6.7 {
|
sl@0
|
237 |
execsql {
|
sl@0
|
238 |
SELECT max(a) FROM t2 LIMIT 0
|
sl@0
|
239 |
}
|
sl@0
|
240 |
} {}
|
sl@0
|
241 |
|
sl@0
|
242 |
# Make sure the max(x) and min(x) optimizations work for nested
|
sl@0
|
243 |
# queries. Ticket #587.
|
sl@0
|
244 |
#
|
sl@0
|
245 |
do_test minmax-7.1 {
|
sl@0
|
246 |
execsql {
|
sl@0
|
247 |
SELECT max(x) FROM t1;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
} 20
|
sl@0
|
250 |
ifcapable subquery {
|
sl@0
|
251 |
do_test minmax-7.2 {
|
sl@0
|
252 |
execsql {
|
sl@0
|
253 |
SELECT * FROM (SELECT max(x) FROM t1);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
} 20
|
sl@0
|
256 |
}
|
sl@0
|
257 |
do_test minmax-7.3 {
|
sl@0
|
258 |
execsql {
|
sl@0
|
259 |
SELECT min(x) FROM t1;
|
sl@0
|
260 |
}
|
sl@0
|
261 |
} 1
|
sl@0
|
262 |
ifcapable subquery {
|
sl@0
|
263 |
do_test minmax-7.4 {
|
sl@0
|
264 |
execsql {
|
sl@0
|
265 |
SELECT * FROM (SELECT min(x) FROM t1);
|
sl@0
|
266 |
}
|
sl@0
|
267 |
} 1
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
# Make sure min(x) and max(x) work correctly when the datatype is
|
sl@0
|
271 |
# TEXT instead of NUMERIC. Ticket #623.
|
sl@0
|
272 |
#
|
sl@0
|
273 |
do_test minmax-8.1 {
|
sl@0
|
274 |
execsql {
|
sl@0
|
275 |
CREATE TABLE t4(a TEXT);
|
sl@0
|
276 |
INSERT INTO t4 VALUES('1234');
|
sl@0
|
277 |
INSERT INTO t4 VALUES('234');
|
sl@0
|
278 |
INSERT INTO t4 VALUES('34');
|
sl@0
|
279 |
SELECT min(a), max(a) FROM t4;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
} {1234 34}
|
sl@0
|
282 |
do_test minmax-8.2 {
|
sl@0
|
283 |
execsql {
|
sl@0
|
284 |
CREATE TABLE t5(a INTEGER);
|
sl@0
|
285 |
INSERT INTO t5 VALUES('1234');
|
sl@0
|
286 |
INSERT INTO t5 VALUES('234');
|
sl@0
|
287 |
INSERT INTO t5 VALUES('34');
|
sl@0
|
288 |
SELECT min(a), max(a) FROM t5;
|
sl@0
|
289 |
}
|
sl@0
|
290 |
} {34 1234}
|
sl@0
|
291 |
|
sl@0
|
292 |
# Ticket #658: Test the min()/max() optimization when the FROM clause
|
sl@0
|
293 |
# is a subquery.
|
sl@0
|
294 |
#
|
sl@0
|
295 |
ifcapable {compound && subquery} {
|
sl@0
|
296 |
do_test minmax-9.1 {
|
sl@0
|
297 |
execsql {
|
sl@0
|
298 |
SELECT max(rowid) FROM (
|
sl@0
|
299 |
SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5
|
sl@0
|
300 |
)
|
sl@0
|
301 |
}
|
sl@0
|
302 |
} {1}
|
sl@0
|
303 |
do_test minmax-9.2 {
|
sl@0
|
304 |
execsql {
|
sl@0
|
305 |
SELECT max(rowid) FROM (
|
sl@0
|
306 |
SELECT max(rowid) FROM t4 EXCEPT SELECT max(rowid) FROM t5
|
sl@0
|
307 |
)
|
sl@0
|
308 |
}
|
sl@0
|
309 |
} {{}}
|
sl@0
|
310 |
} ;# ifcapable compound&&subquery
|
sl@0
|
311 |
|
sl@0
|
312 |
# If there is a NULL in an aggregate max() or min(), ignore it. An
|
sl@0
|
313 |
# aggregate min() or max() will only return NULL if all values are NULL.
|
sl@0
|
314 |
#
|
sl@0
|
315 |
do_test minmax-10.1 {
|
sl@0
|
316 |
execsql {
|
sl@0
|
317 |
CREATE TABLE t6(x);
|
sl@0
|
318 |
INSERT INTO t6 VALUES(1);
|
sl@0
|
319 |
INSERT INTO t6 VALUES(2);
|
sl@0
|
320 |
INSERT INTO t6 VALUES(NULL);
|
sl@0
|
321 |
SELECT coalesce(min(x),-1) FROM t6;
|
sl@0
|
322 |
}
|
sl@0
|
323 |
} {1}
|
sl@0
|
324 |
do_test minmax-10.2 {
|
sl@0
|
325 |
execsql {
|
sl@0
|
326 |
SELECT max(x) FROM t6;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
} {2}
|
sl@0
|
329 |
do_test minmax-10.3 {
|
sl@0
|
330 |
execsql {
|
sl@0
|
331 |
CREATE INDEX i6 ON t6(x);
|
sl@0
|
332 |
SELECT coalesce(min(x),-1) FROM t6;
|
sl@0
|
333 |
}
|
sl@0
|
334 |
} {1}
|
sl@0
|
335 |
do_test minmax-10.4 {
|
sl@0
|
336 |
execsql {
|
sl@0
|
337 |
SELECT max(x) FROM t6;
|
sl@0
|
338 |
}
|
sl@0
|
339 |
} {2}
|
sl@0
|
340 |
do_test minmax-10.5 {
|
sl@0
|
341 |
execsql {
|
sl@0
|
342 |
DELETE FROM t6 WHERE x NOT NULL;
|
sl@0
|
343 |
SELECT count(*) FROM t6;
|
sl@0
|
344 |
}
|
sl@0
|
345 |
} 1
|
sl@0
|
346 |
do_test minmax-10.6 {
|
sl@0
|
347 |
execsql {
|
sl@0
|
348 |
SELECT count(x) FROM t6;
|
sl@0
|
349 |
}
|
sl@0
|
350 |
} 0
|
sl@0
|
351 |
ifcapable subquery {
|
sl@0
|
352 |
do_test minmax-10.7 {
|
sl@0
|
353 |
execsql {
|
sl@0
|
354 |
SELECT (SELECT min(x) FROM t6), (SELECT max(x) FROM t6);
|
sl@0
|
355 |
}
|
sl@0
|
356 |
} {{} {}}
|
sl@0
|
357 |
}
|
sl@0
|
358 |
do_test minmax-10.8 {
|
sl@0
|
359 |
execsql {
|
sl@0
|
360 |
SELECT min(x), max(x) FROM t6;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
} {{} {}}
|
sl@0
|
363 |
do_test minmax-10.9 {
|
sl@0
|
364 |
execsql {
|
sl@0
|
365 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
366 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
367 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
368 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
369 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
370 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
371 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
372 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
373 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
374 |
INSERT INTO t6 SELECT * FROM t6;
|
sl@0
|
375 |
SELECT count(*) FROM t6;
|
sl@0
|
376 |
}
|
sl@0
|
377 |
} 1024
|
sl@0
|
378 |
do_test minmax-10.10 {
|
sl@0
|
379 |
execsql {
|
sl@0
|
380 |
SELECT count(x) FROM t6;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
} 0
|
sl@0
|
383 |
ifcapable subquery {
|
sl@0
|
384 |
do_test minmax-10.11 {
|
sl@0
|
385 |
execsql {
|
sl@0
|
386 |
SELECT (SELECT min(x) FROM t6), (SELECT max(x) FROM t6);
|
sl@0
|
387 |
}
|
sl@0
|
388 |
} {{} {}}
|
sl@0
|
389 |
}
|
sl@0
|
390 |
do_test minmax-10.12 {
|
sl@0
|
391 |
execsql {
|
sl@0
|
392 |
SELECT min(x), max(x) FROM t6;
|
sl@0
|
393 |
}
|
sl@0
|
394 |
} {{} {}}
|
sl@0
|
395 |
|
sl@0
|
396 |
|
sl@0
|
397 |
do_test minmax-11.1 {
|
sl@0
|
398 |
execsql {
|
sl@0
|
399 |
CREATE INDEX t1i2 ON t1(y,x);
|
sl@0
|
400 |
SELECT min(x) FROM t1 WHERE y=5;
|
sl@0
|
401 |
}
|
sl@0
|
402 |
} {16}
|
sl@0
|
403 |
do_test minmax-11.2 {
|
sl@0
|
404 |
execsql {
|
sl@0
|
405 |
SELECT max(x) FROM t1 WHERE y=5;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
} {20}
|
sl@0
|
408 |
do_test minmax-11.3 {
|
sl@0
|
409 |
execsql {
|
sl@0
|
410 |
SELECT min(x) FROM t1 WHERE y=6;
|
sl@0
|
411 |
}
|
sl@0
|
412 |
} {{}}
|
sl@0
|
413 |
do_test minmax-11.4 {
|
sl@0
|
414 |
execsql {
|
sl@0
|
415 |
SELECT max(x) FROM t1 WHERE y=6;
|
sl@0
|
416 |
}
|
sl@0
|
417 |
} {{}}
|
sl@0
|
418 |
do_test minmax-11.5 {
|
sl@0
|
419 |
execsql {
|
sl@0
|
420 |
SELECT min(x) FROM t1 WHERE y=1;
|
sl@0
|
421 |
}
|
sl@0
|
422 |
} {1}
|
sl@0
|
423 |
do_test minmax-11.6 {
|
sl@0
|
424 |
execsql {
|
sl@0
|
425 |
SELECT max(x) FROM t1 WHERE y=1;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
} {1}
|
sl@0
|
428 |
do_test minmax-11.7 {
|
sl@0
|
429 |
execsql {
|
sl@0
|
430 |
SELECT min(x) FROM t1 WHERE y=0;
|
sl@0
|
431 |
}
|
sl@0
|
432 |
} {{}}
|
sl@0
|
433 |
do_test minmax-11.8 {
|
sl@0
|
434 |
execsql {
|
sl@0
|
435 |
SELECT max(x) FROM t1 WHERE y=0;
|
sl@0
|
436 |
}
|
sl@0
|
437 |
} {{}}
|
sl@0
|
438 |
do_test minmax-11.9 {
|
sl@0
|
439 |
execsql {
|
sl@0
|
440 |
SELECT min(x) FROM t1 WHERE y=5 AND x>=17.5;
|
sl@0
|
441 |
}
|
sl@0
|
442 |
} {18}
|
sl@0
|
443 |
do_test minmax-11.10 {
|
sl@0
|
444 |
execsql {
|
sl@0
|
445 |
SELECT max(x) FROM t1 WHERE y=5 AND x>=17.5;
|
sl@0
|
446 |
}
|
sl@0
|
447 |
} {20}
|
sl@0
|
448 |
|
sl@0
|
449 |
do_test minmax-12.1 {
|
sl@0
|
450 |
execsql {
|
sl@0
|
451 |
CREATE TABLE t7(a,b,c);
|
sl@0
|
452 |
INSERT INTO t7 SELECT y, x, x*y FROM t1;
|
sl@0
|
453 |
INSERT INTO t7 SELECT y, x, x*y+1000 FROM t1;
|
sl@0
|
454 |
CREATE INDEX t7i1 ON t7(a,b,c);
|
sl@0
|
455 |
SELECT min(a) FROM t7;
|
sl@0
|
456 |
}
|
sl@0
|
457 |
} {1}
|
sl@0
|
458 |
do_test minmax-12.2 {
|
sl@0
|
459 |
execsql {
|
sl@0
|
460 |
SELECT max(a) FROM t7;
|
sl@0
|
461 |
}
|
sl@0
|
462 |
} {5}
|
sl@0
|
463 |
do_test minmax-12.3 {
|
sl@0
|
464 |
execsql {
|
sl@0
|
465 |
SELECT max(a) FROM t7 WHERE a=5;
|
sl@0
|
466 |
}
|
sl@0
|
467 |
} {5}
|
sl@0
|
468 |
do_test minmax-12.4 {
|
sl@0
|
469 |
execsql {
|
sl@0
|
470 |
SELECT min(b) FROM t7 WHERE a=5;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
} {16}
|
sl@0
|
473 |
do_test minmax-12.5 {
|
sl@0
|
474 |
execsql {
|
sl@0
|
475 |
SELECT max(b) FROM t7 WHERE a=5;
|
sl@0
|
476 |
}
|
sl@0
|
477 |
} {20}
|
sl@0
|
478 |
do_test minmax-12.6 {
|
sl@0
|
479 |
execsql {
|
sl@0
|
480 |
SELECT min(b) FROM t7 WHERE a=4;
|
sl@0
|
481 |
}
|
sl@0
|
482 |
} {8}
|
sl@0
|
483 |
do_test minmax-12.7 {
|
sl@0
|
484 |
execsql {
|
sl@0
|
485 |
SELECT max(b) FROM t7 WHERE a=4;
|
sl@0
|
486 |
}
|
sl@0
|
487 |
} {15}
|
sl@0
|
488 |
do_test minmax-12.8 {
|
sl@0
|
489 |
execsql {
|
sl@0
|
490 |
SELECT min(c) FROM t7 WHERE a=4 AND b=10;
|
sl@0
|
491 |
}
|
sl@0
|
492 |
} {40}
|
sl@0
|
493 |
do_test minmax-12.9 {
|
sl@0
|
494 |
execsql {
|
sl@0
|
495 |
SELECT max(c) FROM t7 WHERE a=4 AND b=10;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
} {1040}
|
sl@0
|
498 |
do_test minmax-12.10 {
|
sl@0
|
499 |
execsql {
|
sl@0
|
500 |
SELECT min(rowid) FROM t7;
|
sl@0
|
501 |
}
|
sl@0
|
502 |
} {1}
|
sl@0
|
503 |
do_test minmax-12.11 {
|
sl@0
|
504 |
execsql {
|
sl@0
|
505 |
SELECT max(rowid) FROM t7;
|
sl@0
|
506 |
}
|
sl@0
|
507 |
} {40}
|
sl@0
|
508 |
do_test minmax-12.12 {
|
sl@0
|
509 |
execsql {
|
sl@0
|
510 |
SELECT min(rowid) FROM t7 WHERE a=3;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
} {4}
|
sl@0
|
513 |
do_test minmax-12.13 {
|
sl@0
|
514 |
execsql {
|
sl@0
|
515 |
SELECT max(rowid) FROM t7 WHERE a=3;
|
sl@0
|
516 |
}
|
sl@0
|
517 |
} {27}
|
sl@0
|
518 |
do_test minmax-12.14 {
|
sl@0
|
519 |
execsql {
|
sl@0
|
520 |
SELECT min(rowid) FROM t7 WHERE a=3 AND b=5;
|
sl@0
|
521 |
}
|
sl@0
|
522 |
} {5}
|
sl@0
|
523 |
do_test minmax-12.15 {
|
sl@0
|
524 |
execsql {
|
sl@0
|
525 |
SELECT max(rowid) FROM t7 WHERE a=3 AND b=5;
|
sl@0
|
526 |
}
|
sl@0
|
527 |
} {25}
|
sl@0
|
528 |
do_test minmax-12.16 {
|
sl@0
|
529 |
execsql {
|
sl@0
|
530 |
SELECT min(rowid) FROM t7 WHERE a=3 AND b=5 AND c=1015;
|
sl@0
|
531 |
}
|
sl@0
|
532 |
} {25}
|
sl@0
|
533 |
do_test minmax-12.17 {
|
sl@0
|
534 |
execsql {
|
sl@0
|
535 |
SELECT max(rowid) FROM t7 WHERE a=3 AND b=5 AND c=15;
|
sl@0
|
536 |
}
|
sl@0
|
537 |
} {5}
|
sl@0
|
538 |
|
sl@0
|
539 |
|
sl@0
|
540 |
|
sl@0
|
541 |
|
sl@0
|
542 |
finish_test
|