]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fixes for OMIT_SUBQUERY builds: Disable where clause OR->IN optimization. Include...
authordanielk1977 <danielk1977@noemail.net>
Sat, 14 Jan 2006 08:02:28 +0000 (08:02 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Sat, 14 Jan 2006 08:02:28 +0000 (08:02 +0000)
FossilOrigin-Name: 8e79a0c24a03ccf960d6ccfb7c6b9b0f7c614e9b

17 files changed:
manifest
manifest.uuid
src/where.c
test/alter.test
test/check.test
test/descidx3.test
test/misc2.test
test/misc5.test
test/select1.test
test/shared.test
test/tkt1443.test
test/tkt1449.test
test/tkt1473.test
test/tkt1537.test
test/view.test
test/where2.test
tool/mkkeywordhash.c

index c7b2f07a743934a479f8352f5daf90b491fb86f2..64601a8e08ec696bbee00ace2dc2326352549453 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Account\sfor\smulti-byte\scharacters\sin\sALTER\sTABLE\scode.\sFix\sfor\s#1609.\s(CVS\s2942)
-D 2006-01-13T18:06:40
+C Fixes\sfor\sOMIT_SUBQUERY\sbuilds:\sDisable\swhere\sclause\sOR->IN\soptimization.\sInclude\sEXISTS\skeyword\s(for\snew\sCREATE\sTABLE\ssyntax).\sTest\sfile\sfixes.\s(CVS\s2943)
+D 2006-01-14T08:02:28
 F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -94,10 +94,10 @@ F src/vdbeapi.c afd3837cea0dec93dcb4724d073c84fa0da68e23
 F src/vdbeaux.c 1d765d671ae31a067b2b064c3f193690f91eea62
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c dd08a0eea4868ac4a2d91fdec32424308b1db772
-F src/where.c 6885d655f3f7fb6455fcf5174c7119b1ce3ed860
+F src/where.c 9fd58a8f5525d036a088c92bb14e2885c2243bc8
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/all.test a23fcbbf1f53515bde840d78732a6d94c673b327
-F test/alter.test 55362362d427682bec6e5087aa0d38fc00198ef4
+F test/alter.test 2678f1ac6d6f7332623c5df249f58eeaa144a302
 F test/alter2.test cc0b8832e4e98605dbc26910efd4bb89abe59cb2
 F test/alter3.test 6e144ea3dcc395afcc28e794bb532be83dc8fdcb
 F test/altermalloc.test 6e1f404ec021eb2ba6582e3c77b0a35cf206b7af
@@ -132,7 +132,7 @@ F test/capi2.test b9354d6c37e6f8f858c08952ebc9709712581221
 F test/capi3.test 318098b606490b2e29c6228743e5c4b37da8c368
 F test/capi3b.test 5f0bc94b104e11086b1103b20277e1910f59c7f4
 F test/cast.test 2543165ced4249c89ce5f0352222df503a98b9e5
-F test/check.test 8154b8ac0c56c34088168b8d87eee713fba2b31b
+F test/check.test 686df5fd9fb986198787f00a79d86b68feb02e32
 F test/collate1.test add9454cef160677bb8b34148b8f277ce7f9f1c4
 F test/collate2.test 224a632ba04907c049804b08162efd234aa7871f
 F test/collate3.test 947a77f5b8227e037a7094d0e338a5504f155cc4
@@ -151,7 +151,7 @@ F test/delete2.test d20b08733243f1890079f3b48f2356fbb62212b2
 F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
 F test/descidx1.test 616076c4fd7efb0098a69a53f965af6e1eb4e7ca
 F test/descidx2.test f9f73c562932b81207faa525cd52acdfd2fc0482
-F test/descidx3.test 56daed47e2eb91cef15a21a656691bb82a4699ba
+F test/descidx3.test b826d067392d48387f19f70f2ea51a93fd0d4ec1
 F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
 F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
 F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
@@ -196,10 +196,10 @@ F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
 F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
 F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
 F test/misc1.test 7aabf32e698ef7cc1253f5e7fc216c65870ce485
-F test/misc2.test 5c699af2fede2694736a9f45aea7e2f052686e15
+F test/misc2.test 17949ae34df8a60e318b2a14492b8cb62cd2072a
 F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
 F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80
-F test/misc5.test a27520a0033f2837cda94bfdfb096a25fc4b128d
+F test/misc5.test 129e19d3844bcc928051a30de34268e28a4bea6f
 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test db52272f9628ae9e77ab451cf0fb3871a98c5f00
@@ -217,7 +217,7 @@ F test/rollback.test fc6be5a5e4b1347fd96777c65484a24fc75e8f0e
 F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
 F test/safety.test 4a06934e45d03b8b50ebcd8d174eb0367d2fd851
 F test/schema.test 8a2ae440fb15f5798a68059e8746402f3137be46
-F test/select1.test ed95ce4c27ab390bcd2d573a0c77ad42599b8a88
+F test/select1.test f4ab4b66e7089f0c64b6df954e75bafe05aabc0d
 F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
 F test/select3.test 8fece41cd8f2955131b3f973a7123bec60b6e65e
 F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
@@ -225,7 +225,7 @@ F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b
 F test/select6.test f459a19bdac0501c4d3eb1a4df4b7a76f1bb8ad4
 F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
 F test/server1.test 9d2d5b17b537911214a7e2a2728ff4f6ff16319c
-F test/shared.test b94678497bf6051faf68ecb1f692d5cc04b8d330
+F test/shared.test 2a7ae35bbf0f805cb9782146f5e812003ee8d1dc
 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
 F test/subquery.test e6de53332c0301b3cfa34edc3f3cd5fa1e859efd
 F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
@@ -239,15 +239,15 @@ F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
 F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
 F test/tkt1435.test f768e5415d102fa1d8de3f548469d8fd1b79abd8
-F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
+F test/tkt1443.test bbd1fa7070783845aa42cdd35867a5ac73e5947a
 F test/tkt1444.test 5ef55d36dba1a39a96c728a519e66378a6f6816f
-F test/tkt1449.test f8de8a84ec12ee805ed80055e1209560f8bee4d8
-F test/tkt1473.test e4637c27d606fd002de78113a8e1a142e48ffb18
+F test/tkt1449.test 541021eb3c652848deb44f1407d692a9c42b6099
+F test/tkt1473.test 0c7f4e94946d5e420c0f4ce393d05703b729a848
 F test/tkt1501.test 0cf859299f0052ecfaf7db6f0984f122c7db5d15
 F test/tkt1512.test 8efd8d07e27e99d7462f75b5711de65eb7708baf
 F test/tkt1514.test baa587a69fa2e8d575ebdaf1460f711281dcba49
 F test/tkt1536.test 83ff7a7b6e248016f8d682d4f7a4ae114070d466
-F test/tkt1537.test 8e6c8399b5be8abeaac18ca17133990806b175fa
+F test/tkt1537.test e3a14332de9770be8ff14bd15c19a49cbec10808
 F test/tkt1567.test 18023cc3626a365f0118e17b66decedec93b1a6f
 F test/trace.test 75ffc1b992c780d054748a656e3e7fd674f18567
 F test/trans.test abd2f74c5685b156d79438e6e812db5bf984eea4
@@ -267,16 +267,16 @@ F test/utf16.test f9c13f4e2b48c42d0bfc96647d82fdf7bc11fc55
 F test/vacuum.test 37f998b841cb335397c26d9bbc3457182af2565f
 F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
-F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
+F test/view.test 354bd0ceb363e88da8ce98fb47e18550d7594b13
 F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df
-F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
+F test/where2.test d85bd79cdd9e3226f25f7c4d1de3f211083a25e3
 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/lemon.c 26d271a753ef87fe1e6194f53c594ab5e6783d85
 F tool/lempar.c 424df14a48736bb961ed47acf30c26d66ed85a62
 F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
 F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
 F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
-F tool/mkkeywordhash.c 9b4d521e1dbd3afbfb8d861f5309fc31ef218a0d
+F tool/mkkeywordhash.c fa58d31c047fa3411761b01907d6df05781970d6
 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
 F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
@@ -340,7 +340,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 2d74cc22de2aa59329b1ea5c26acd6ebe46e16c2
-R 4a0b32395646e93911e1e578ba0ad36a
+P d634f8b28abd7af4565c644bd7972b067caa0133
+R e68269cdd28a8797bb4063cb46df0175
 U danielk1977
-Z 041d454a34960199d9b79c2713dca134
+Z 2134ba8d1976f430c91af4baa4a445ff
index 88744dfe1f600ea9a8706fee04dd610614397743..50029f624d4e8c5a05ad1c6a24d4bf5827c67d7c 100644 (file)
@@ -1 +1 @@
-d634f8b28abd7af4565c644bd7972b067caa0133
\ No newline at end of file
+8e79a0c24a03ccf960d6ccfb7c6b9b0f7c614e9b
\ No newline at end of file
index 35f319254e3bdca641a7d4a2079cb6bb31e7c1ea..9a7e5906268ad9f7b965d5c291b8f41d3d6e5cf8 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.197 2006/01/13 15:58:43 danielk1977 Exp $
+** $Id: where.c,v 1.198 2006/01/14 08:02:28 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -643,7 +643,7 @@ static void exprAnalyze(
   }
 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
 
-#ifndef SQLITE_OMIT_OR_OPTIMIZATION
+#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
   /* Attempt to convert OR-connected terms into an IN operator so that
   ** they can make use of indices.  Example:
   **
@@ -652,6 +652,9 @@ static void exprAnalyze(
   ** is converted into
   **
   **      x IN (expr1,expr2,expr3)
+  **
+  ** This optimization must be omitted if OMIT_SUBQUERY is defined because
+  ** the compiler for the the IN operator is part of sub-queries.
   */
   else if( pExpr->op==TK_OR ){
     int ok;
index 9725f2e0f13bf286eaa6b3fe726a3a375dbc7b8f..06853989047fc18e9ba5e9baa03fd2c83df8dfbd 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is testing the ALTER TABLE statement.
 #
-# $Id: alter.test,v 1.13 2006/01/13 18:06:40 danielk1977 Exp $
+# $Id: alter.test,v 1.14 2006/01/14 08:02:28 danielk1977 Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -560,9 +560,9 @@ do_test alter-5.2 {
   execsql "
     CREATE TABLE ${tbl_name}(a, b, c);
   "
+  set ::oid [execsql {SELECT max(oid) FROM sqlite_master}]
   execsql {
-    SELECT sql FROM sqlite_master 
-        WHERE oid = (SELECT max(oid) FROM sqlite_master);
+    SELECT sql FROM sqlite_master WHERE oid = $::oid;
   }
 } "{CREATE TABLE ${::tbl_name}(a, b, c)}"
 set ::tbl_name2 "abcXdef"
@@ -571,8 +571,7 @@ do_test alter-5.2 {
     ALTER TABLE $::tbl_name RENAME TO $::tbl_name2 
   "
   execsql {
-    SELECT sql FROM sqlite_master 
-        WHERE oid = (SELECT max(oid) FROM sqlite_master);
+    SELECT sql FROM sqlite_master WHERE oid = $::oid;
   }
 } "{CREATE TABLE '${::tbl_name2}'(a, b, c)}"
 do_test alter-5.3 {
@@ -580,8 +579,7 @@ do_test alter-5.3 {
     ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name
   "
   execsql {
-    SELECT sql FROM sqlite_master 
-        WHERE oid = (SELECT max(oid) FROM sqlite_master);
+    SELECT sql FROM sqlite_master WHERE oid = $::oid;
   }
 } "{CREATE TABLE '${::tbl_name}'(a, b, c)}"
 set ::col_name ghi\1234\jkl
@@ -590,8 +588,7 @@ do_test alter-5.4 {
     ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR
   "
   execsql {
-    SELECT sql FROM sqlite_master 
-        WHERE oid = (SELECT max(oid) FROM sqlite_master);
+    SELECT sql FROM sqlite_master WHERE oid = $::oid;
   }
 } "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR)}"
 set ::col_name2 B\3421\A
@@ -602,8 +599,7 @@ do_test alter-5.5 {
     ALTER TABLE $::tbl_name ADD COLUMN $::col_name2
   "
   execsql {
-    SELECT sql FROM sqlite_master 
-        WHERE oid = (SELECT max(oid) FROM sqlite_master);
+    SELECT sql FROM sqlite_master WHERE oid = $::oid;
   }
 } "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR, $::col_name2)}"
 do_test alter-5.6 {
index 5c9f8c154b914513447996cc8b4f67ab067948e3..1f728ca27b17726a94b88823963ef61cf063ab5f 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing CHECK constraints
 #
-# $Id: check.test,v 1.6 2005/11/14 22:29:06 drh Exp $
+# $Id: check.test,v 1.7 2006/01/14 08:02:28 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -151,14 +151,17 @@ do_test check-2.6 {
   }
 } {1 {constraint failed}}
 
-do_test check-3.1 {
-  catchsql {
-    CREATE TABLE t3(
-      x, y, z,
-      CHECK( x<(SELECT min(x) FROM t1) )
-    );
-  }
-} {1 {subqueries prohibited in CHECK constraints}}
+ifcapable subquery {
+  do_test check-3.1 {
+    catchsql {
+      CREATE TABLE t3(
+        x, y, z,
+        CHECK( x<(SELECT min(x) FROM t1) )
+      );
+    }
+  } {1 {subqueries prohibited in CHECK constraints}}
+}
+
 do_test check-3.2 {
   execsql {
     SELECT name FROM sqlite_master ORDER BY name
index 8977e1e8d2ffa044cba92269bc1c589555eb3a98..bf39f1ef0a7d2ce7e4624b73459aae11de0fc264 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is descending indices.
 #
-# $Id: descidx3.test,v 1.1 2006/01/02 18:24:40 drh Exp $
+# $Id: descidx3.test,v 1.2 2006/01/14 08:02:28 danielk1977 Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -122,23 +122,28 @@ do_test descidx3-3.5 {
   }
 } {9 7 6 8 3 4 2 5}
 
-do_test descidx3-4.1 {
-  execsql {
-    UPDATE t1 SET a=2 WHERE i<6;
-    SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
-  }
-} {8 6 2 4 3}
-do_test descidx3-4.2 {
-  execsql {
-    UPDATE t1 SET a=1;
-    SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
-  }
-} {2 4 3 8 6}
-do_test descidx3-4.3 {
-  execsql {
-    UPDATE t1 SET b=2;
-    SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
-  }
-} {9 7 6 8 3 4 2 5 1}
+ifcapable subquery {
+  # If the subquery capability is not compiled in to the binary, then
+  # the IN(...) operator is not available. Hence these tests cannot be 
+  # run.
+  do_test descidx3-4.1 {
+    execsql {
+      UPDATE t1 SET a=2 WHERE i<6;
+      SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
+    }
+  } {8 6 2 4 3}
+  do_test descidx3-4.2 {
+    execsql {
+      UPDATE t1 SET a=1;
+      SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
+    }
+  } {2 4 3 8 6}
+  do_test descidx3-4.3 {
+    execsql {
+      UPDATE t1 SET b=2;
+      SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
+    }
+  } {9 7 6 8 3 4 2 5 1}
+}
 
 finish_test
index 7cb0983503fb26e9d8eefdf2c3cc54730e9a2b75..3f9d42d69e669481010816345eaf35134cc7b34b 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc2.test,v 1.22 2005/04/29 02:10:00 drh Exp $
+# $Id: misc2.test,v 1.23 2006/01/14 08:02:28 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -257,14 +257,16 @@ ifcapable tempdb {
 #
 # The SQL code below was causing a segfault.
 #
-do_test misc2-10.1 {
-  execsql {
-    CREATE TABLE t1229(x);
-    CREATE TRIGGER r1229 BEFORE INSERT ON t1229 BEGIN
-      INSERT INTO t1229 SELECT y FROM (SELECT new.x y);
-    END;
-    INSERT INTO t1229 VALUES(1);
-  }
-} {}
+ifcapable subquery {
+  do_test misc2-10.1 {
+    execsql {
+      CREATE TABLE t1229(x);
+      CREATE TRIGGER r1229 BEFORE INSERT ON t1229 BEGIN
+        INSERT INTO t1229 SELECT y FROM (SELECT new.x y);
+      END;
+      INSERT INTO t1229 VALUES(1);
+    }
+  } {}
+}
 
 finish_test
index 8170496e6d683f7514195ee4aa77c8d55efe6a96..00321eb7fbc7aca66301d91eed07c791db551020 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc5.test,v 1.8 2006/01/05 14:22:34 danielk1977 Exp $
+# $Id: misc5.test,v 1.9 2006/01/14 08:02:28 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -439,38 +439,40 @@ do_test misc5-2.2 {
 # Ticket #1210.  Do proper reference counting of Table structures
 # so that deeply nested SELECT statements can be flattened correctly.
 #
-do_test misc5-3.1 {
-  execsql {
-    CREATE TABLE songs(songid, artist, timesplayed);
-    INSERT INTO songs VALUES(1,'one',1);
-    INSERT INTO songs VALUES(2,'one',2);
-    INSERT INTO songs VALUES(3,'two',3);
-    INSERT INTO songs VALUES(4,'three',5);
-    INSERT INTO songs VALUES(5,'one',7);
-    INSERT INTO songs VALUES(6,'two',11);
-    SELECT DISTINCT artist 
-    FROM (    
-     SELECT DISTINCT artist    
-     FROM songs      
-     WHERE songid IN (    
-      SELECT songid    
-      FROM songs    
-      WHERE LOWER(artist) = (    
-        SELECT DISTINCT LOWER(artist)    
-        FROM (      
-          SELECT DISTINCT artist,sum(timesplayed) AS total      
-          FROM songs      
-          GROUP BY LOWER(artist)      
-          ORDER BY total DESC      
-          LIMIT 10    
-        )    
-        WHERE artist <> '' 
+ifcapable subquery {
+  do_test misc5-3.1 {
+    execsql {
+      CREATE TABLE songs(songid, artist, timesplayed);
+      INSERT INTO songs VALUES(1,'one',1);
+      INSERT INTO songs VALUES(2,'one',2);
+      INSERT INTO songs VALUES(3,'two',3);
+      INSERT INTO songs VALUES(4,'three',5);
+      INSERT INTO songs VALUES(5,'one',7);
+      INSERT INTO songs VALUES(6,'two',11);
+      SELECT DISTINCT artist 
+      FROM (    
+       SELECT DISTINCT artist    
+       FROM songs      
+       WHERE songid IN (    
+        SELECT songid    
+        FROM songs    
+        WHERE LOWER(artist) = (    
+          SELECT DISTINCT LOWER(artist)    
+          FROM (      
+            SELECT DISTINCT artist,sum(timesplayed) AS total      
+            FROM songs      
+            GROUP BY LOWER(artist)      
+            ORDER BY total DESC      
+            LIMIT 10    
+          )    
+          WHERE artist <> '' 
+        )  
+       )       
       )  
-     )       
-    )  
-    ORDER BY LOWER(artist) ASC;
-  }
-} {two}
+      ORDER BY LOWER(artist) ASC;
+    }
+  } {two}
+}
 
 # Ticket #1370.  Do not overwrite small files (less than 1024 bytes)
 # when trying to open them as a database.
index 4998866b03946a4d9537ccfb91c5493e8e8b82c8..58270c58283c2ca56df020c24c30c8cdcf3fa680 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the SELECT statement.
 #
-# $Id: select1.test,v 1.46 2006/01/13 13:01:20 danielk1977 Exp $
+# $Id: select1.test,v 1.47 2006/01/14 08:02:28 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -803,27 +803,29 @@ ifcapable {compound && subquery} {
 
 # Check for a VDBE stack growth problem that existed at one point.
 #
-do_test select1-13.1 {
-  execsql {
-    BEGIN;
-    create TABLE abc(a, b, c, PRIMARY KEY(a, b));
-    INSERT INTO abc VALUES(1, 1, 1);
-  }
-  for {set i 0} {$i<10} {incr i} {
+ifcapable subquery {
+  do_test select1-13.1 {
     execsql {
-      INSERT INTO abc SELECT a+(select max(a) FROM abc), 
-          b+(select max(a) FROM abc), c+(select max(a) FROM abc) FROM abc;
+      BEGIN;
+      create TABLE abc(a, b, c, PRIMARY KEY(a, b));
+      INSERT INTO abc VALUES(1, 1, 1);
     }
-  }
-  execsql {COMMIT}
-
-  # This used to seg-fault when the problem existed.
-  execsql {
-    SELECT count(
-      (SELECT a FROM abc WHERE a = NULL AND b >= upper.c) 
-    ) FROM abc AS upper;
-  }
-} {0}
+    for {set i 0} {$i<10} {incr i} {
+      execsql {
+        INSERT INTO abc SELECT a+(select max(a) FROM abc), 
+            b+(select max(a) FROM abc), c+(select max(a) FROM abc) FROM abc;
+      }
+    }
+    execsql {COMMIT}
+  
+    # This used to seg-fault when the problem existed.
+    execsql {
+      SELECT count(
+        (SELECT a FROM abc WHERE a = NULL AND b >= upper.c) 
+      ) FROM abc AS upper;
+    }
+  } {0}
+}
 
 finish_test
 
index af23aa23e76bedd55e175556c3e9e1bee7146538..f88df3f18ac52bb201ff05160d4a1f6bba9438a0 100644 (file)
@@ -9,7 +9,7 @@
 #
 #***********************************************************************
 #
-# $Id: shared.test,v 1.11 2006/01/11 14:09:32 danielk1977 Exp $
+# $Id: shared.test,v 1.12 2006/01/14 08:02:29 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -191,8 +191,9 @@ do_test shared-3.1.1 {
   set ret [list]
   db2 eval {SELECT i FROM seq} {
     if {$i < 4} {
-      execsql {
-        INSERT INTO seq SELECT i + (SELECT max(i) FROM seq), x FROM seq;
+      set max [execsql {SELECT max(i) FROM seq}]
+      db eval {
+        INSERT INTO seq SELECT i + $max, x FROM seq;
       }
     }
     lappend ret $i
index 3814b4b9e9910c0b2e18bca06bc4c8c5fbc58342..62aad9c7e7574c85b3eb3856452de0e4998a8f41 100644 (file)
 # name be the time I noticed the error.  With CVS it is a really hassle
 # to change filenames, so I'll just leave it as is.  No harm done.
 #
-# $Id: tkt1443.test,v 1.2 2005/09/17 13:29:24 drh Exp $
+# $Id: tkt1443.test,v 1.3 2006/01/14 08:02:29 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
+ifcapable !subquery {
+  finish_test
+  return
+}
 
 # Construct the sample database.
 #
index b358818c0aee824f2c3378d162cdbd4a2e2c7c9d..5094b4fb055829fc9b979e5dac752d37ce80f411 100644 (file)
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
+# Somewhere in tkt1449-1.1 is a VIEW definition that uses a subquery.
+# So we cannot run this file if subqueries are not available.
+ifcapable !subquery {
+  finish_test
+  return
+}
+
 # The following schema generated problems in ticket #1449.  We've retained
 # the original schema here because it is some unbelievably complex, it seemed
 # like a good test case for SQLite.
index bc53de3a8ed3323ac16cc23ffb5b7b703eae8f82..1795931398fbcf38d971696cf180641f9d1a79a6 100644 (file)
@@ -67,6 +67,13 @@ do_test tkt1473-1.9 {
   }
 } {}
 
+# Everything from this point on depends on sub-queries. So skip it
+# if sub-queries are not available.
+ifcapable !subquery {
+  finish_test
+  return
+}
+
 do_test tkt1473-2.2 {
   execsql {
     SELECT (SELECT 1 FROM t1 WHERE a=1 UNION ALL SELECT 2 FROM t1 WHERE b=0)
index 94ac80460e48d65450d6e84bbfd2ca70cf238d2d..633f91fceef2eee16bc31cab4eff6a839124f807 100644 (file)
@@ -38,16 +38,18 @@ do_test tkt1537-1.3 {
     SELECT * FROM t2 LEFT JOIN t1 ON a1=b OR a2=b;
   }
 } {3 1 2 1 3 4 {} {} {} {}}
-do_test tkt1537-1.4 {
-  execsql {
-    SELECT * FROM t1 LEFT JOIN t2 ON b IN (a1,a2);
-  }
-} {1 {} {} {} {} 2 1 3 3 1}
-do_test tkt1537-1.5 {
-  execsql {
-    SELECT * FROM t2 LEFT JOIN t1 ON b IN (a2,a1);
-  }
-} {3 1 2 1 3 4 {} {} {} {}}
+ifcapable subquery {
+  do_test tkt1537-1.4 {
+    execsql {
+      SELECT * FROM t1 LEFT JOIN t2 ON b IN (a1,a2);
+    }
+  } {1 {} {} {} {} 2 1 3 3 1}
+  do_test tkt1537-1.5 {
+    execsql {
+      SELECT * FROM t2 LEFT JOIN t1 ON b IN (a2,a1);
+    }
+  } {3 1 2 1 3 4 {} {} {} {}}
+}
 do_test tkt1537-1.6 {
   execsql {
     CREATE INDEX t1a1 ON t1(a1);
@@ -61,16 +63,19 @@ do_test tkt1537-1.7 {
     SELECT * FROM t2 LEFT JOIN t1 ON a1=b OR a2=b;
   }
 } {3 1 2 1 3 4 {} {} {} {}}
-do_test tkt1537-1.8 {
-  execsql {
-    SELECT * FROM t1 LEFT JOIN t2 ON b IN (a1,a2);
-  }
-} {1 {} {} {} {} 2 1 3 3 1}
-do_test tkt1537-1.9 {
-  execsql {
-    SELECT * FROM t2 LEFT JOIN t1 ON b IN (a2,a1);
-  }
-} {3 1 2 1 3 4 {} {} {} {}}
+
+ifcapable subquery {
+  do_test tkt1537-1.8 {
+    execsql {
+      SELECT * FROM t1 LEFT JOIN t2 ON b IN (a1,a2);
+    }
+  } {1 {} {} {} {} 2 1 3 3 1}
+  do_test tkt1537-1.9 {
+    execsql {
+      SELECT * FROM t2 LEFT JOIN t1 ON b IN (a2,a1);
+    }
+  } {3 1 2 1 3 4 {} {} {} {}}
+}
 
 execsql {
   DROP INDEX t1a1;
index 22b74094918f59e4d964304268b938bd62725585..1b73aed1671d830ff7baf810dbb4c9b009ea530d 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing VIEW statements.
 #
-# $Id: view.test,v 1.27 2005/08/20 03:03:04 drh Exp $
+# $Id: view.test,v 1.28 2006/01/14 08:02:29 danielk1977 Exp $
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
@@ -428,11 +428,13 @@ do_test view-11.1 {
     SELECT * FROM t4 WHERE a = 'THIS';
   }
 } {This this THIS}
-do_test view-11.2 {
-  execsql {
-    SELECT * FROM (SELECT * FROM t4) WHERE a = 'THIS';
-  }
-} {This this THIS}
+ifcapable subquery {
+  do_test view-11.2 {
+    execsql {
+      SELECT * FROM (SELECT * FROM t4) WHERE a = 'THIS';
+    }
+  } {This this THIS}
+}
 do_test view-11.3 {
   execsql {
     CREATE VIEW v11 AS SELECT * FROM t4;
index af78f895195d546ad39d0b9fad771628e22605f9..86c4626a581bce919ee4b162bfe872c4a28a0868 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing the use of indices in WHERE clauses
 # based on recent changes to the optimizer.
 #
-# $Id: where2.test,v 1.5 2005/08/13 16:13:06 drh Exp $
+# $Id: where2.test,v 1.6 2006/01/14 08:02:29 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -124,69 +124,72 @@ do_test where2-3.2 {
 
 # The IN operator can be used by indices at multiple layers
 #
-do_test where2-4.1 {
-  queryplan {
-    SELECT * FROM t1 WHERE z IN (10207,10006) AND y IN (10000,10201)
-                     AND x>0 AND x<10
-    ORDER BY w
-  }
-} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
-do_test where2-4.2 {
-  queryplan {
-    SELECT * FROM t1 WHERE z IN (10207,10006) AND y=10000
-                     AND x>0 AND x<10
-    ORDER BY w
-  }
-} {99 6 10000 10006 sort t1 i1zyx}
-do_test where2-4.3 {
-  queryplan {
-    SELECT * FROM t1 WHERE z=10006 AND y IN (10000,10201)
-                     AND x>0 AND x<10
-    ORDER BY w
-  }
-} {99 6 10000 10006 sort t1 i1zyx}
-do_test where2-4.4 {
-  queryplan {
-    SELECT * FROM t1 WHERE z IN (SELECT 10207 UNION SELECT 10006)
-                     AND y IN (10000,10201)
-                     AND x>0 AND x<10
-    ORDER BY w
-  }
-} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
-do_test where2-4.5 {
-  queryplan {
-    SELECT * FROM t1 WHERE z IN (SELECT 10207 UNION SELECT 10006)
-                     AND y IN (SELECT 10000 UNION SELECT 10201)
-                     AND x>0 AND x<10
-    ORDER BY w
-  }
-} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
-do_test where2-4.6 {
-  queryplan {
-    SELECT * FROM t1
-     WHERE x IN (1,2,3,4,5,6,7,8)
-       AND y IN (10000,10001,10002,10003,10004,10005)
-     ORDER BY 2
-  }
-} {99 6 10000 10006 sort t1 i1xy}
+ifcapable subquery {
+  do_test where2-4.1 {
+    queryplan {
+      SELECT * FROM t1 WHERE z IN (10207,10006) AND y IN (10000,10201)
+                       AND x>0 AND x<10
+      ORDER BY w
+    }
+  } {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+  do_test where2-4.2 {
+    queryplan {
+      SELECT * FROM t1 WHERE z IN (10207,10006) AND y=10000
+                       AND x>0 AND x<10
+      ORDER BY w
+    }
+  } {99 6 10000 10006 sort t1 i1zyx}
+  do_test where2-4.3 {
+    queryplan {
+      SELECT * FROM t1 WHERE z=10006 AND y IN (10000,10201)
+                       AND x>0 AND x<10
+      ORDER BY w
+    }
+  } {99 6 10000 10006 sort t1 i1zyx}
+  do_test where2-4.4 {
+    queryplan {
+      SELECT * FROM t1 WHERE z IN (SELECT 10207 UNION SELECT 10006)
+                       AND y IN (10000,10201)
+                       AND x>0 AND x<10
+      ORDER BY w
+    }
+  } {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+  do_test where2-4.5 {
+    queryplan {
+      SELECT * FROM t1 WHERE z IN (SELECT 10207 UNION SELECT 10006)
+                       AND y IN (SELECT 10000 UNION SELECT 10201)
+                       AND x>0 AND x<10
+      ORDER BY w
+    }
+  } {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+  do_test where2-4.6 {
+    queryplan {
+      SELECT * FROM t1
+       WHERE x IN (1,2,3,4,5,6,7,8)
+         AND y IN (10000,10001,10002,10003,10004,10005)
+       ORDER BY 2
+    }
+  } {99 6 10000 10006 sort t1 i1xy}
 
-# Duplicate entires on the RHS of an IN operator do not cause duplicate
-# output rows.
-#
-do_test where2-4.6 {
-  queryplan {
-    SELECT * FROM t1 WHERE z IN (10207,10006,10006,10207)
-    ORDER BY w
-  }
-} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
-do_test where2-4.7 {
-  queryplan {
-    SELECT * FROM t1 WHERE z IN (
-       SELECT 10207 UNION ALL SELECT 10006
-       UNION ALL SELECT 10006 UNION ALL SELECT 10207)
-    ORDER BY w
-  }
-} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+  # Duplicate entires on the RHS of an IN operator do not cause duplicate
+  # output rows.
+  #
+  do_test where2-4.6 {
+    queryplan {
+      SELECT * FROM t1 WHERE z IN (10207,10006,10006,10207)
+      ORDER BY w
+    }
+  } {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+  do_test where2-4.7 {
+    queryplan {
+      SELECT * FROM t1 WHERE z IN (
+         SELECT 10207 UNION ALL SELECT 10006
+         UNION ALL SELECT 10006 UNION ALL SELECT 10207)
+      ORDER BY w
+    }
+  } {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+
+} ;# ifcapable subquery
 
 # The use of an IN operator disables the index as a sorter.
 #
@@ -195,24 +198,30 @@ do_test where2-5.1 {
     SELECT * FROM t1 WHERE w=99 ORDER BY w
   }
 } {99 6 10000 10006 nosort t1 i1w}
-do_test where2-5.2 {
-  queryplan {
-    SELECT * FROM t1 WHERE w IN (99) ORDER BY w
-  }
-} {99 6 10000 10006 sort t1 i1w}
+
+ifcapable subquery {
+  do_test where2-5.2 {
+    queryplan {
+      SELECT * FROM t1 WHERE w IN (99) ORDER BY w
+    }
+  } {99 6 10000 10006 sort t1 i1w}
+}
 
 # Verify that OR clauses get translated into IN operators.
 #
+set ::idx {}
+ifcapable subquery {set ::idx i1w}
 do_test where2-6.1 {
   queryplan {
     SELECT * FROM t1 WHERE w=99 OR w=100 ORDER BY +w
   }
-} {99 6 10000 10006 100 6 10201 10207 sort t1 i1w}
+} [list 99 6 10000 10006 100 6 10201 10207 sort t1 $::idx]
 do_test where2-6.2 {
   queryplan {
     SELECT * FROM t1 WHERE w=99 OR w=100 OR 6=w ORDER BY +w
   }
-} {6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 i1w}
+} [list 6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 $::idx]
+
 do_test where2-6.3 {
   queryplan {
     SELECT * FROM t1 WHERE w=99 OR w=100 OR 6=+w ORDER BY +w
@@ -223,20 +232,23 @@ do_test where2-6.4 {
     SELECT * FROM t1 WHERE w=99 OR +w=100 OR 6=w ORDER BY +w
   }
 } {6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 {}}
+
+set ::idx {}
+ifcapable subquery {set ::idx i1zyx}
 do_test where2-6.5 {
   queryplan {
     SELECT b.* FROM t1 a, t1 b
      WHERE a.w=1 AND (a.y=b.z OR b.z=10)
      ORDER BY +b.w
   }
-} {1 0 4 4 2 1 9 10 sort a i1w b i1zyx}
+} [list 1 0 4 4 2 1 9 10 sort a i1w b $::idx]
 do_test where2-6.6 {
   queryplan {
     SELECT b.* FROM t1 a, t1 b
      WHERE a.w=1 AND (b.z=10 OR a.y=b.z OR b.z=10)
      ORDER BY +b.w
   }
-} {1 0 4 4 2 1 9 10 sort a i1w b i1zyx}
+} [list 1 0 4 4 2 1 9 10 sort a i1w b $::idx]
 
 # Unique queries (queries that are guaranteed to return only a single
 # row of result) do not call the sorter.  But all tables must give
index 209276420134a4e9c4130ccc4db2d83d43f9384d..2e4675be87286679b20883b4e966e0eb6d435b2a 100644 (file)
@@ -155,7 +155,7 @@ static Keyword aKeywordTable[] = {
   { "ESCAPE",           "TK_ESCAPE",       ALWAYS                 },
   { "EXCEPT",           "TK_EXCEPT",       COMPOUND               },
   { "EXCLUSIVE",        "TK_EXCLUSIVE",    ALWAYS                 },
-  { "EXISTS",           "TK_EXISTS",       SUBQUERY               },
+  { "EXISTS",           "TK_EXISTS",       ALWAYS                 },
   { "EXPLAIN",          "TK_EXPLAIN",      EXPLAIN                },
   { "FAIL",             "TK_FAIL",         CONFLICT|TRIGGER       },
   { "FOR",              "TK_FOR",          TRIGGER                },