Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: third_party/sqlite/src/test/subquery.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2005 January 19 1 # 2005 January 19
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #************************************************************************* 10 #*************************************************************************
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 do_test subquery-2.5.3.1 { 234 do_test subquery-2.5.3.1 {
235 # The t4i index cannot be used to resolve the "x IN (...)" constraint 235 # The t4i index cannot be used to resolve the "x IN (...)" constraint
236 # because the constraint has integer affinity but t4i has text affinity. 236 # because the constraint has integer affinity but t4i has text affinity.
237 execsql { 237 execsql {
238 CREATE INDEX t4i ON t4(x); 238 CREATE INDEX t4i ON t4(x);
239 SELECT * FROM t4 WHERE x IN (SELECT a FROM t3); 239 SELECT * FROM t4 WHERE x IN (SELECT a FROM t3);
240 } 240 }
241 } {10.0} 241 } {10.0}
242 do_test subquery-2.5.3.2 { 242 do_test subquery-2.5.3.2 {
243 # Verify that the t4i index was not used in the previous query 243 # Verify that the t4i index was not used in the previous query
244 set ::sqlite_query_plan 244 execsql {
245 } {t4 {}} 245 EXPLAIN QUERY PLAN
246 SELECT * FROM t4 WHERE x IN (SELECT a FROM t3);
247 }
248 } {~/t4i/}
246 do_test subquery-2.5.4 { 249 do_test subquery-2.5.4 {
247 execsql { 250 execsql {
248 DROP TABLE t3; 251 DROP TABLE t3;
249 DROP TABLE t4; 252 DROP TABLE t4;
250 } 253 }
251 } {} 254 } {}
252 255
253 #------------------------------------------------------------------ 256 #------------------------------------------------------------------
254 # The following test cases - subquery-3.* - test tickets that 257 # The following test cases - subquery-3.* - test tickets that
255 # were raised during development of correlated subqueries. 258 # were raised during development of correlated subqueries.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 execsql { 327 execsql {
325 SELECT a, (SELECT (SELECT d FROM t2 WHERE a=c)) FROM t1 GROUP BY a; 328 SELECT a, (SELECT (SELECT d FROM t2 WHERE a=c)) FROM t1 GROUP BY a;
326 } 329 }
327 } {1 one 2 two} 330 } {1 one 2 two}
328 do_test subquery-3.3.5 { 331 do_test subquery-3.3.5 {
329 execsql { 332 execsql {
330 SELECT a, (SELECT count(*) FROM t2 WHERE a=c) FROM t1; 333 SELECT a, (SELECT count(*) FROM t2 WHERE a=c) FROM t1;
331 } 334 }
332 } {1 1 2 1} 335 } {1 1 2 1}
333 336
337 # The following tests check for aggregate subqueries in an aggregate
338 # query.
339 #
340 do_test subquery-3.4.1 {
341 execsql {
342 CREATE TABLE t34(x,y);
343 INSERT INTO t34 VALUES(106,4), (107,3), (106,5), (107,5);
344 SELECT a.x, avg(a.y)
345 FROM t34 AS a
346 GROUP BY a.x
347 HAVING NOT EXISTS( SELECT b.x, avg(b.y)
348 FROM t34 AS b
349 GROUP BY b.x
350 HAVING avg(a.y) > avg(b.y));
351 }
352 } {107 4.0}
353 do_test subquery-3.4.2 {
354 execsql {
355 SELECT a.x, avg(a.y) AS avg1
356 FROM t34 AS a
357 GROUP BY a.x
358 HAVING NOT EXISTS( SELECT b.x, avg(b.y) AS avg2
359 FROM t34 AS b
360 GROUP BY b.x
361 HAVING avg1 > avg2);
362 }
363 } {107 4.0}
364 do_test subquery-3.4.3 {
365 execsql {
366 SELECT
367 a.x,
368 avg(a.y),
369 NOT EXISTS ( SELECT b.x, avg(b.y)
370 FROM t34 AS b
371 GROUP BY b.x
372 HAVING avg(a.y) > avg(b.y)),
373 EXISTS ( SELECT c.x, avg(c.y)
374 FROM t34 AS c
375 GROUP BY c.x
376 HAVING avg(a.y) > avg(c.y))
377 FROM t34 AS a
378 GROUP BY a.x
379 ORDER BY a.x;
380 }
381 } {106 4.5 0 1 107 4.0 1 0}
382
383 do_test subquery-3.5.1 {
384 execsql {
385 CREATE TABLE t35a(x); INSERT INTO t35a VALUES(1),(2),(3);
386 CREATE TABLE t35b(y); INSERT INTO t35b VALUES(98), (99);
387 SELECT max((SELECT avg(y) FROM t35b)) FROM t35a;
388 }
389 } {98.5}
390 do_test subquery-3.5.2 {
391 execsql {
392 SELECT max((SELECT count(y) FROM t35b)) FROM t35a;
393 }
394 } {2}
395 do_test subquery-3.5.3 {
396 execsql {
397 SELECT max((SELECT count() FROM t35b)) FROM t35a;
398 }
399 } {2}
400 do_test subquery-3.5.4 {
401 catchsql {
402 SELECT max((SELECT count(x) FROM t35b)) FROM t35a;
403 }
404 } {1 {misuse of aggregate: count()}}
405 do_test subquery-3.5.5 {
406 catchsql {
407 SELECT max((SELECT count(x) FROM t35b)) FROM t35a;
408 }
409 } {1 {misuse of aggregate: count()}}
410 do_test subquery-3.5.6 {
411 catchsql {
412 SELECT max((SELECT a FROM (SELECT count(x) AS a FROM t35b))) FROM t35a;
413 }
414 } {1 {misuse of aggregate: count()}}
415 do_test subquery-3.5.7 {
416 execsql {
417 SELECT max((SELECT a FROM (SELECT count(y) AS a FROM t35b))) FROM t35a;
418 }
419 } {2}
420
421
334 #------------------------------------------------------------------ 422 #------------------------------------------------------------------
335 # These tests - subquery-4.* - use the TCL statement cache to try 423 # These tests - subquery-4.* - use the TCL statement cache to try
336 # and expose bugs to do with re-using statements that have been 424 # and expose bugs to do with re-using statements that have been
337 # passed to sqlite3_reset(). 425 # passed to sqlite3_reset().
338 # 426 #
339 # One problem was that VDBE memory cells were not being initialised 427 # One problem was that VDBE memory cells were not being initialized
340 # to NULL on the second and subsequent executions. 428 # to NULL on the second and subsequent executions.
341 # 429 #
342 do_test subquery-4.1.1 { 430 do_test subquery-4.1.1 {
343 execsql { 431 execsql {
344 SELECT (SELECT a FROM t1); 432 SELECT (SELECT a FROM t1);
345 } 433 }
346 } {1} 434 } {1}
347 do_test subquery-4.2 { 435 do_test subquery-4.2 {
348 execsql { 436 execsql {
349 DELETE FROM t1; 437 DELETE FROM t1;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 578 }
491 } {30101 30102 30103} 579 } {30101 30102 30103}
492 do_test subquery-7.11 { 580 do_test subquery-7.11 {
493 execsql { 581 execsql {
494 SELECT (SELECT (SELECT max(c7)+max(c8)+max(c9) FROM t9) FROM t8) FROM t7 582 SELECT (SELECT (SELECT max(c7)+max(c8)+max(c9) FROM t9) FROM t8) FROM t7
495 } 583 }
496 } {30303} 584 } {30303}
497 } ;############# Disabled 585 } ;############# Disabled
498 586
499 finish_test 587 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698