From 4044906210bcb65f1ed643aee3238674e98d7a90 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 20 Aug 2013 16:08:39 +0000 Subject: [PATCH 01/17] Test script changes to support testing sqlite3_interrupt(). FossilOrigin-Name: 0cede9f898bcd13dab51b25cb0e72213d988d3d2 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- test/malloc_common.tcl | 28 +++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 9ad5c805c7..b35e7347db 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\soptimizations\sin\sthe\sVDBE\sand\sespecially\sto\sthe\sOP_Next\sand\nrelated\sopcodes\sand\sin\sthe\ssqlite3BtreeNext()\sand\ssqlite3BtreePrevious()\nroutines.\s\sThis\sis\sa\scherrypick\sof\s[6f99b54aedeb],\s[d2efea1682a7],\sand\n[d78c5d89de4b]. -D 2013-08-20T03:13:51.513 +C Test\sscript\schanges\sto\ssupport\stesting\ssqlite3_interrupt(). +D 2013-08-20T16:08:39.938 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -661,7 +661,7 @@ F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb F test/mallocI.test a88c2b9627c8506bf4703d8397420043a786cdb6 F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e F test/mallocK.test d79968641d1b70d88f6c01bdb9a7eb4a55582cc9 -F test/malloc_common.tcl 9a98856549bfb3fab205edbc1317216edc52e70d +F test/malloc_common.tcl 05b53b004b4ee09f3bb1d34166a8b8ce0ad2dd09 F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test db5260330676de007be8530d6ecc7c9ab2b06ad3 @@ -1105,10 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P dc65ad8c4c67b21e3b042b8df6580d02b634a90b -Q +6f99b54aedeb91e46d52f65504d02a9cc61c0062 -Q +d2efea1682a7e708000c1f5d36370aaf1199b3be -Q +d78c5d89de4b840351b026c9db1952fc24e689d0 -R 539c71750e964e780f11bfb1b59ee716 -U drh -Z feae42d544c0a4532e8cd3cb8461eca6 +P 7f72fc4f47445a2c01910b268335873de9f75059 +R d7254aa102bedab4ec8ef3b2a2896635 +U dan +Z e9a2c8620ce0b09ce68b2f2f4880d098 diff --git a/manifest.uuid b/manifest.uuid index 42e6161093..5b39852d5d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7f72fc4f47445a2c01910b268335873de9f75059 \ No newline at end of file +0cede9f898bcd13dab51b25cb0e72213d988d3d2 \ No newline at end of file diff --git a/test/malloc_common.tcl b/test/malloc_common.tcl index 2ac619b1df..daf04a4fa0 100644 --- a/test/malloc_common.tcl +++ b/test/malloc_common.tcl @@ -93,6 +93,16 @@ set FAULTSIM(cantopen-persistent) [list \ -injectuninstall cantopen_injectuninstall \ ] +set ::default_faults_arg [array names FAULTSIM] + +set FAULTSIM(interrupt) [list \ + -injectinstall interrupt_injectinstall \ + -injectstart interrupt_injectstart \ + -injectstop interrupt_injectstop \ + -injecterrlist {{1 interrupted} {1 interrupt}} \ + -injectuninstall interrupt_injectuninstall \ +] + #-------------------------------------------------------------------------- @@ -113,7 +123,7 @@ set FAULTSIM(cantopen-persistent) [list \ proc do_faultsim_test {name args} { global FAULTSIM - set DEFAULT(-faults) [array names FAULTSIM] + set DEFAULT(-faults) $::default_faults_arg set DEFAULT(-prep) "" set DEFAULT(-body) "" set DEFAULT(-test) "" @@ -255,6 +265,22 @@ proc cantopen_injectstop {} { shmfault cantopen } +# The following procs are used as [do_one_faultsim_test] callbacks +# when injecting SQLITE_INTERRUPT error faults into test cases. +# +proc interrupt_injectinstall {} { +} +proc interrupt_injectuninstall {} { +} +proc interrupt_injectstart {iFail} { + set ::sqlite_interrupt_count $iFail +} +proc interrupt_injectstop {} { + set res [expr $::sqlite_interrupt_count<=0] + set ::sqlite_interrupt_count 0 + set res +} + # This command is not called directly. It is used by the # [faultsim_test_result] command created by [do_faultsim_test] and used # by -test scripts. From d0aa2f3afd6865d7d9f228be99e43daf63b99f89 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Aug 2013 17:00:55 +0000 Subject: [PATCH 02/17] Ignore IS NOT NULL and NOT NULL constraints on NOT NULL columns. FossilOrigin-Name: e476408e3c5ba5f3ba5e98ff264167c163d72e3f --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/where.c | 6 ++---- test/where3.test | 6 ++++++ test/whereA.test | 6 ++++++ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index b35e7347db..f7304e3316 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\sscript\schanges\sto\ssupport\stesting\ssqlite3_interrupt(). -D 2013-08-20T16:08:39.938 +C Ignore\sIS\sNOT\sNULL\sand\sNOT\sNULL\sconstraints\son\sNOT\sNULL\scolumns. +D 2013-08-20T17:00:55.048 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 2e8b489db47e20ae36cd247932dc671c9ded0624 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 03a50ecb2f4f02b5492d669a84875947b56b8906 +F src/where.c 1a020a02c9062af8de011427461d1fb515dbba97 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1040,7 +1040,7 @@ F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e F test/where.test da54153a4c1571ea1b95659e5bec8119edf786aa F test/where2.test b1830f762f837153a4c9743adaab90a5761f73e7 -F test/where3.test a0682ba3dc8c8f46ffcc95a3d9f58c4327fc129f +F test/where3.test d28c51f257e60be30f74308fa385ceeddfb54a6e F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 F test/where6.test 5da5a98cec820d488e82708301b96cb8c18a258b @@ -1048,7 +1048,7 @@ F test/where7.test 5a4b0abc207d71da4deecd734ad8579e8dd40aa8 F test/where8.test 6f95896633cf2d307b5263145b942b7d33e837c6 F test/where8m.test da346596e19d54f0aba35ebade032a7c47d79739 F test/where9.test 9a7fda4a4512abc26a855e8b2b6572b200f6019b -F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a +F test/whereA.test 4d253178d135ec46d1671e440cd8f2b916aa6e6b F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test d6f4ecd4fa2d9429681a5b22a25d2bda8e86ab8a F test/whereD.test 6c2feb79ef1f68381b07f39017fe5f9b96da8d62 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 7f72fc4f47445a2c01910b268335873de9f75059 -R d7254aa102bedab4ec8ef3b2a2896635 -U dan -Z e9a2c8620ce0b09ce68b2f2f4880d098 +P 0cede9f898bcd13dab51b25cb0e72213d988d3d2 +R 725f0aaaf1dfad075e5c9084063c2a98 +U drh +Z e9e50abe87d60d38c6172ae130ead1c3 diff --git a/manifest.uuid b/manifest.uuid index 5b39852d5d..74afdfb909 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cede9f898bcd13dab51b25cb0e72213d988d3d2 \ No newline at end of file +e476408e3c5ba5f3ba5e98ff264167c163d72e3f \ No newline at end of file diff --git a/src/where.c b/src/where.c index 9de283c4cc..8f6494af68 100644 --- a/src/where.c +++ b/src/where.c @@ -4336,13 +4336,11 @@ static int whereLoopAddBtreeIndex( for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ int nIn = 0; if( pTerm->prereqRight & pNew->maskSelf ) continue; -#ifdef SQLITE_ENABLE_STAT3 - if( (pTerm->wtFlags & TERM_VNULL)!=0 + if( (pTerm->eOperator==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0) && (iCol<0 || pSrc->pTab->aCol[iCol].notNull) ){ - continue; /* skip IS NOT NULL constraints on a NOT NULL column */ + continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */ } -#endif pNew->wsFlags = saved_wsFlags; pNew->u.btree.nEq = saved_nEq; pNew->nLTerm = saved_nLTerm; diff --git a/test/where3.test b/test/where3.test index 72ae98b6c6..8fa9fa7840 100644 --- a/test/where3.test +++ b/test/where3.test @@ -246,6 +246,12 @@ do_execsql_test where3-3.1 { 0 0 1 {SCAN TABLE t302} 0 1 0 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?)} } +do_execsql_test where3-3.2 { + SELECT * FROM t301 WHERE c=3 AND a IS NULL; +} {} +do_execsql_test where3-3.3 { + SELECT * FROM t301 WHERE c=3 AND a IS NOT NULL; +} {1 2 3} if 0 { # Query planner no longer does this # Verify that when there are multiple tables in a join which must be diff --git a/test/whereA.test b/test/whereA.test index 5d0aca591c..78826b111c 100644 --- a/test/whereA.test +++ b/test/whereA.test @@ -68,6 +68,12 @@ do_test whereA-1.7 { SELECT * FROM t1; } } {3 4.53 {} 2 hello world 1 2 3} +do_execsql_test whereA-1.8 { + SELECT * FROM t1 WHERE b=2 AND a IS NULL; +} {} +do_execsql_test whereA-1.9 { + SELECT * FROM t1 WHERE b=2 AND a IS NOT NULL; +} {1 2 3} do_test whereA-2.1 { db eval { From e934e633a5894cc75e9d8628d3626cfe1f272580 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 20 Aug 2013 17:14:57 +0000 Subject: [PATCH 03/17] Fix an invalid assert() in where.c. Also a crash that can occur in the EXPLAIN QUERY PLAN code under obscure circumstances. FossilOrigin-Name: ef192abb82c2fc31135f875d7a19908d67c076b0 --- manifest | 16 +++++++-------- manifest.uuid | 2 +- src/where.c | 5 +++-- test/indexedby.test | 47 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index f7304e3316..58ac190c98 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ignore\sIS\sNOT\sNULL\sand\sNOT\sNULL\sconstraints\son\sNOT\sNULL\scolumns. -D 2013-08-20T17:00:55.048 +C Fix\san\sinvalid\sassert()\sin\swhere.c.\sAlso\sa\scrash\sthat\scan\soccur\sin\sthe\sEXPLAIN\sQUERY\sPLAN\scode\sunder\sobscure\scircumstances. +D 2013-08-20T17:14:57.137 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 2e8b489db47e20ae36cd247932dc671c9ded0624 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 1a020a02c9062af8de011427461d1fb515dbba97 +F src/where.c 0ced8882cadbf1817904331a5d942b30ebe0e789 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -591,7 +591,7 @@ F test/index3.test 423a25c789fc8cc51aaf2a4370bbdde2d9e9eed7 F test/index4.test 2983216eb8c86ee62d9ed7cb206b5cc3331c0026 F test/index5.test fc07c14193c0430814e7a08b5da46888ee795c33 F test/index6.test f53a788b813eb6937346867bae9e587c434dd9a1 -F test/indexedby.test 0e959308707c808515c3a51363f7a9835027108c +F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 F test/insert.test 489aa12a027c83d291f5034a83c8c32e6be1dca2 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 0cede9f898bcd13dab51b25cb0e72213d988d3d2 -R 725f0aaaf1dfad075e5c9084063c2a98 -U drh -Z e9e50abe87d60d38c6172ae130ead1c3 +P e476408e3c5ba5f3ba5e98ff264167c163d72e3f +R 44efbb8237f8929e6aff522c9e736888 +U dan +Z 8bb1f7038ca62fa90bbb1e1bf6c35d10 diff --git a/manifest.uuid b/manifest.uuid index 74afdfb909..0e3f98b8b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e476408e3c5ba5f3ba5e98ff264167c163d72e3f \ No newline at end of file +ef192abb82c2fc31135f875d7a19908d67c076b0 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 8f6494af68..23a35fa790 100644 --- a/src/where.c +++ b/src/where.c @@ -3029,7 +3029,7 @@ static int codeAllEqualityTerms( /* Evaluate the equality constraints */ - assert( pIdx->nColumn>=nEq ); + assert( zAff==0 || strlen(zAff)>=nEq ); for(j=0; jaLTerm[j]; @@ -3121,7 +3121,8 @@ static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){ txt.db = db; sqlite3StrAccumAppend(&txt, " (", 2); for(i=0; i Date: Wed, 21 Aug 2013 12:04:32 +0000 Subject: [PATCH 06/17] Candidate fix for [d666d600a6]. FossilOrigin-Name: 781592f32c8e1dcd59954c17211cf61349d1c0b1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 4 ++-- test/collate2.test | 31 +++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 4535299e32..e5f921a3d2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sminor\sproblem\sin\sprogress.test.\sNo\scode\schanges. -D 2013-08-21T07:25:03.850 +C Candidate\sfix\sfor\s[d666d600a6]. +D 2013-08-21T12:04:32.485 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -172,7 +172,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 4262c227bc91cecc61ae37ed3a40f08069cfa267 F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/delete.c 2317c814866d9aa71fea16b3faf4fdd4d6a49b94 -F src/expr.c 42d8235af422661ab80be097bebca485b33e2e14 +F src/expr.c 6bab61c757c4c4c94a92e98d507025d5d18afd3c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 914a6bbd987d857c41ac9d244efa6641f36faadb F src/func.c 5c50c1ea31fd864b0fe921fe1a8d4c55acd609ef @@ -367,7 +367,7 @@ F test/close.test 340bd24cc58b16c6bc01967402755027c37eb815 F test/closure01.test dbb28f1ea9eeaf0a53ec5bc0fed352e479def8c7 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 F test/collate1.test b709989e6e6ff6e1d2bd64231c2c1d8146846c9e -F test/collate2.test 285cef1b58ce2b3cf074a386f763ce753c81c97f +F test/collate2.test 96c4cded721b7df7fead3669bd5e5e56a1c1e72d F test/collate3.test 79558a286362cb9ed603c6fa543f1cda7f563f0f F test/collate4.test 031f7265c13308b724ba3c49f41cc04612bd92b1 F test/collate5.test 65d928034d30d2d263a80f6359f7549ee1598ec6 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 356c6c59311eaf7d5633476f635e94a12b8b3924 -R 3810158b358b1ad8cbaf587b4d9b2a39 +P a95ae93b32a9ad2ae017124ed0881802c3c741c0 +R 35cc26635e6bc873eb202f0021417291 U dan -Z f1931decb20295530674ca6fa0949acd +Z 642302ea64d9f9943d5c6662ae753a34 diff --git a/manifest.uuid b/manifest.uuid index ef7d2261d6..f9cfd5c1c7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a95ae93b32a9ad2ae017124ed0881802c3c741c0 \ No newline at end of file +781592f32c8e1dcd59954c17211cf61349d1c0b1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index e857193b8b..dd4f5de15f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -114,8 +114,7 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ p = p->pLeft; continue; } - assert( op!=TK_REGISTER || p->op2!=TK_COLLATE ); - if( op==TK_COLLATE ){ + if( op==TK_COLLATE || (op==TK_REGISTER && p->op2==TK_COLLATE) ){ pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); break; } @@ -3505,6 +3504,7 @@ static void exprCodeBetween( compRight.pLeft = &exprX; compRight.pRight = pExpr->x.pList->a[1].pExpr; exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, ®Free1); + exprX.op2 = exprX.op; exprX.op = TK_REGISTER; if( jumpIfTrue ){ sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull); diff --git a/test/collate2.test b/test/collate2.test index c758b0a6db..a23728b15f 100644 --- a/test/collate2.test +++ b/test/collate2.test @@ -17,6 +17,8 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set ::testprefix collate2 + # # Tests are organised as follows: # @@ -693,4 +695,33 @@ do_test collate2-5.5 { } } {aa aa} +do_execsql_test 6.1 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('b'); + INSERT INTO t1 VALUES('B'); +} +do_execsql_test 6.2 { + SELECT * FROM t1 WHERE x COLLATE nocase BETWEEN 'a' AND 'c'; +} {b B} +do_execsql_test 6.3 { + SELECT * FROM t1 WHERE x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.4 { + SELECT * FROM t1 + WHERE x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.5 { + SELECT * FROM t1 WHERE +x COLLATE nocase BETWEEN 'a' AND 'c'; +} {b B} +do_execsql_test 6.6 { + SELECT * FROM t1 WHERE +x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.7 { + SELECT * FROM t1 + WHERE +x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} + +finish_test + + finish_test From 2505a5fee2651d184fa56523692d0f0b34fe5c07 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Aug 2013 15:45:27 +0000 Subject: [PATCH 07/17] Fix an FTS4 problem introduced by [361084e1eb]. FossilOrigin-Name: 5f35c8cb8f8b67121c70f98c02c4aa7c25327690 --- ext/fts3/fts3_write.c | 8 ++++---- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 0624cd6e97..cb1d1cb266 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -5135,11 +5135,11 @@ int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *pCsr){ if( pTC ) pModule->xClose(pTC); if( rc==SQLITE_DONE ) rc = SQLITE_OK; } + } - for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){ - if( pDef->pList ){ - rc = fts3PendingListAppendVarint(&pDef->pList, 0); - } + for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){ + if( pDef->pList ){ + rc = fts3PendingListAppendVarint(&pDef->pList, 0); } } } diff --git a/manifest b/manifest index e5f921a3d2..9433316ef3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Candidate\sfix\sfor\s[d666d600a6]. -D 2013-08-21T12:04:32.485 +C Fix\san\sFTS4\sproblem\sintroduced\sby\s[361084e1eb]. +D 2013-08-21T15:45:27.749 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -96,7 +96,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c 92391b4b4fb043564c6539ea9b8661e3bcba47b9 F ext/fts3/fts3_unicode2.c 0113d3acf13429e6dc38e0647d1bc71211c31a4d -F ext/fts3/fts3_write.c edf39aea5d45080195f6b38aa5efee3804716dd0 +F ext/fts3/fts3_write.c ce45c3ea578464f26b0293ea8e54a39694f18b64 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/fts3/tool/fts3view.c 6cfc5b67a5f0e09c0d698f9fd012c784bfaa9197 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P a95ae93b32a9ad2ae017124ed0881802c3c741c0 -R 35cc26635e6bc873eb202f0021417291 +P 781592f32c8e1dcd59954c17211cf61349d1c0b1 +R 954710c672abb501b54f9208dbeb6f94 U dan -Z 642302ea64d9f9943d5c6662ae753a34 +Z 36f3acb088bc10968624ff14f224d8d6 diff --git a/manifest.uuid b/manifest.uuid index f9cfd5c1c7..a78176e3f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -781592f32c8e1dcd59954c17211cf61349d1c0b1 \ No newline at end of file +5f35c8cb8f8b67121c70f98c02c4aa7c25327690 \ No newline at end of file From 13c77bf86bc30ec65e10a35678b0ba5fa0f1b0f4 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 21 Aug 2013 15:52:22 +0000 Subject: [PATCH 08/17] Performance enhancement in btreeParseCellPtr(). FossilOrigin-Name: a17190a2296e8cd5e59524ff5914fc5ea3560697 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 9433316ef3..4ef209bd7d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sFTS4\sproblem\sintroduced\sby\s[361084e1eb]. -D 2013-08-21T15:45:27.749 +C Performance\senhancement\sin\sbtreeParseCellPtr(). +D 2013-08-21T15:52:22.167 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,7 +163,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c adea13e65d6c7b969bcd74cea6ae79b2d3c393fa +F src/btree.c d49f16006152a2f2737b6a904287797724dbd760 F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h 51cf220a9b9223354770883e93a859dc377aa27f F src/build.c f99a715ff9290996b579d5e1ec8e94239dc9ae5e @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 781592f32c8e1dcd59954c17211cf61349d1c0b1 -R 954710c672abb501b54f9208dbeb6f94 -U dan -Z 36f3acb088bc10968624ff14f224d8d6 +P 5f35c8cb8f8b67121c70f98c02c4aa7c25327690 +R e14622f8e8b62bb772b89104f8221b5c +U drh +Z b5924f726ed7a29e078b915e4c18ae4c diff --git a/manifest.uuid b/manifest.uuid index a78176e3f9..a8d0b5a9a8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f35c8cb8f8b67121c70f98c02c4aa7c25327690 \ No newline at end of file +a17190a2296e8cd5e59524ff5914fc5ea3560697 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 27f9f412fb..44c35e6415 100644 --- a/src/btree.c +++ b/src/btree.c @@ -940,7 +940,8 @@ static void btreeParseCellPtr( assert( n==4-4*pPage->leaf ); if( pPage->intKey ){ if( pPage->hasData ){ - n += getVarint32(&pCell[n], nPayload); + assert( n==0 ); + n = getVarint32(pCell, nPayload); }else{ nPayload = 0; } From 016f7811f2ce5b6f904654ee55a20817db3031eb Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Aug 2013 17:35:48 +0000 Subject: [PATCH 09/17] If a virtual table xSync() returns an error message, copy it into a buffer allocated by sqlite3DbMalloc() before transfering it to Vdbe.zErrMsg. FossilOrigin-Name: 854ba3049005adf033e07e6740a36e63f2a56758 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/sqliteInt.h | 3 ++- src/vdbe.c | 29 ++++++++--------------------- src/vdbeaux.c | 17 ++++++++++++++++- src/vtab.c | 9 +++------ 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/manifest b/manifest index 4ef209bd7d..016a599cf9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancement\sin\sbtreeParseCellPtr(). -D 2013-08-21T15:52:22.167 +C If\sa\svirtual\stable\sxSync()\sreturns\san\serror\smessage,\scopy\sit\sinto\sa\sbuffer\sallocated\sby\ssqlite3DbMalloc()\sbefore\stransfering\sit\sto\sVdbe.zErrMsg. +D 2013-08-21T17:35:48.189 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -221,7 +221,7 @@ F src/shell.c 1c317a4c96d61d8d9fdad9fd1811d9b10b8c7f57 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h eae58298bc7c9a491ad2fc6c600f534b74be8a11 +F src/sqliteInt.h e4ae9edb97983a8d7d751559391962cf7668948c F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -277,16 +277,16 @@ F src/update.c 7f3fe64d8f3b44c44a1eac293f0f85f87c355b7a F src/utf.c 8d819e2e5104a430fc2005f018db14347c95a38f F src/util.c f566b5138099a2df8533b190d0dcc74b7dfbe0c9 F src/vacuum.c d9c5759f4c5a438bb43c2086f72c5d2edabc36c8 -F src/vdbe.c 938feb53407dee2234849aad0f103ae9b941595e +F src/vdbe.c d37aee2c89e2a589f2b1599e0178eb17a08a3ccb F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4 F src/vdbeInt.h cbe71b8b36d8b3bba5709cc3f436c7e3b47b7b08 F src/vdbeapi.c 96b24b946cf21894f63d9393e821baa2f0a80979 -F src/vdbeaux.c a6ea36a9dc714e1128a0173249a0532ddcab0489 +F src/vdbeaux.c c7fe2695e256dbf254113c4fe90d3ec9aabe3bbe F src/vdbeblob.c 5dc79627775bd9a9b494dd956e26297946417d69 F src/vdbemem.c 833005f1cbbf447289f1973dba2a0c2228c7b8ab F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017 F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc -F src/vtab.c 2e8b489db47e20ae36cd247932dc671c9ded0624 +F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 5f35c8cb8f8b67121c70f98c02c4aa7c25327690 -R e14622f8e8b62bb772b89104f8221b5c -U drh -Z b5924f726ed7a29e078b915e4c18ae4c +P a17190a2296e8cd5e59524ff5914fc5ea3560697 +R 960d322e69aedcdd76cb08d63bcf1bec +U dan +Z adc03a3c46cd4ac4ea0aa84c35a35580 diff --git a/manifest.uuid b/manifest.uuid index a8d0b5a9a8..659dd1dc01 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a17190a2296e8cd5e59524ff5914fc5ea3560697 \ No newline at end of file +854ba3049005adf033e07e6740a36e63f2a56758 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 643040a7a2..bde4008016 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3153,13 +3153,14 @@ void sqlite3AutoLoadExtensions(sqlite3*); #else void sqlite3VtabClear(sqlite3 *db, Table*); void sqlite3VtabDisconnect(sqlite3 *db, Table *p); - int sqlite3VtabSync(sqlite3 *db, char **); + int sqlite3VtabSync(sqlite3 *db, Vdbe*); int sqlite3VtabRollback(sqlite3 *db); int sqlite3VtabCommit(sqlite3 *db); void sqlite3VtabLock(VTable *); void sqlite3VtabUnlock(VTable *); void sqlite3VtabUnlockList(sqlite3*); int sqlite3VtabSavepoint(sqlite3 *, int, int); + void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*); VTable *sqlite3GetVTable(sqlite3*, Table*); # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) #endif diff --git a/src/vdbe.c b/src/vdbe.c index 516e8ae9b4..6c825e4e9a 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -497,19 +497,6 @@ static int checkSavepointCount(sqlite3 *db){ } #endif -/* -** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored -** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored -** in memory obtained from sqlite3DbMalloc). -*/ -static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){ - sqlite3 *db = p->db; - sqlite3DbFree(db, p->zErrMsg); - p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg); - sqlite3_free(pVtab->zErrMsg); - pVtab->zErrMsg = 0; -} - /* ** Execute as much of a VDBE program as we can then return. @@ -4350,7 +4337,7 @@ case OP_Rowid: { /* out2-prerelease */ pModule = pVtab->pModule; assert( pModule->xRowid ); rc = pModule->xRowid(pC->pVtabCursor, &v); - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); #endif /* SQLITE_OMIT_VIRTUALTABLE */ }else{ assert( pC->pCursor!=0 ); @@ -5743,7 +5730,7 @@ case OP_VBegin: { VTable *pVTab; pVTab = pOp->p4.pVtab; rc = sqlite3VtabBegin(db, pVTab); - if( pVTab ) importVtabErrMsg(p, pVTab->pVtab); + if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab); break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -5794,7 +5781,7 @@ case OP_VOpen: { pModule = (sqlite3_module *)pVtab->pModule; assert(pVtab && pModule); rc = pModule->xOpen(pVtab, &pVtabCursor); - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); if( SQLITE_OK==rc ){ /* Initialize sqlite3_vtab_cursor base class */ pVtabCursor->pVtab = pVtab; @@ -5872,7 +5859,7 @@ case OP_VFilter: { /* jump */ p->inVtabMethod = 1; rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); p->inVtabMethod = 0; - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK ){ res = pModule->xEof(pVtabCursor); } @@ -5923,7 +5910,7 @@ case OP_VColumn: { MemSetTypeFlag(&sContext.s, MEM_Null); rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); if( sContext.isError ){ rc = sContext.isError; } @@ -5976,7 +5963,7 @@ case OP_VNext: { /* jump */ p->inVtabMethod = 1; rc = pModule->xNext(pCur->pVtabCursor); p->inVtabMethod = 0; - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK ){ res = pModule->xEof(pCur->pVtabCursor); } @@ -6013,7 +6000,7 @@ case OP_VRename: { rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8); if( rc==SQLITE_OK ){ rc = pVtab->pModule->xRename(pVtab, pName->z); - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); p->expired = 0; } break; @@ -6075,7 +6062,7 @@ case OP_VUpdate: { db->vtabOnConflict = pOp->p5; rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); db->vtabOnConflict = vtabOnConflict; - importVtabErrMsg(p, pVtab); + sqlite3VtabImportErrmsg(p, pVtab); if( rc==SQLITE_OK && pOp->p1 ){ assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); db->lastRowid = lastRowid = rowid; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 576483e141..ec071606a2 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1765,7 +1765,7 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){ ** required, as an xSync() callback may add an attached database ** to the transaction. */ - rc = sqlite3VtabSync(db, &p->zErrMsg); + rc = sqlite3VtabSync(db, p); /* This loop determines (a) if the commit hook should be invoked and ** (b) how many database files have open write transactions, not @@ -3304,3 +3304,18 @@ void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){ v->expmask |= ((u32)1 << (iVar-1)); } } + +#ifndef SQLITE_OMIT_VIRTUALTABLE +/* +** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored +** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored +** in memory obtained from sqlite3DbMalloc). +*/ +void sqlite3VtabImportErrmsg(Vdbe *p, sqlite3_vtab *pVtab){ + sqlite3 *db = p->db; + sqlite3DbFree(db, p->zErrMsg); + p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg); + sqlite3_free(pVtab->zErrMsg); + pVtab->zErrMsg = 0; +} +#endif /* SQLITE_OMIT_VIRTUALTABLE */ diff --git a/src/vtab.c b/src/vtab.c index a7fd17a35f..357a6dba2a 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -810,10 +810,9 @@ static void callFinaliser(sqlite3 *db, int offset){ ** array. Return the error code for the first error that occurs, or ** SQLITE_OK if all xSync operations are successful. ** -** Set *pzErrmsg to point to a buffer that should be released using -** sqlite3DbFree() containing an error message, if one is available. +** If an error message is available, leave it in p->zErrMsg. */ -int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){ +int sqlite3VtabSync(sqlite3 *db, Vdbe *p){ int i; int rc = SQLITE_OK; VTable **aVTrans = db->aVTrans; @@ -824,9 +823,7 @@ int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){ sqlite3_vtab *pVtab = aVTrans[i]->pVtab; if( pVtab && (x = pVtab->pModule->xSync)!=0 ){ rc = x(pVtab); - sqlite3DbFree(db, *pzErrmsg); - *pzErrmsg = pVtab->zErrMsg; - pVtab->zErrMsg = 0; + sqlite3VtabImportErrmsg(p, pVtab); } } db->aVTrans = aVTrans; From e7ecdfabd25d574b592eefc341dd76bb3c28cde5 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 21 Aug 2013 19:13:53 +0000 Subject: [PATCH 10/17] Update sqlite3MemCompare() to try common cases first, for a modest speed improvement. FossilOrigin-Name: b25bac79191975149d88fe34618c74354de62c5e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbemem.c | 43 +++++++++++++++++++------------------------ 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/manifest b/manifest index 016a599cf9..a875769543 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\svirtual\stable\sxSync()\sreturns\san\serror\smessage,\scopy\sit\sinto\sa\sbuffer\sallocated\sby\ssqlite3DbMalloc()\sbefore\stransfering\sit\sto\sVdbe.zErrMsg. -D 2013-08-21T17:35:48.189 +C Update\ssqlite3MemCompare()\sto\stry\scommon\scases\sfirst,\sfor\sa\smodest\sspeed\nimprovement. +D 2013-08-21T19:13:53.653 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -283,7 +283,7 @@ F src/vdbeInt.h cbe71b8b36d8b3bba5709cc3f436c7e3b47b7b08 F src/vdbeapi.c 96b24b946cf21894f63d9393e821baa2f0a80979 F src/vdbeaux.c c7fe2695e256dbf254113c4fe90d3ec9aabe3bbe F src/vdbeblob.c 5dc79627775bd9a9b494dd956e26297946417d69 -F src/vdbemem.c 833005f1cbbf447289f1973dba2a0c2228c7b8ab +F src/vdbemem.c 61d5ddb8e4d4e14f625062bf5bcc7ce08bb20af3 F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017 F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P a17190a2296e8cd5e59524ff5914fc5ea3560697 -R 960d322e69aedcdd76cb08d63bcf1bec -U dan -Z adc03a3c46cd4ac4ea0aa84c35a35580 +P 854ba3049005adf033e07e6740a36e63f2a56758 +R 5d5628959a5d40f606befcd69113ea6a +U drh +Z dcf5e645387c1a81c20687bc599ea742 diff --git a/manifest.uuid b/manifest.uuid index 659dd1dc01..e15601f04e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -854ba3049005adf033e07e6740a36e63f2a56758 \ No newline at end of file +b25bac79191975149d88fe34618c74354de62c5e \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index 8fc222e2de..0fa51e8ae1 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -799,34 +799,29 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){ ** if both values are integers. */ if( combined_flags&(MEM_Int|MEM_Real) ){ - if( !(f1&(MEM_Int|MEM_Real)) ){ - return 1; - } - if( !(f2&(MEM_Int|MEM_Real)) ){ - return -1; - } - if( (f1 & f2 & MEM_Int)==0 ){ - double r1, r2; - if( (f1&MEM_Real)==0 ){ - r1 = (double)pMem1->u.i; - }else{ - r1 = pMem1->r; - } - if( (f2&MEM_Real)==0 ){ - r2 = (double)pMem2->u.i; - }else{ - r2 = pMem2->r; - } - if( r1r2 ) return 1; - return 0; - }else{ - assert( f1&MEM_Int ); - assert( f2&MEM_Int ); + double r1, r2; + if( (f1 & f2 & MEM_Int)!=0 ){ if( pMem1->u.i < pMem2->u.i ) return -1; if( pMem1->u.i > pMem2->u.i ) return 1; return 0; } + if( (f1&MEM_Real)!=0 ){ + r1 = pMem1->r; + }else if( (f1&MEM_Int)!=0 ){ + r1 = (double)pMem1->u.i; + }else{ + return 1; + } + if( (f2&MEM_Real)!=0 ){ + r2 = pMem2->r; + }else if( (f2&MEM_Int)!=0 ){ + r2 = (double)pMem2->u.i; + }else{ + return -1; + } + if( r1r2 ) return 1; + return 0; } /* If one value is a string and the other is a blob, the string is less. From 47b299598326d691d564a803f27ff8b12e0ba6d1 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 21 Aug 2013 19:59:14 +0000 Subject: [PATCH 11/17] Fix typo in test. FossilOrigin-Name: f9859fe93bcecb4be7c1034291018523124c4a5c --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/collate2.test | 3 --- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index a875769543..6602baaafb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\ssqlite3MemCompare()\sto\stry\scommon\scases\sfirst,\sfor\sa\smodest\sspeed\nimprovement. -D 2013-08-21T19:13:53.653 +C Fix\stypo\sin\stest. +D 2013-08-21T19:59:14.262 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -367,7 +367,7 @@ F test/close.test 340bd24cc58b16c6bc01967402755027c37eb815 F test/closure01.test dbb28f1ea9eeaf0a53ec5bc0fed352e479def8c7 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 F test/collate1.test b709989e6e6ff6e1d2bd64231c2c1d8146846c9e -F test/collate2.test 96c4cded721b7df7fead3669bd5e5e56a1c1e72d +F test/collate2.test 9aaa410a00734e48bcb27f3872617d6f69b2a621 F test/collate3.test 79558a286362cb9ed603c6fa543f1cda7f563f0f F test/collate4.test 031f7265c13308b724ba3c49f41cc04612bd92b1 F test/collate5.test 65d928034d30d2d263a80f6359f7549ee1598ec6 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 854ba3049005adf033e07e6740a36e63f2a56758 -R 5d5628959a5d40f606befcd69113ea6a -U drh -Z dcf5e645387c1a81c20687bc599ea742 +P b25bac79191975149d88fe34618c74354de62c5e +R 4256e507dbd56983b9201102947b35fd +U mistachkin +Z 855e1f4db08112408b490484d606f43b diff --git a/manifest.uuid b/manifest.uuid index e15601f04e..9ed90e9644 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b25bac79191975149d88fe34618c74354de62c5e \ No newline at end of file +f9859fe93bcecb4be7c1034291018523124c4a5c \ No newline at end of file diff --git a/test/collate2.test b/test/collate2.test index a23728b15f..d5aadb4eb5 100644 --- a/test/collate2.test +++ b/test/collate2.test @@ -722,6 +722,3 @@ do_execsql_test 6.7 { } {b B} finish_test - - -finish_test From c63e880bdbf9c1a775feedae161ddbdc64e4de34 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 21 Aug 2013 20:04:54 +0000 Subject: [PATCH 12/17] Minor fixes for test cases. No code changes. FossilOrigin-Name: ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/malloc5.test | 2 ++ test/where2.test | 2 ++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6602baaafb..cabb3227c3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\stest. -D 2013-08-21T19:59:14.262 +C Minor\sfixes\sfor\stest\scases.\sNo\scode\schanges. +D 2013-08-21T20:04:54.847 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -644,7 +644,7 @@ F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9 F test/malloc.test fd368e31fe98d4779ed80442f311ed9f03bcd1f7 F test/malloc3.test e3b32c724b5a124b57cb0ed177f675249ad0c66a F test/malloc4.test 957337613002b7058a85116493a262f679f3a261 -F test/malloc5.test a577cbbcc1594c7763b9b3515b3633555751c7f0 +F test/malloc5.test fafce0aa9157060445cd1a56ad50fc79d82f28c3 F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151 F test/malloc7.test 7c68a32942858bc715284856c5507446bba88c3a F test/malloc8.test 9b7a3f8cb9cf0b12fff566e80a980b1767bd961d @@ -1039,7 +1039,7 @@ F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e F test/where.test da54153a4c1571ea1b95659e5bec8119edf786aa -F test/where2.test b1830f762f837153a4c9743adaab90a5761f73e7 +F test/where2.test 76d5346f7edb2a6a0442dcf3e9d088ac6903e0b5 F test/where3.test d28c51f257e60be30f74308fa385ceeddfb54a6e F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P b25bac79191975149d88fe34618c74354de62c5e -R 4256e507dbd56983b9201102947b35fd -U mistachkin -Z 855e1f4db08112408b490484d606f43b +P f9859fe93bcecb4be7c1034291018523124c4a5c +R ddee5479b507575b9f0433a0c601d21b +U dan +Z 54b08646e994fdf84c4fc6867487aa5d diff --git a/manifest.uuid b/manifest.uuid index 9ed90e9644..def9fd1722 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9859fe93bcecb4be7c1034291018523124c4a5c \ No newline at end of file +ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db \ No newline at end of file diff --git a/test/malloc5.test b/test/malloc5.test index c02f65e344..6abedf79e1 100644 --- a/test/malloc5.test +++ b/test/malloc5.test @@ -205,6 +205,7 @@ do_test malloc5-4.1 { execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');" } execsql {COMMIT;} + db cache flush sqlite3_release_memory sqlite3_memory_highwater 1 execsql {SELECT * FROM abc} @@ -213,6 +214,7 @@ do_test malloc5-4.1 { expr $nMaxBytes > 1000000 } {1} do_test malloc5-4.2 { + db cache flush sqlite3_release_memory sqlite3_soft_heap_limit 100000 sqlite3_memory_highwater 1 diff --git a/test/where2.test b/test/where2.test index c827ecc7b5..a3858c5909 100644 --- a/test/where2.test +++ b/test/where2.test @@ -701,6 +701,7 @@ do_test where2-11.4 { # Verify that the OR clause is used in an outer loop even when # the OR clause scores slightly better on an inner loop. +if {[permutation] != "no_optimization"} { do_execsql_test where2-12.1 { CREATE TABLE t12(x INTEGER PRIMARY KEY, y); CREATE INDEX t12y ON t12(y); @@ -709,6 +710,7 @@ do_execsql_test where2-12.1 { FROM t12 AS a JOIN t12 AS b ON a.y=b.x WHERE (b.x=$abc OR b.y=$abc); } {/.*SEARCH TABLE t12 AS b .*SEARCH TABLE t12 AS b .*/} +} finish_test From b49bc86a1a6134806dde81bb788fcf4a9fa8d7a9 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 21 Aug 2013 21:12:10 +0000 Subject: [PATCH 13/17] Simplification to the StrAccum object and the sqlite3StrAccumAppend() method that also results in slightly better performance. FossilOrigin-Name: 700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/btree.c | 2 +- src/func.c | 4 ++-- src/printf.c | 31 ++++++++++++++----------------- src/sqliteInt.h | 5 +++-- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index cabb3227c3..c036908051 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sfixes\sfor\stest\scases.\sNo\scode\schanges. -D 2013-08-21T20:04:54.847 +C Simplification\sto\sthe\sStrAccum\sobject\sand\sthe\ssqlite3StrAccumAppend()\nmethod\sthat\salso\sresults\sin\sslightly\sbetter\sperformance. +D 2013-08-21T21:12:10.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,7 +163,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c d49f16006152a2f2737b6a904287797724dbd760 +F src/btree.c 7e7b3eba8d902217fb2dbad0ac8217e952dba8ca F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h 51cf220a9b9223354770883e93a859dc377aa27f F src/build.c f99a715ff9290996b579d5e1ec8e94239dc9ae5e @@ -175,7 +175,7 @@ F src/delete.c 2317c814866d9aa71fea16b3faf4fdd4d6a49b94 F src/expr.c 6bab61c757c4c4c94a92e98d507025d5d18afd3c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 914a6bbd987d857c41ac9d244efa6641f36faadb -F src/func.c 5c50c1ea31fd864b0fe921fe1a8d4c55acd609ef +F src/func.c d7be77897c91d5b9887beb372f1e6deb515c92af F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759 F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 @@ -212,7 +212,7 @@ F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63 F src/pragma.c 1d96ba749253b49bc229c6294f9c2e5ef3dca85c F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f -F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e +F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 @@ -221,7 +221,7 @@ F src/shell.c 1c317a4c96d61d8d9fdad9fd1811d9b10b8c7f57 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h e4ae9edb97983a8d7d751559391962cf7668948c +F src/sqliteInt.h 124e4b19cd5533116909ccf203bdcdd04a28f99a F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f9859fe93bcecb4be7c1034291018523124c4a5c -R ddee5479b507575b9f0433a0c601d21b -U dan -Z 54b08646e994fdf84c4fc6867487aa5d +P ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db +R b5f522403c7336cdf922a181f76ebfed +U drh +Z 3ab1c9a1ca4e97a25908645404ada3f7 diff --git a/manifest.uuid b/manifest.uuid index def9fd1722..261a986cf4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db \ No newline at end of file +700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 44c35e6415..3fcce0dd46 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7747,7 +7747,7 @@ static void checkAppendMsg( } sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); va_end(ap); - if( pCheck->errMsg.mallocFailed ){ + if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ pCheck->mallocFailed = 1; } } diff --git a/src/func.c b/src/func.c index 49f6c892be..be6e238670 100644 --- a/src/func.c +++ b/src/func.c @@ -1522,9 +1522,9 @@ static void groupConcatFinalize(sqlite3_context *context){ StrAccum *pAccum; pAccum = sqlite3_aggregate_context(context, 0); if( pAccum ){ - if( pAccum->tooBig ){ + if( pAccum->accError==STRACCUM_TOOBIG ){ sqlite3_result_error_toobig(context); - }else if( pAccum->mallocFailed ){ + }else if( pAccum->accError==STRACCUM_NOMEM ){ sqlite3_result_error_nomem(context); }else{ sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1, diff --git a/src/printf.c b/src/printf.c index 67649b269b..f9e5c6406d 100644 --- a/src/printf.c +++ b/src/printf.c @@ -359,7 +359,7 @@ void sqlite3VXPrintf( nOut = precision + 10; zOut = zExtra = sqlite3Malloc( nOut ); if( zOut==0 ){ - pAccum->mallocFailed = 1; + pAccum->accError = STRACCUM_NOMEM; return; } } @@ -471,7 +471,7 @@ void sqlite3VXPrintf( if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); if( bufpt==0 ){ - pAccum->mallocFailed = 1; + pAccum->accError = STRACCUM_NOMEM; return; } } @@ -606,7 +606,7 @@ void sqlite3VXPrintf( if( n>etBUFSIZE ){ bufpt = zExtra = sqlite3Malloc( n ); if( bufpt==0 ){ - pAccum->mallocFailed = 1; + pAccum->accError = STRACCUM_NOMEM; return; } }else{ @@ -684,22 +684,20 @@ void sqlite3VXPrintf( */ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ assert( z!=0 || N==0 ); - if( p->tooBig | p->mallocFailed ){ - testcase(p->tooBig); - testcase(p->mallocFailed); + if( p->accError ){ + testcase(p->accError==STRACCUM_TOOBIG); + testcase(p->accError==STRACCUM_NOMEM); return; } assert( p->zText!=0 || p->nChar==0 ); - if( N<0 ){ + if( N<=0 ){ + if( N==0 || z[0]==0 ) return; N = sqlite3Strlen30(z); } - if( N==0 || NEVER(z==0) ){ - return; - } if( p->nChar+N >= p->nAlloc ){ char *zNew; if( !p->useMalloc ){ - p->tooBig = 1; + p->accError = STRACCUM_TOOBIG; N = p->nAlloc - p->nChar - 1; if( N<=0 ){ return; @@ -710,7 +708,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ szNew += N + 1; if( szNew > p->mxAlloc ){ sqlite3StrAccumReset(p); - p->tooBig = 1; + p->accError = STRACCUM_TOOBIG; return; }else{ p->nAlloc = (int)szNew; @@ -724,7 +722,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); p->zText = zNew; }else{ - p->mallocFailed = 1; + p->accError = STRACCUM_NOMEM; sqlite3StrAccumReset(p); return; } @@ -752,7 +750,7 @@ char *sqlite3StrAccumFinish(StrAccum *p){ if( p->zText ){ memcpy(p->zText, p->zBase, p->nChar+1); }else{ - p->mallocFailed = 1; + p->accError = STRACCUM_NOMEM; } } } @@ -783,8 +781,7 @@ void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ p->nAlloc = n; p->mxAlloc = mx; p->useMalloc = 1; - p->tooBig = 0; - p->mallocFailed = 0; + p->accError = 0; } /* @@ -801,7 +798,7 @@ char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ acc.db = db; sqlite3VXPrintf(&acc, 1, zFormat, ap); z = sqlite3StrAccumFinish(&acc); - if( acc.mallocFailed ){ + if( acc.accError==STRACCUM_NOMEM ){ db->mallocFailed = 1; } return z; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index bde4008016..025bb466d5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2425,10 +2425,11 @@ struct StrAccum { int nChar; /* Length of the string so far */ int nAlloc; /* Amount of space allocated in zText */ int mxAlloc; /* Maximum allowed string length */ - u8 mallocFailed; /* Becomes true if any memory allocation fails */ u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */ - u8 tooBig; /* Becomes true if string size exceeds limits */ + u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ }; +#define STRACCUM_NOMEM 1 +#define STRACCUM_TOOBIG 2 /* ** A pointer to this structure is used to communicate information From cf5ff12105aa5108dba3c00d65b21da05dbaa3db Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 21 Aug 2013 22:09:25 +0000 Subject: [PATCH 14/17] Refactor the sqlite3_randomness() implementation for improved performance. FossilOrigin-Name: 4144dffb57b5ed791d7a6d2f26fab5e7dc77fbd1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/random.c | 51 ++++++++++++++------------------------------------- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/manifest b/manifest index c036908051..6265e284f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplification\sto\sthe\sStrAccum\sobject\sand\sthe\ssqlite3StrAccumAppend()\nmethod\sthat\salso\sresults\sin\sslightly\sbetter\sperformance. -D 2013-08-21T21:12:10.959 +C Refactor\sthe\ssqlite3_randomness()\simplementation\sfor\simproved\sperformance. +D 2013-08-21T22:09:25.294 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -213,7 +213,7 @@ F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63 F src/pragma.c 1d96ba749253b49bc229c6294f9c2e5ef3dca85c F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b -F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 +F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68 F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db -R b5f522403c7336cdf922a181f76ebfed +P 700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a +R bace2fbe40d117379ef5fcee60c09ed4 U drh -Z 3ab1c9a1ca4e97a25908645404ada3f7 +Z a22b19ec66f802a5577e622202a99c6b diff --git a/manifest.uuid b/manifest.uuid index 261a986cf4..e433e95dde 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a \ No newline at end of file +4144dffb57b5ed791d7a6d2f26fab5e7dc77fbd1 \ No newline at end of file diff --git a/src/random.c b/src/random.c index 234ebdf658..7afff50885 100644 --- a/src/random.c +++ b/src/random.c @@ -28,24 +28,11 @@ static SQLITE_WSD struct sqlite3PrngType { } sqlite3Prng; /* -** Get a single 8-bit random value from the RC4 PRNG. The Mutex -** must be held while executing this routine. -** -** Why not just use a library random generator like lrand48() for this? -** Because the OP_NewRowid opcode in the VDBE depends on having a very -** good source of random numbers. The lrand48() library function may -** well be good enough. But maybe not. Or maybe lrand48() has some -** subtle problems on some systems that could cause problems. It is hard -** to know. To minimize the risk of problems due to bad lrand48() -** implementations, SQLite uses this random number generator based -** on RC4, which we know works very well. -** -** (Later): Actually, OP_NewRowid does not depend on a good source of -** randomness any more. But we will leave this code in all the same. +** Return N random bytes. */ -static u8 randomByte(void){ +void sqlite3_randomness(int N, void *pBuf){ unsigned char t; - + unsigned char *zBuf = pBuf; /* The "wsdPrng" macro will resolve to the pseudo-random number generator ** state vector. If writable static data is unsupported on the target, @@ -60,6 +47,10 @@ static u8 randomByte(void){ # define wsdPrng sqlite3Prng #endif +#if SQLITE_THREADSAFE + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); + sqlite3_mutex_enter(mutex); +#endif /* Initialize the state of the random number generator once, ** the first time this routine is called. The seed value does @@ -88,28 +79,14 @@ static u8 randomByte(void){ wsdPrng.isInit = 1; } - /* Generate and return single random byte - */ - wsdPrng.i++; - t = wsdPrng.s[wsdPrng.i]; - wsdPrng.j += t; - wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; - wsdPrng.s[wsdPrng.j] = t; - t += wsdPrng.s[wsdPrng.i]; - return wsdPrng.s[t]; -} - -/* -** Return N random bytes. -*/ -void sqlite3_randomness(int N, void *pBuf){ - unsigned char *zBuf = pBuf; -#if SQLITE_THREADSAFE - sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); -#endif - sqlite3_mutex_enter(mutex); while( N-- ){ - *(zBuf++) = randomByte(); + wsdPrng.i++; + t = wsdPrng.s[wsdPrng.i]; + wsdPrng.j += t; + wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; + wsdPrng.s[wsdPrng.j] = t; + t += wsdPrng.s[wsdPrng.i]; + *(zBuf++) = wsdPrng.s[t]; } sqlite3_mutex_leave(mutex); } From 9d1ab0794e8045b8e9649b7d990c204726777890 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 21 Aug 2013 22:54:55 +0000 Subject: [PATCH 15/17] Minor performance tweaks to the pager. FossilOrigin-Name: 9ae1f9ce7ea6beaeddc3711080b3796e05acc4f8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 20 +++++++++----------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 6265e284f8..382174c2bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Refactor\sthe\ssqlite3_randomness()\simplementation\sfor\simproved\sperformance. -D 2013-08-21T22:09:25.294 +C Minor\sperformance\stweaks\sto\sthe\spager. +D 2013-08-21T22:54:55.506 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -204,7 +204,7 @@ F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 9eafa5458cf2ff684ddccff82c9bb113c7cad847 F src/os_win.c 1d84f2079d9b91f91a4b5dbfa5e08f1b1a0ed0ff -F src/pager.c 7c999137cb940133f7fc7609ccfa66f17eec4ab4 +F src/pager.c 7e9130d5fad290aa6d6cf016852bde9ce0a06ea5 F src/pager.h 66e42d6942a445d4c25651733ab2079dbebc7ca9 F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a -R bace2fbe40d117379ef5fcee60c09ed4 +P 4144dffb57b5ed791d7a6d2f26fab5e7dc77fbd1 +R b15f43d0f820a86b48ec589e9a604865 U drh -Z a22b19ec66f802a5577e622202a99c6b +Z cdb48d46f0e84ecc9bf7ab245ef06a01 diff --git a/manifest.uuid b/manifest.uuid index e433e95dde..9d7b50680c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4144dffb57b5ed791d7a6d2f26fab5e7dc77fbd1 \ No newline at end of file +9ae1f9ce7ea6beaeddc3711080b3796e05acc4f8 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 77a7d86a0d..6ccf2d7cee 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1022,13 +1022,17 @@ static char *print_pager_state(Pager *p){ ** PagerSavepoint.pInSavepoint. */ static int subjRequiresPage(PgHdr *pPg){ - Pgno pgno = pPg->pgno; Pager *pPager = pPg->pPager; + PagerSavepoint *p; + Pgno pgno; int i; - for(i=0; inSavepoint; i++){ - PagerSavepoint *p = &pPager->aSavepoint[i]; - if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ - return 1; + if( pPager->nSavepoint ){ + pgno = pPg->pgno; + for(i=0; inSavepoint; i++){ + p = &pPager->aSavepoint[i]; + if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ + return 1; + } } } return 0; @@ -2874,12 +2878,6 @@ static int readDbPage(PgHdr *pPg, u32 iFrame){ assert( pPager->eState>=PAGER_READER && !MEMDB ); assert( isOpen(pPager->fd) ); - if( NEVER(!isOpen(pPager->fd)) ){ - assert( pPager->tempFile ); - memset(pPg->pData, 0, pPager->pageSize); - return SQLITE_OK; - } - #ifndef SQLITE_OMIT_WAL if( iFrame ){ /* Try to pull the page from the write-ahead log. */ From b00fc3b14efee22ae7db3bf9f5fcf40ef055bf82 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 21 Aug 2013 23:42:32 +0000 Subject: [PATCH 16/17] Simplify the btreeGetPage() routine so that it uses a single flag parameter in place of two boolean parameters. FossilOrigin-Name: 617e23ec283d3147fc3fd29c474ccedf4915cdc7 --- manifest | 18 +++++++-------- manifest.uuid | 2 +- src/backup.c | 2 +- src/btree.c | 62 +++++++++++++++++++++++++-------------------------- src/pager.c | 6 ++--- src/pager.h | 4 ++-- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/manifest b/manifest index 382174c2bc..07c1642183 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sperformance\stweaks\sto\sthe\spager. -D 2013-08-21T22:54:55.506 +C Simplify\sthe\sbtreeGetPage()\sroutine\sso\sthat\sit\suses\sa\ssingle\sflag\sparameter\nin\splace\sof\stwo\sboolean\sparameters. +D 2013-08-21T23:42:32.077 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -160,10 +160,10 @@ F src/alter.c f8db986c03eb0bfb221523fc9bbb9d0b70de3168 F src/analyze.c a33fcb0b3a399d966951feb9f32115106b3ecc2e F src/attach.c 5df737912f668fd160ec1d560755f85fdccbe5b7 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 -F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 +F src/backup.c 2f1987981139bd2f6d8c728d64bf09fb387443c3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 7e7b3eba8d902217fb2dbad0ac8217e952dba8ca +F src/btree.c b7cbb0bcc61cbf1e0ed3cfcc79ee12ffcf4f469e F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h 51cf220a9b9223354770883e93a859dc377aa27f F src/build.c f99a715ff9290996b579d5e1ec8e94239dc9ae5e @@ -204,8 +204,8 @@ F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 9eafa5458cf2ff684ddccff82c9bb113c7cad847 F src/os_win.c 1d84f2079d9b91f91a4b5dbfa5e08f1b1a0ed0ff -F src/pager.c 7e9130d5fad290aa6d6cf016852bde9ce0a06ea5 -F src/pager.h 66e42d6942a445d4c25651733ab2079dbebc7ca9 +F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 +F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 4144dffb57b5ed791d7a6d2f26fab5e7dc77fbd1 -R b15f43d0f820a86b48ec589e9a604865 +P 9ae1f9ce7ea6beaeddc3711080b3796e05acc4f8 +R 14b54904acb5b4b4c7c51baf723290ac U drh -Z cdb48d46f0e84ecc9bf7ab245ef06a01 +Z 0a305d97c258e659e4da204fe193224d diff --git a/manifest.uuid b/manifest.uuid index 9d7b50680c..f6dfd7fe75 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9ae1f9ce7ea6beaeddc3711080b3796e05acc4f8 \ No newline at end of file +617e23ec283d3147fc3fd29c474ccedf4915cdc7 \ No newline at end of file diff --git a/src/backup.c b/src/backup.c index 6ef9374ec6..afbaeeb109 100644 --- a/src/backup.c +++ b/src/backup.c @@ -392,7 +392,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){ if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){ DbPage *pSrcPg; /* Source page object */ rc = sqlite3PagerAcquire(pSrcPager, iSrcPg, &pSrcPg, - PAGER_ACQUIRE_READONLY); + PAGER_GET_READONLY); if( rc==SQLITE_OK ){ rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0); sqlite3PagerUnref(pSrcPg); diff --git a/src/btree.c b/src/btree.c index 3fcce0dd46..d6fb5834c5 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1585,15 +1585,12 @@ static int btreeGetPage( BtShared *pBt, /* The btree */ Pgno pgno, /* Number of the page to fetch */ MemPage **ppPage, /* Return the page in this parameter */ - int noContent, /* Do not load page content if true */ - int bReadonly /* True if a read-only (mmap) page is ok */ + int flags /* PAGER_GET_NOCONTENT or PAGER_GET_READONLY */ ){ int rc; DbPage *pDbPage; - int flags = (noContent ? PAGER_ACQUIRE_NOCONTENT : 0) - | (bReadonly ? PAGER_ACQUIRE_READONLY : 0); - assert( noContent==0 || bReadonly==0 ); + assert( flags==0 || flags==PAGER_GET_NOCONTENT || flags==PAGER_GET_READONLY ); assert( sqlite3_mutex_held(pBt->mutex) ); rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, flags); if( rc ) return rc; @@ -1641,15 +1638,16 @@ static int getAndInitPage( BtShared *pBt, /* The database file */ Pgno pgno, /* Number of the page to get */ MemPage **ppPage, /* Write the page pointer here */ - int bReadonly /* True if a read-only (mmap) page is ok */ + int bReadonly /* PAGER_GET_READONLY or 0 */ ){ int rc; assert( sqlite3_mutex_held(pBt->mutex) ); + assert( bReadonly==PAGER_GET_READONLY || bReadonly==0 ); if( pgno>btreePagecount(pBt) ){ rc = SQLITE_CORRUPT_BKPT; }else{ - rc = btreeGetPage(pBt, pgno, ppPage, 0, bReadonly); + rc = btreeGetPage(pBt, pgno, ppPage, bReadonly); if( rc==SQLITE_OK ){ rc = btreeInitPage(*ppPage); if( rc!=SQLITE_OK ){ @@ -2382,7 +2380,7 @@ static int lockBtree(BtShared *pBt){ assert( pBt->pPage1==0 ); rc = sqlite3PagerSharedLock(pBt->pPager); if( rc!=SQLITE_OK ) return rc; - rc = btreeGetPage(pBt, 1, &pPage1, 0, 0); + rc = btreeGetPage(pBt, 1, &pPage1, 0); if( rc!=SQLITE_OK ) return rc; /* Do some checking to help insure the file we opened really is @@ -2964,7 +2962,7 @@ static int relocatePage( ** iPtrPage. */ if( eType!=PTRMAP_ROOTPAGE ){ - rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0, 0); + rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0); if( rc!=SQLITE_OK ){ return rc; } @@ -3048,7 +3046,7 @@ static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){ u8 eMode = BTALLOC_ANY; /* Mode parameter for allocateBtreePage() */ Pgno iNear = 0; /* nearby parameter for allocateBtreePage() */ - rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0, 0); + rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0); if( rc!=SQLITE_OK ){ return rc; } @@ -3447,7 +3445,7 @@ int sqlite3BtreeRollback(Btree *p, int tripCode){ /* The rollback may have destroyed the pPage1->aData value. So ** call btreeGetPage() on page 1 again to make ** sure pPage1->aData is set correctly. */ - if( btreeGetPage(pBt, 1, &pPage1, 0, 0)==SQLITE_OK ){ + if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){ int nPage = get4byte(28+(u8*)pPage1->aData); testcase( nPage==0 ); if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage); @@ -3882,7 +3880,7 @@ static int getOverflowPage( assert( next==0 || rc==SQLITE_DONE ); if( rc==SQLITE_OK ){ - rc = btreeGetPage(pBt, ovfl, &pPage, 0, (ppPage==0)); + rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0); assert( rc==SQLITE_OK || pPage==0 ); if( rc==SQLITE_OK ){ next = get4byte(pPage->aData); @@ -4104,7 +4102,7 @@ static int accessPayload( { DbPage *pDbPage; rc = sqlite3PagerAcquire(pBt->pPager, nextPage, &pDbPage, - (eOp==0 ? PAGER_ACQUIRE_READONLY : 0) + (eOp==0 ? PAGER_GET_READONLY : 0) ); if( rc==SQLITE_OK ){ aPayload = sqlite3PagerGetData(pDbPage); @@ -4288,7 +4286,8 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){ return SQLITE_CORRUPT_BKPT; } - rc = getAndInitPage(pBt, newPgno, &pNewPage, (pCur->wrFlag==0)); + rc = getAndInitPage(pBt, newPgno, &pNewPage, + pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); if( rc ) return rc; pCur->apPage[i+1] = pNewPage; pCur->aiIdx[i+1] = 0; @@ -4405,7 +4404,8 @@ static int moveToRoot(BtCursor *pCur){ pCur->eState = CURSOR_INVALID; return SQLITE_OK; }else{ - rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], pCur->wrFlag==0); + rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], + pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); if( rc!=SQLITE_OK ){ pCur->eState = CURSOR_INVALID; return rc; @@ -5042,7 +5042,7 @@ static int allocateBtreePage( if( iTrunk>mxPage ){ rc = SQLITE_CORRUPT_BKPT; }else{ - rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0); + rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0); } if( rc ){ pTrunk = 0; @@ -5106,7 +5106,7 @@ static int allocateBtreePage( goto end_allocate_page; } testcase( iNewTrunk==mxPage ); - rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0, 0); + rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0); if( rc!=SQLITE_OK ){ goto end_allocate_page; } @@ -5185,8 +5185,8 @@ static int allocateBtreePage( memcpy(&aData[8+closest*4], &aData[4+k*4], 4); } put4byte(&aData[4], k-1); - noContent = !btreeGetHasContent(pBt, *pPgno); - rc = btreeGetPage(pBt, *pPgno, ppPage, noContent, 0); + noContent = !btreeGetHasContent(pBt, *pPgno) ? PAGER_GET_NOCONTENT : 0; + rc = btreeGetPage(pBt, *pPgno, ppPage, noContent); if( rc==SQLITE_OK ){ rc = sqlite3PagerWrite((*ppPage)->pDbPage); if( rc!=SQLITE_OK ){ @@ -5218,7 +5218,7 @@ static int allocateBtreePage( ** here are confined to those pages that lie between the end of the ** database image and the end of the database file. */ - int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)); + int bNoContent = (0==IfNotOmitAV(pBt->bDoTruncate)) ? PAGER_GET_NOCONTENT : 0; rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); if( rc ) return rc; @@ -5234,7 +5234,7 @@ static int allocateBtreePage( MemPage *pPg = 0; TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage)); assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) ); - rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent, 0); + rc = btreeGetPage(pBt, pBt->nPage, &pPg, bNoContent); if( rc==SQLITE_OK ){ rc = sqlite3PagerWrite(pPg->pDbPage); releasePage(pPg); @@ -5248,7 +5248,7 @@ static int allocateBtreePage( *pPgno = pBt->nPage; assert( *pPgno!=PENDING_BYTE_PAGE(pBt) ); - rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent, 0); + rc = btreeGetPage(pBt, *pPgno, ppPage, bNoContent); if( rc ) return rc; rc = sqlite3PagerWrite((*ppPage)->pDbPage); if( rc!=SQLITE_OK ){ @@ -5316,7 +5316,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){ /* If the secure_delete option is enabled, then ** always fully overwrite deleted information with zeros. */ - if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0, 0))!=0) ) + if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) ) || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0) ){ goto freepage_out; @@ -5343,7 +5343,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){ u32 nLeaf; /* Initial number of leaf cells on trunk page */ iTrunk = get4byte(&pPage1->aData[32]); - rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0, 0); + rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0); if( rc!=SQLITE_OK ){ goto freepage_out; } @@ -5389,7 +5389,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){ ** first trunk in the free-list is full. Either way, the page being freed ** will become the new first trunk page in the free-list. */ - if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0, 0)) ){ + if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){ goto freepage_out; } rc = sqlite3PagerWrite(pPage->pDbPage); @@ -7288,7 +7288,7 @@ static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){ } /* Move the page currently at pgnoRoot to pgnoMove. */ - rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0); + rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0); if( rc!=SQLITE_OK ){ return rc; } @@ -7309,7 +7309,7 @@ static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){ if( rc!=SQLITE_OK ){ return rc; } - rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0, 0); + rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0); if( rc!=SQLITE_OK ){ return rc; } @@ -7487,7 +7487,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){ return SQLITE_LOCKED_SHAREDCACHE; } - rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0, 0); + rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); if( rc ) return rc; rc = sqlite3BtreeClearTable(p, iTable, 0); if( rc ){ @@ -7522,7 +7522,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){ */ MemPage *pMove; releasePage(pPage); - rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0); + rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); if( rc!=SQLITE_OK ){ return rc; } @@ -7532,7 +7532,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){ return rc; } pMove = 0; - rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0, 0); + rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0); freePage(pMove, &rc); releasePage(pMove); if( rc!=SQLITE_OK ){ @@ -7944,7 +7944,7 @@ static int checkTreePage( usableSize = pBt->usableSize; if( iPage==0 ) return 0; if( checkRef(pCheck, iPage, zParentContext) ) return 0; - if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0, 0))!=0 ){ + if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){ checkAppendMsg(pCheck, zContext, "unable to get the page. error code=%d", rc); return 0; diff --git a/src/pager.c b/src/pager.c index 6ccf2d7cee..d675b85821 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5231,19 +5231,19 @@ int sqlite3PagerAcquire( Pager *pPager, /* The pager open on the database file */ Pgno pgno, /* Page number to fetch */ DbPage **ppPage, /* Write a pointer to the page here */ - int flags /* PAGER_ACQUIRE_XXX flags */ + int flags /* PAGER_GET_XXX flags */ ){ int rc = SQLITE_OK; PgHdr *pPg = 0; u32 iFrame = 0; /* Frame to read from WAL file */ - const int noContent = (flags & PAGER_ACQUIRE_NOCONTENT); + const int noContent = (flags & PAGER_GET_NOCONTENT); /* It is acceptable to use a read-only (mmap) page for any page except ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY ** flag was specified by the caller. And so long as the db is not a ** temporary or in-memory database. */ const int bMmapOk = (pgno!=1 && USEFETCH(pPager) - && (pPager->eState==PAGER_READER || (flags & PAGER_ACQUIRE_READONLY)) + && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY)) #ifdef SQLITE_HAS_CODEC && pPager->xCodec==0 #endif diff --git a/src/pager.h b/src/pager.h index 5528be14e7..7851d28345 100644 --- a/src/pager.h +++ b/src/pager.h @@ -81,8 +81,8 @@ typedef struct PgHdr DbPage; /* ** Flags that make up the mask passed to sqlite3PagerAcquire(). */ -#define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */ -#define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */ +#define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */ +#define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */ /* ** Flags for sqlite3PagerSetFlags() From cc04afdad03905e34e32db7f47ceca9ff0f29d08 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 22 Aug 2013 02:56:28 +0000 Subject: [PATCH 17/17] Defer the creation of automatic indices until the index is actually used. FossilOrigin-Name: 0775501acf152dcbf4dd039f4511f3d8c4330d85 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 19 ++++++++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 07c1642183..18542bbdc3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\sbtreeGetPage()\sroutine\sso\sthat\sit\suses\sa\ssingle\sflag\sparameter\nin\splace\sof\stwo\sboolean\sparameters. -D 2013-08-21T23:42:32.077 +C Defer\sthe\screation\sof\sautomatic\sindices\suntil\sthe\sindex\sis\sactually\sused. +D 2013-08-22T02:56:28.029 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 0ced8882cadbf1817904331a5d942b30ebe0e789 +F src/where.c 8596edcfbffc6d26a9a4f8e4a41d09f058dd7037 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 9ae1f9ce7ea6beaeddc3711080b3796e05acc4f8 -R 14b54904acb5b4b4c7c51baf723290ac +P 617e23ec283d3147fc3fd29c474ccedf4915cdc7 +R c8cf06f49dffbef3bb0170f8252069c7 U drh -Z 0a305d97c258e659e4da204fe193224d +Z c5e5b20d4589a0c600c887ab3fa62d4e diff --git a/manifest.uuid b/manifest.uuid index f6dfd7fe75..296e198d71 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -617e23ec283d3147fc3fd29c474ccedf4915cdc7 \ No newline at end of file +0775501acf152dcbf4dd039f4511f3d8c4330d85 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 23a35fa790..1375c585e1 100644 --- a/src/where.c +++ b/src/where.c @@ -90,6 +90,7 @@ struct WhereLevel { int addrNxt; /* Jump here to start the next IN combination */ int addrCont; /* Jump here to continue with the next loop cycle */ int addrFirst; /* First instruction of interior of the loop */ + int addrBody; /* Beginning of the body of this loop */ u8 iFrom; /* Which entry in the FROM clause */ u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */ int p1, p2; /* Operands of the opcode used to ends the loop */ @@ -5984,11 +5985,6 @@ WhereInfo *sqlite3WhereBegin( }else{ sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); } -#ifndef SQLITE_OMIT_AUTOMATIC_INDEX - if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ - constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel); - }else -#endif if( pLoop->wsFlags & WHERE_INDEXED ){ Index *pIx = pLoop->u.btree.pIndex; KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx); @@ -6013,7 +6009,15 @@ WhereInfo *sqlite3WhereBegin( notReady = ~(Bitmask)0; for(ii=0; iia[ii]; +#ifndef SQLITE_OMIT_AUTOMATIC_INDEX + if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ + constructAutomaticIndex(pParse, &pWInfo->sWC, + &pTabList->a[pLevel->iFrom], notReady, pLevel); + if( db->mallocFailed ) goto whereBeginError; + } +#endif explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags); + pLevel->addrBody = sqlite3VdbeCurrentAddr(v); notReady = codeOneLoopStart(pWInfo, ii, notReady); pWInfo->iContinue = pLevel->addrCont; } @@ -6133,9 +6137,10 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ int k, j, last; VdbeOp *pOp; - pOp = sqlite3VdbeGetOp(v, pWInfo->iTop); last = sqlite3VdbeCurrentAddr(v); - for(k=pWInfo->iTop; kaddrBody; + pOp = sqlite3VdbeGetOp(v, k); + for(; kp1!=pLevel->iTabCur ) continue; if( pOp->opcode==OP_Column ){ for(j=0; jnColumn; j++){