]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fixes and some extra test cases for count(*) optimization. (CVS 6320)
authordanielk1977 <danielk1977@noemail.net>
Tue, 24 Feb 2009 18:33:15 +0000 (18:33 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 24 Feb 2009 18:33:15 +0000 (18:33 +0000)
FossilOrigin-Name: 3f0baa1b63df31f7dc885fd39290ca12ad2be6df

manifest
manifest.uuid
src/select.c
test/count.test

index cbc7d9d58b92fb99b017b48ba9865cfef308b971..3f152f663fa312c8d7f4ff820332047c243b3f9b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhanced\scomments\son\stable\slocking\slogic\sas\sit\srelates\sto\spreparing\snew\nstatements.\s\sAdded\sassert()\sand\stestcase()\sbut\sno\sother\schanges\sto\scode.\s(CVS\s6319)
-D 2009-02-24T16:18:05
+C Fixes\sand\ssome\sextra\stest\scases\sfor\scount(*)\soptimization.\s(CVS\s6320)
+D 2009-02-24T18:33:15
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in d64baddbf55cdf33ff030e14da837324711a4ef7
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -154,7 +154,7 @@ F src/printf.c 9866a9a9c4a90f6d4147407f373df3fd5d5f9b6f
 F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
 F src/resolve.c dea005135845acbbfae1f2968c0deb6b2e3d580c
 F src/rowset.c ba9375f37053d422dd76965a9c370a13b6e1aac4
-F src/select.c 474557a5e4388c347f055c6759da1a7a4fc01e32
+F src/select.c 757eb43f9344f8f68e5b9e41830547407ff0d9a9
 F src/shell.c f109ebbb50132926ebbc173a6c2d8838d5d78527
 F src/sqlite.h.in 14f4d065bafed8500ea558a75a8e2be89c784d61
 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
@@ -286,7 +286,7 @@ F test/corrupt9.test 794d284109c65c8f10a2b275479045e02d163bae
 F test/corruptA.test 99e95620b980161cb3e79f06a884a4bb8ae265ff
 F test/corruptB.test 505331779fe7a96fe38ecbb817f19c63bc27d171
 F test/corruptC.test c798aa395a8d052fba88bd1be8e1945309e3f94a
-F test/count.test 51c69ee6b3394dfba27dbc1e30f25fb41d66200d
+F test/count.test 27293d5708d199493cd5af8d1f4aa13bff3615cf
 F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89
 F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651
 F test/crash3.test 776f9363554c029fcce71d9e6600fa0ba6359ce7
@@ -702,7 +702,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P a195d74ff9ce836447dba4da7edcc6f1cdae5574
-R 7311b1fa9b7b5c3d12ba433576f5510b
-U drh
-Z 99368cf9c56a6d99659a698dff53e252
+P 4a12f5b818b769d7518c942ff3dedf453dde698e
+R d37add306fd93c06febcf46f01525da8
+U danielk1977
+Z 6c6a246b0d032d8c6796d74983b15024
index e181bcc7c07b6f4814810c5b5d2198b1f7361253..642473b62ea41b9d5c5d990dacdd1824ed25085b 100644 (file)
@@ -1 +1 @@
-4a12f5b818b769d7518c942ff3dedf453dde698e
\ No newline at end of file
+3f0baa1b63df31f7dc885fd39290ca12ad2be6df
\ No newline at end of file
index 2fe1929a4592984e0456d5691815028fc0f6341d..f64aec0966404cf8538e231dfb1443b967e90419 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.502 2009/02/24 10:01:52 danielk1977 Exp $
+** $Id: select.c,v 1.503 2009/02/24 18:33:15 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -2970,7 +2970,7 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
 
   assert( !p->pGroupBy );
 
-  if( p->pWhere || p->pHaving || p->pEList->nExpr!=1
+  if( p->pWhere || p->pEList->nExpr!=1 
    || p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect
   ){
     return 0;
@@ -4144,12 +4144,12 @@ int sqlite3Select(
         }
         sqlite3WhereEnd(pWInfo);
         finalizeAggFunctions(pParse, &sAggInfo);
-        pOrderBy = 0;
-        if( pHaving ){
-          sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
-        }
       }
 
+      pOrderBy = 0;
+      if( pHaving ){
+        sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
+      }
       selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, -1, 
                       pDest, addrEnd, addrEnd);
       sqlite3ExprListDelete(db, pDel);
index cf947f23e78b7d080edf0968180b5f1931438bc1..7e309a79d6715e8664ac96a6381117107de5d0cb 100644 (file)
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing "SELECT count(*)" statements.
 #
-# $Id: count.test,v 1.1 2009/02/24 10:48:28 danielk1977 Exp $
+# $Id: count.test,v 1.2 2009/02/24 18:33:15 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
+# Test plan:
+#
+#  count-1.*: Test that the OP_Count instruction appears to work on both
+#             tables and indexes. Test both when they contain 0 entries,
+#             when all entries are on the root page, and when the b-tree
+#             forms a structure 2 and 3 levels deep.
+#            
+#  count-2.*: Test that 
+#
+#
+
 set iTest 0
 foreach zIndex [list {
   /* no-op */
@@ -29,14 +40,18 @@ foreach zIndex [list {
       CREATE TABLE t1(a, b);
     }
     execsql $zIndex
+    execsql { SELECT count(*) FROM t1 }
+  } {0}
+  
+  do_test count-1.$iTest.2 {
     execsql {
       INSERT INTO t1 VALUES(1, 2);
       INSERT INTO t1 VALUES(3, 4);
       SELECT count(*) FROM t1;
     }
   } {2}
-  
-  do_test count-1.$iTest.2 {
+
+  do_test count-1.$iTest.3 {
     execsql {
       INSERT INTO t1 SELECT * FROM t1;          --   4
       INSERT INTO t1 SELECT * FROM t1;          --   8
@@ -49,7 +64,7 @@ foreach zIndex [list {
     }
   } {256}
   
-  do_test count-1.$iTest.3 {
+  do_test count-1.$iTest.4 {
     execsql {
       INSERT INTO t1 SELECT * FROM t1;          --  512
       INSERT INTO t1 SELECT * FROM t1;          -- 1024
@@ -59,7 +74,7 @@ foreach zIndex [list {
     }
   } {4096}
   
-  do_test count-1.$iTest.4 {
+  do_test count-1.$iTest.5 {
     execsql {
       BEGIN;
       INSERT INTO t1 SELECT * FROM t1;          --  8192
@@ -72,5 +87,68 @@ foreach zIndex [list {
   } {65536}
 }
 
+proc uses_op_count {sql} {
+  if {[lsearch [execsql "EXPLAIN $sql"] Count]>=0} {
+    return 1;
+  }
+  return 0
+}
+
+do_test count-2.1 {
+  execsql {
+    CREATE TABLE t2(a, b);
+  }
+  uses_op_count {SELECT count(*) FROM t2}
+} {1}
+do_test count-2.2 {
+  catchsql {SELECT count(DISTINCT *) FROM t2}
+} {1 {near "*": syntax error}}
+do_test count-2.3 {
+  uses_op_count {SELECT count(DISTINCT a) FROM t2}
+} {0}
+do_test count-2.4 {
+  uses_op_count {SELECT count(a) FROM t2}
+} {0}
+do_test count-2.5 {
+  uses_op_count {SELECT count() FROM t2}
+} {1}
+do_test count-2.6 {
+  catchsql {SELECT count(DISTINCT) FROM t2}
+} {1 {DISTINCT aggregates must have exactly one argument}}
+do_test count-2.7 {
+  uses_op_count {SELECT count(*)+1 FROM t2}
+} {0}
+do_test count-2.8 {
+  uses_op_count {SELECT count(*) FROM t2 WHERE a IS NOT NULL}
+} {0}
+do_test count-2.9 {
+  catchsql {SELECT count(*) FROM t2 HAVING count(*)>1}
+} {1 {a GROUP BY clause is required before HAVING}}
+do_test count-2.10 {
+  uses_op_count {SELECT count(*) FROM (SELECT 1)}
+} {0}
+do_test count-2.11 {
+  execsql { CREATE VIEW v1 AS SELECT 1 AS a }
+  uses_op_count {SELECT count(*) FROM v1}
+} {0}
+do_test count-2.12 {
+  uses_op_count {SELECT count(*), max(a) FROM t2}
+} {0}
+do_test count-2.13 {
+  uses_op_count {SELECT count(*) FROM t1, t2}
+} {0}
+
+do_test count-3.1 {
+  execsql {
+    CREATE TABLE t3(a, b);
+    SELECT a FROM (SELECT count(*) AS a FROM t3) WHERE a==0;
+  }
+} {0}
+do_test count-3.2 {
+  execsql {
+    SELECT a FROM (SELECT count(*) AS a FROM t3) WHERE a==1;
+  }
+} {}
+
 finish_test