Minor changes and coverge tests for "SELECT count(*)" optimization. (CVS 6324)

FossilOrigin-Name: a3695b98f63fb776c3b7f77f0553e8a38bcc6f78
This commit is contained in:
danielk1977 2009-02-25 08:56:47 +00:00
parent 11b57d6929
commit 02f33725d2
5 changed files with 73 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Additional\scommands\sand\sanother\sprocedure\sname\schanges\sfor\sclarity\sof\npresentation.\sNo\slogic\schanges.\s(CVS\s6323)
D 2009-02-24T19:21:41
C Minor\schanges\sand\scoverge\stests\sfor\s"SELECT\scount(*)"\soptimization.\s(CVS\s6324)
D 2009-02-25T08:56:47
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 757eb43f9344f8f68e5b9e41830547407ff0d9a9
F src/select.c 4d0b77fd76ff80f09a798ee98953e344c9de8fbb
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 27293d5708d199493cd5af8d1f4aa13bff3615cf
F test/count.test 89df9e4cf33caa060be12607462caaf47df6c435
F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89
F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651
F test/crash3.test 776f9363554c029fcce71d9e6600fa0ba6359ce7
@ -437,7 +437,7 @@ F test/lock6.test 862aa71e97b288d6b3f92ba3313f51bd0b003776
F test/lookaside.test e69f822f13745f1d5c445c6e30e30f059f30c8e5
F test/main.test 187a9a1b5248ed74a83838c581c15ec6023b555b
F test/make-where7.tcl 40bb740b37eead343eaf57b74ab72d2a5a304745
F test/malloc.test 8e3ad667ef1c55147dcf9190b5edd3bf808ab147
F test/malloc.test 8180b651cc7e6b6be933c335db590ff1c33d8884
F test/malloc3.test 4bc57f850b212f706f3e1b37c4eced1d5a727cd1
F test/malloc4.test 957337613002b7058a85116493a262f679f3a261
F test/malloc5.test 20d1a0884b03edf811bfd7005faade028367e7c8
@ -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 b99c1815fe270decf1ac3d714acc7e945d1e728a
R 52f851adc25a6b49b81feac1c5feb754
U drh
Z 7a0daf7b4a8f562b34bdae9981a338a7
P 91d9d51e03657e7492dd7b93e66c82b152abec3b
R c65d7c9d041d481539ec6e65a8bbfcc4
U danielk1977
Z f03589b6049282aa23f55a52edc62f1d

View File

@ -1 +1 @@
91d9d51e03657e7492dd7b93e66c82b152abec3b
a3695b98f63fb776c3b7f77f0553e8a38bcc6f78

View 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.503 2009/02/24 18:33:15 danielk1977 Exp $
** $Id: select.c,v 1.504 2009/02/25 08:56:47 danielk1977 Exp $
*/
#include "sqliteInt.h"
@ -2975,10 +2975,11 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
){
return 0;
}
pTab = p->pSrc->a[0].pTab;
pExpr = p->pEList->a[0].pExpr;
if( !pTab || pTab->pSelect || IsVirtual(pTab) ) return 0;
assert( pTab && !pTab->pSelect && pExpr );
if( IsVirtual(pTab) ) return 0;
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
if( pExpr->flags&EP_Distinct ) return 0;

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing "SELECT count(*)" statements.
#
# $Id: count.test,v 1.2 2009/02/24 18:33:15 danielk1977 Exp $
# $Id: count.test,v 1.3 2009/02/25 08:56:47 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -138,6 +138,14 @@ do_test count-2.13 {
uses_op_count {SELECT count(*) FROM t1, t2}
} {0}
ifcapable vtab {
register_echo_module [sqlite3_connection_pointer db]
do_test count-2.14 {
execsql { CREATE VIRTUAL TABLE techo USING echo(t1); }
uses_op_count {SELECT count(*) FROM techo}
} {0}
}
do_test count-3.1 {
execsql {
CREATE TABLE t3(a, b);
@ -150,5 +158,28 @@ do_test count-3.2 {
}
} {}
do_test count-4.1 {
execsql {
CREATE TABLE t4(a, b);
INSERT INTO t4 VALUES('a', 'b');
CREATE INDEX t4i1 ON t4(b, a);
SELECT count(*) FROM t4;
}
} {1}
do_test count-4.2 {
execsql {
CREATE INDEX t4i2 ON t4(b);
SELECT count(*) FROM t4;
}
} {1}
do_test count-4.3 {
execsql {
DROP INDEX t4i1;
CREATE INDEX t4i1 ON t4(b, a);
SELECT count(*) FROM t4;
}
} {1}
finish_test

View File

@ -16,7 +16,7 @@
# to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.75 2009/02/04 08:17:57 danielk1977 Exp $
# $Id: malloc.test,v 1.76 2009/02/25 08:56:47 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -791,6 +791,32 @@ do_malloc_test 32 -tclprep {
db2 close
}
# The following two OOM tests verify that OOM handling works in the
# code used to optimize "SELECT count(*) FROM <tbl>".
#
do_malloc_test 33 -tclprep {
db eval { PRAGMA cache_size = 10 }
db transaction {
db eval { CREATE TABLE abc(a, b) }
for {set i 0} {$i<500} {incr i} {
db eval {INSERT INTO abc VALUES(randstr(100,100), randstr(1000,1000))}
}
}
} -sqlbody {
SELECT count(*) FROM abc;
}
do_malloc_test 34 -tclprep {
db eval { PRAGMA cache_size = 10 }
db transaction {
db eval { CREATE TABLE abc(a PRIMARY KEY, b) }
for {set i 0} {$i<500} {incr i} {
db eval {INSERT INTO abc VALUES(randstr(100,100), randstr(1000,1000))}
}
}
} -sqlbody {
SELECT count(*) FROM abc;
}
# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
catch {db close}