-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
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
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
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
-4a12f5b818b769d7518c942ff3dedf453dde698e
\ No newline at end of file
+3f0baa1b63df31f7dc885fd39290ca12ad2be6df
\ No newline at end of file
** 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"
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;
}
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);
# 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 */
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
}
} {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
}
} {4096}
- do_test count-1.$iTest.4 {
+ do_test count-1.$iTest.5 {
execsql {
BEGIN;
INSERT INTO t1 SELECT * FROM t1; -- 8192
} {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