From edf5b1657dc1fc1301de36de3b353295c383a064 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 19 Aug 2014 09:15:41 +0000 Subject: [PATCH 01/16] Minor changes to do with the Tcl tea extension package autoconf system. FossilOrigin-Name: f10a6111262ce6ee6984c64fa0e0023642eca27d --- autoconf/tea/Makefile.in | 1 + autoconf/tea/configure.in | 6 ++++-- autoconf/tea/tclconfig/tcl.m4 | 21 ++++++++++++--------- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/tclsqlite.c | 2 +- tool/mkautoconfamal.sh | 2 +- 7 files changed, 31 insertions(+), 25 deletions(-) diff --git a/autoconf/tea/Makefile.in b/autoconf/tea/Makefile.in index 08b1a44182..a8708974b0 100644 --- a/autoconf/tea/Makefile.in +++ b/autoconf/tea/Makefile.in @@ -73,6 +73,7 @@ exec_prefix = @exec_prefix@ bindir = @bindir@ libdir = @libdir@ +datarootdir = @datarootdir@ datadir = @datadir@ mandir = @mandir@ includedir = @includedir@ diff --git a/autoconf/tea/configure.in b/autoconf/tea/configure.in index ec9c565c6f..8df0af6195 100644 --- a/autoconf/tea/configure.in +++ b/autoconf/tea/configure.in @@ -166,8 +166,10 @@ AC_DEFINE(USE_TCL_STUBS, 1, [Use Tcl stubs]) #-------------------------------------------------------------------- # Redefine fdatasync as fsync on systems that lack fdatasync #-------------------------------------------------------------------- - -AC_CHECK_FUNC(fdatasync, , AC_DEFINE(fdatasync, fsync)) +# +#AC_CHECK_FUNC(fdatasync, , AC_DEFINE(fdatasync, fsync)) +# Check for library functions that SQLite can optionally use. +AC_CHECK_FUNCS([fdatasync usleep fullfsync localtime_r gmtime_r]) AC_FUNC_STRERROR_R diff --git a/autoconf/tea/tclconfig/tcl.m4 b/autoconf/tea/tclconfig/tcl.m4 index 66214e78a2..4b4bd1e888 100644 --- a/autoconf/tea/tclconfig/tcl.m4 +++ b/autoconf/tea/tclconfig/tcl.m4 @@ -1641,6 +1641,7 @@ AC_DEFUN([TEA_CONFIG_CFLAGS], [ SHLIB_CFLAGS="-fPIC" SHLIB_LD="${CC} -shared" TCL_SHLIB_LD_EXTRAS="-Wl,-soname=\$[@]" + TK_SHLIB_LD_EXTRAS="-Wl,-soname,\$[@]" SHLIB_SUFFIX=".so" LDFLAGS="" AS_IF([test $doRpath = yes], [ @@ -1651,11 +1652,15 @@ AC_DEFUN([TEA_CONFIG_CFLAGS], [ LIBS=`echo $LIBS | sed s/-pthread//` CFLAGS="$CFLAGS $PTHREAD_CFLAGS" LDFLAGS="$LDFLAGS $PTHREAD_LIBS"]) - # Version numbers are dot-stripped by system policy. - TCL_TRIM_DOTS=`echo ${PACKAGE_VERSION} | tr -d .` - UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' - SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1' - TCL_LIB_VERSIONS_OK=nodots + case $system in + FreeBSD-3.*) + # Version numbers are dot-stripped by system policy. + TCL_TRIM_DOTS=`echo ${VERSION} | tr -d .` + UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' + SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so' + TCL_LIB_VERSIONS_OK=nodots + ;; + esac ;; Darwin-*) CFLAGS_OPTIMIZE="-Os" @@ -1826,8 +1831,8 @@ AC_DEFUN([TEA_CONFIG_CFLAGS], [ SHLIB_CFLAGS="-fPIC -melf" LDFLAGS="$LDFLAGS -melf -Wl,-Bexport" ], [ - SHLIB_CFLAGS="-Kpic -belf" - LDFLAGS="$LDFLAGS -belf -Wl,-Bexport" + SHLIB_CFLAGS="-Kpic -belf" + LDFLAGS="$LDFLAGS -belf -Wl,-Bexport" ]) SHLIB_LD="ld -G" SHLIB_LD_LIBS="" @@ -4158,8 +4163,6 @@ AC_DEFUN([TEA_PATH_CELIB], [ fi fi ]) - - # Local Variables: # mode: autoconf # End: diff --git a/manifest b/manifest index 6b5562f42e..963d794593 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Refactor\sthe\snames\sof\sstate\sobjects\sin\sthe\scommand-line\sshell\simplementation.. -D 2014-08-18T13:45:42.156 +C Minor\schanges\sto\sdo\swith\sthe\sTcl\stea\sextension\spackage\sautoconf\ssystem. +D 2014-08-19T09:15:41.141 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -23,15 +23,15 @@ F autoconf/depcomp 0b26f101e3bc9fd1ff0be1da9fb4a82371142f92 x F autoconf/install-sh 06ee6336e63bb845c8439d777c32eb2eccc4fbf1 x F autoconf/ltmain.sh 7a658a24028f02331c1d2446562758083c5eadd1 F autoconf/missing d7c9981a81af13370d4ed152b24c0a82b7028585 x -F autoconf/tea/Makefile.in 5c3b0bdfb66c20d55ebff59d1718864461570ca9 +F autoconf/tea/Makefile.in d55bcc63832caf0309c2ff80358756116618cfca F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 -F autoconf/tea/configure.in e0466b881b53f31f5a4a69e7a91ad130902fb359 +F autoconf/tea/configure.in 93d43c79e936fb16556e22498177d7e8571efa04 F autoconf/tea/doc/sqlite3.n e1fe45d4f5286ee3d0ccc877aca2a0def488e9bb F autoconf/tea/license.terms 13bd403c9610fd2b76ece0ab50c4c5eda933d523 F autoconf/tea/pkgIndex.tcl.in 3ef61715cf1c7bdcff56947ffadb26bc991ca39d F autoconf/tea/tclconfig/install-sh bdd5e293591621ae60d9824d86a4b1c5f22c3d00 -F autoconf/tea/tclconfig/tcl.m4 f035b86539a5ab30689e997a11ae9e7fd2e65570 +F autoconf/tea/tclconfig/tcl.m4 66ddf0a5d5e4b1d29bff472c0985fd7fa89d0fb5 F autoconf/tea/win/makefile.vc f89d0184d0eee5f7e356ea407964dcd139939928 F autoconf/tea/win/nmakehlp.c 2070e086f39866b353a482d3a14dedaf26196506 F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 @@ -231,7 +231,7 @@ F src/sqliteInt.h 641f8fbb65ca2084c8df95b525f6f82c7a1e91ae F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e -F src/tclsqlite.c e87c99e28a145943666b51b212dacae35fcea0bd +F src/tclsqlite.c 7d100e2e7aad614bb3d7026a41a0e3827dbaaebc F src/test1.c 14409a611e9c27c6c522c610bbff5561f05c1558 F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c @@ -1148,7 +1148,7 @@ F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c 3ff0fec22f92dfb54e62eeb48772eddffdbeb0d6 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 -F tool/mkautoconfamal.sh f8d8dbf7d62f409ebed5134998bf5b51d7266383 +F tool/mkautoconfamal.sh 5dc5010e2e748a9e1bba67baca5956a2c2deda7b F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 78a77b2c554d534c6f2dc903130186ed15715460 @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 28a379fcd43389ad3249eff51a621d0bb7c81640 -R ef518fe403795d3b06bbe754ecf5c125 -U drh -Z e00f86954fa90c49bf5a476ef91fbb0c +P 11a70e1ae7f05d06e4e09c9d20db0444b8881584 +R aa6c5df3344dab5b287c6351a237958f +U dan +Z b3667514ef51eabff2a360098e935ae4 diff --git a/manifest.uuid b/manifest.uuid index e975bd8d97..a39201275a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -11a70e1ae7f05d06e4e09c9d20db0444b8881584 \ No newline at end of file +f10a6111262ce6ee6984c64fa0e0023642eca27d \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 9b977e54ae..2b98b6aab4 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -2381,7 +2381,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ if( rc==TCL_OK ){ rc = createIncrblobChannel( - interp, pDb, zDb, zTable, zColumn, iRow, isReadonly + interp, pDb, zDb, zTable, zColumn, (sqlite3_int64)iRow, isReadonly ); } #endif diff --git a/tool/mkautoconfamal.sh b/tool/mkautoconfamal.sh index c13f7c999a..4829277234 100644 --- a/tool/mkautoconfamal.sh +++ b/tool/mkautoconfamal.sh @@ -62,7 +62,7 @@ mkdir -p tea/generic echo "#ifdef USE_SYSTEM_SQLITE" > tea/generic/tclsqlite3.c echo "# include " >> tea/generic/tclsqlite3.c echo "#else" >> tea/generic/tclsqlite3.c -echo "#include \"../../sqlite3.c\"" >> tea/generic/tclsqlite3.c +echo "#include \"sqlite3.c\"" >> tea/generic/tclsqlite3.c echo "#endif" >> tea/generic/tclsqlite3.c cat $TOP/src/tclsqlite.c >> tea/generic/tclsqlite3.c From 4b2590e44b422eb0445220624c2438d74d17ed06 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 19 Aug 2014 19:28:00 +0000 Subject: [PATCH 02/16] Improvements to output formatting with the ".trace" command in the command-line shell. FossilOrigin-Name: d09d63c07748839e9b778a769b183bdd614c6c13 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 10 +++++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 963d794593..1735f35740 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\schanges\sto\sdo\swith\sthe\sTcl\stea\sextension\spackage\sautoconf\ssystem. -D 2014-08-19T09:15:41.141 +C Improvements\sto\soutput\sformatting\swith\sthe\s".trace"\scommand\sin\sthe\ncommand-line\sshell. +D 2014-08-19T19:28:00.623 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -223,7 +223,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 0ea356d32a5e884add23d1b9b4e8736681dd5697 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c ea48e891406ccdf748f3eb02893e056d134a0fea -F src/shell.c 41df1103617331e023301d943977f8c06bd1486f +F src/shell.c 728d2226594d356bf4fbdbdfd08538fd78fd06f3 F src/sqlite.h.in ed9d35990c61f0388ca6405706455c4095310553 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 11a70e1ae7f05d06e4e09c9d20db0444b8881584 -R aa6c5df3344dab5b287c6351a237958f -U dan -Z b3667514ef51eabff2a360098e935ae4 +P f10a6111262ce6ee6984c64fa0e0023642eca27d +R 257d241ab9ebe5fc3f4654d7f2e169ae +U drh +Z 211a00cac8127ca939f7e6f32071c25c diff --git a/manifest.uuid b/manifest.uuid index a39201275a..1cf4ead3de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f10a6111262ce6ee6984c64fa0e0023642eca27d \ No newline at end of file +d09d63c07748839e9b778a769b183bdd614c6c13 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 87b335fbb1..68478a19ba 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1899,7 +1899,11 @@ static FILE *output_file_open(const char *zFile){ */ static void sql_trace_callback(void *pArg, const char *z){ FILE *f = (FILE*)pArg; - if( f ) fprintf(f, "%s\n", z); + if( f ){ + int i = (int)strlen(z); + while( i>0 && z[i-1]==';' ){ i--; } + fprintf(f, "%.*s;\n", i, z); + } } /* @@ -2511,7 +2515,7 @@ static int do_meta_command(char *zLine, ShellState *p){ " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x" " FROM sqlite_master UNION ALL" " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) " - "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" + "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' " "ORDER BY rowid", callback, &data, &zErrMsg ); @@ -3065,7 +3069,7 @@ static int do_meta_command(char *zLine, ShellState *p){ " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x" " FROM sqlite_master UNION ALL" " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) " - "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" + "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' " "ORDER BY rowid", callback, &data, &zErrMsg ); From 2c7946a485b6e19072506e40203af4cc10b0848d Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 19 Aug 2014 20:27:40 +0000 Subject: [PATCH 03/16] Make sure the sqlite3_trace() callback is invoked, even if the prepared statement was marked "expired" before it ever entered sqlite3_step(). Ticket [11d5aa455e0d98f3c1e6a08]. FossilOrigin-Name: 0d4d3df4bc5e75ce1543b5539a1e9e279d2a062f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeapi.c | 8 +++++--- test/trace.test | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 1735f35740..c307f54e8f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\soutput\sformatting\swith\sthe\s".trace"\scommand\sin\sthe\ncommand-line\sshell. -D 2014-08-19T19:28:00.623 +C Make\ssure\sthe\ssqlite3_trace()\scallback\sis\sinvoked,\seven\sif\sthe\sprepared\nstatement\swas\smarked\s"expired"\sbefore\sit\sever\sentered\ssqlite3_step().\nTicket\s[11d5aa455e0d98f3c1e6a08]. +D 2014-08-19T20:27:40.455 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -286,7 +286,7 @@ F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c f7f4066e4d6e3858878d76ce9288ea603e12ddf6 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 F src/vdbeInt.h f5513f2b5ac1e2c5128996c7ea23add256a301df -F src/vdbeapi.c 24e40422382beb774daab11fe9fe9d37e8a04949 +F src/vdbeapi.c ce75e452dfd9c6ba4f8c6c76be6399c88bce3142 F src/vdbeaux.c 25d62ef82cf1be2a1255eacac636fa0d943d8b3d F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac F src/vdbemem.c d90a1e8acf8b63dc9d14cbbea12bfec6cec31394 @@ -1017,7 +1017,7 @@ F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/tpch01.test 04adbf8d8300fa60a222f28d901abd76e7be6dd4 -F test/trace.test 4b36a41a3e9c7842151af6da5998f5080cdad9e5 +F test/trace.test 73a5508100f7fccfbc3f8018d5f6963ed478eea0 F test/trace2.test 93b47ca6996c66b47f57224cfb146f34e07df382 F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6 F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76 @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f10a6111262ce6ee6984c64fa0e0023642eca27d -R 257d241ab9ebe5fc3f4654d7f2e169ae +P d09d63c07748839e9b778a769b183bdd614c6c13 +R dc4a84c1e3dbc4c500aead2f870904cc U drh -Z 211a00cac8127ca939f7e6f32071c25c +Z 8ee9013dcfb943fe42c807d90f81accd diff --git a/manifest.uuid b/manifest.uuid index 1cf4ead3de..b804f56674 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d09d63c07748839e9b778a769b183bdd614c6c13 \ No newline at end of file +0d4d3df4bc5e75ce1543b5539a1e9e279d2a062f \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 5e5bb81366..568f67296c 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -513,10 +513,12 @@ int sqlite3_step(sqlite3_stmt *pStmt){ sqlite3_mutex_enter(db->mutex); v->doingRerun = 0; while( (rc = sqlite3Step(v))==SQLITE_SCHEMA - && cnt++ < SQLITE_MAX_SCHEMA_RETRY - && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){ + && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){ + int savedPc = v->pc; + rc2 = rc = sqlite3Reprepare(v); + if( rc!=SQLITE_OK) break; sqlite3_reset(pStmt); - v->doingRerun = 1; + v->doingRerun = savedPc>=0; assert( v->expired==0 ); } if( rc2!=SQLITE_OK ){ diff --git a/test/trace.test b/test/trace.test index ce5a2d712a..a64cc333fa 100644 --- a/test/trace.test +++ b/test/trace.test @@ -48,6 +48,22 @@ do_test trace-1.5 { db trace {} db trace } {} +do_test trace-1.6 { + db eval { + CREATE TABLE t1b(x TEXT PRIMARY KEY, y); + INSERT INTO t1b VALUES('abc','def'),('ghi','jkl'),('mno','pqr'); + } + set ::stmtlist {} + set xyzzy a* + db trace trace_proc + db eval { + SELECT y FROM t1b WHERE x GLOB $xyzzy + } +} {def} +do_test trace-1.7 { + set ::stmtlist +} {{SELECT y FROM t1b WHERE x GLOB 'a*'}} +db trace {} # If we prepare a statement and execute it multiple times, the trace # happens on each execution. From 5f58ae75c91e1ec56f41e0d465224a6625152f24 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 19 Aug 2014 20:41:36 +0000 Subject: [PATCH 04/16] A better fix for the sqlite3_trace() problem. Ticket [11d5aa455e0d98f3c1e6a] FossilOrigin-Name: 44d5bd4cc3f76e9a151ba0abae1092bd184af264 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeapi.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c307f54e8f..d226fa4f96 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\ssqlite3_trace()\scallback\sis\sinvoked,\seven\sif\sthe\sprepared\nstatement\swas\smarked\s"expired"\sbefore\sit\sever\sentered\ssqlite3_step().\nTicket\s[11d5aa455e0d98f3c1e6a08]. -D 2014-08-19T20:27:40.455 +C A\sbetter\sfix\sfor\sthe\ssqlite3_trace()\sproblem.\nTicket\s[11d5aa455e0d98f3c1e6a] +D 2014-08-19T20:41:36.374 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -286,7 +286,7 @@ F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c f7f4066e4d6e3858878d76ce9288ea603e12ddf6 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8 F src/vdbeInt.h f5513f2b5ac1e2c5128996c7ea23add256a301df -F src/vdbeapi.c ce75e452dfd9c6ba4f8c6c76be6399c88bce3142 +F src/vdbeapi.c 7858d7e7cd23267d3fbca18e3a28cce8e0d162a8 F src/vdbeaux.c 25d62ef82cf1be2a1255eacac636fa0d943d8b3d F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac F src/vdbemem.c d90a1e8acf8b63dc9d14cbbea12bfec6cec31394 @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d09d63c07748839e9b778a769b183bdd614c6c13 -R dc4a84c1e3dbc4c500aead2f870904cc +P 0d4d3df4bc5e75ce1543b5539a1e9e279d2a062f +R 3e9fe87a97e756aac5d53e0b321cfb1c U drh -Z 8ee9013dcfb943fe42c807d90f81accd +Z dae8e8935ea979fe699fbe5ad58485b9 diff --git a/manifest.uuid b/manifest.uuid index b804f56674..270766200f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0d4d3df4bc5e75ce1543b5539a1e9e279d2a062f \ No newline at end of file +44d5bd4cc3f76e9a151ba0abae1092bd184af264 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 568f67296c..f6cc2d8c05 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -518,7 +518,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){ rc2 = rc = sqlite3Reprepare(v); if( rc!=SQLITE_OK) break; sqlite3_reset(pStmt); - v->doingRerun = savedPc>=0; + if( savedPc>=0 ) v->doingRerun = 1; assert( v->expired==0 ); } if( rc2!=SQLITE_OK ){ From dfd1547b482f8f3cc75382934575cea4c624f005 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 19 Aug 2014 23:04:49 +0000 Subject: [PATCH 05/16] Modify the memsubsys1-3.1.4 test so that it does not fail arbitrarily due to variations in the behavior of system malloc(). FossilOrigin-Name: d280157da0b5275f3e3c875d2dcfb9998d374ac0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/memsubsys1.test | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d226fa4f96..c6aee7c716 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\sbetter\sfix\sfor\sthe\ssqlite3_trace()\sproblem.\nTicket\s[11d5aa455e0d98f3c1e6a] -D 2014-08-19T20:41:36.374 +C Modify\sthe\smemsubsys1-3.1.4\stest\sso\sthat\sit\sdoes\snot\sfail\sarbitrarily\sdue\nto\svariations\sin\sthe\sbehavior\sof\ssystem\smalloc(). +D 2014-08-19T23:04:49.204 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -702,7 +702,7 @@ F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test fcb5297b321b562084fc79d64d5a12a1cd2b639b F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 -F test/memsubsys1.test f97cfd0b30e85c2f1ed16d642e7ac58006be84b2 +F test/memsubsys1.test bf270964ab83bc2da5927960f78304a866fb9a9d F test/memsubsys2.test 3a1c1a9de48e5726faa85108b02459fae8cb9ee9 F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0d4d3df4bc5e75ce1543b5539a1e9e279d2a062f -R 3e9fe87a97e756aac5d53e0b321cfb1c +P 44d5bd4cc3f76e9a151ba0abae1092bd184af264 +R da9b4e10fd35ea0494fda63ca4df66ec U drh -Z dae8e8935ea979fe699fbe5ad58485b9 +Z 375791abd440beaccbf3e162957d1a64 diff --git a/manifest.uuid b/manifest.uuid index 270766200f..a915b839b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -44d5bd4cc3f76e9a151ba0abae1092bd184af264 \ No newline at end of file +d280157da0b5275f3e3c875d2dcfb9998d374ac0 \ No newline at end of file diff --git a/test/memsubsys1.test b/test/memsubsys1.test index 76b79d00f6..8cc7c2afc1 100644 --- a/test/memsubsys1.test +++ b/test/memsubsys1.test @@ -124,7 +124,13 @@ do_test memsubsys1-3.1.3 { } 0 do_test memsubsys1-3.1.4 { set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] -} $max_pagecache + # Note: The measured PAGECACHE_OVERFLOW is amount malloc() returns, not what + # was requested. System malloc() implementations might (arbitrarily) return + # slightly different oversize buffers, which can result in slightly different + # PAGECACHE_OVERFLOW sizes between consecutive runs. So we cannot do an + # exact comparison. Simply verify that the amount is within 5%. + expr {$overflow>=$max_pagecache*0.95 && $overflow<=$max_pagecache*1.05} +} 1 do_test memsubsys1-3.1.5 { set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] } 0 From 75b31dc9adcd78576b8d89064c1d03f2164336ba Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 00:54:46 +0000 Subject: [PATCH 06/16] Minor performance improvement and size reduction for the btree-page space allocator. FossilOrigin-Name: 73637d12e31f5489efe37d8cf4ab50a1911d4c75 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 17 +++++++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index c6aee7c716..91db86833d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Modify\sthe\smemsubsys1-3.1.4\stest\sso\sthat\sit\sdoes\snot\sfail\sarbitrarily\sdue\nto\svariations\sin\sthe\sbehavior\sof\ssystem\smalloc(). -D 2014-08-19T23:04:49.204 +C Minor\sperformance\simprovement\sand\ssize\sreduction\sfor\sthe\sbtree-page\sspace\nallocator. +D 2014-08-20T00:54:46.809 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c fa057e30794bfd867963b44a3a42710a45c335a1 +F src/btree.c c580f3fb3b3d1bf968e5c7e6a0ad48b7b0bd4366 F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 44d5bd4cc3f76e9a151ba0abae1092bd184af264 -R da9b4e10fd35ea0494fda63ca4df66ec +P d280157da0b5275f3e3c875d2dcfb9998d374ac0 +R 020501de111b3b2380806f2152969bc3 U drh -Z 375791abd440beaccbf3e162957d1a64 +Z 17df18c00e8e514c309dda1b0357fb11 diff --git a/manifest.uuid b/manifest.uuid index a915b839b0..0e6072d88f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d280157da0b5275f3e3c875d2dcfb9998d374ac0 \ No newline at end of file +73637d12e31f5489efe37d8cf4ab50a1911d4c75 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 60bc7de41e..2ed304d04b 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1197,7 +1197,6 @@ static int defragmentPage(MemPage *pPage){ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ u8 * const data = pPage->aData; /* Local cache of pPage->aData */ - int nFrag; /* Number of fragmented bytes on pPage */ int top; /* First byte of cell content area */ int gap; /* First byte of gap between cell pointers and cell content */ int rc; /* Integer return code */ @@ -1212,16 +1211,22 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ usableSize = pPage->pBt->usableSize; assert( nByte < usableSize-8 ); - nFrag = data[hdr+7]; assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); gap = pPage->cellOffset + 2*pPage->nCell; - top = get2byteNotZero(&data[hdr+5]); - if( gap>top ) return SQLITE_CORRUPT_BKPT; + assert( gap<=65536 ); + top = get2byte(&data[hdr+5]); + if( gap>top ){ + if( top==0 ){ + top = 65536; + }else{ + return SQLITE_CORRUPT_BKPT; + } + } testcase( gap+2==top ); testcase( gap+1==top ); testcase( gap==top ); - if( nFrag>=60 ){ + if( data[hdr+7]>=60 ){ /* Always defragment highly fragmented pages */ rc = defragmentPage(pPage); if( rc ) return rc; @@ -1246,7 +1251,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ /* Remove the slot from the free-list. Update the number of ** fragmented bytes within the page. */ memcpy(&data[addr], &data[pc], 2); - data[hdr+7] = (u8)(nFrag + x); + data[hdr+7] += (u8)x; }else if( size+pc > usableSize ){ return SQLITE_CORRUPT_BKPT; }else{ From 53d89cdfe98e7c5b07527ff65cffa91798fa3ed9 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 20 Aug 2014 10:42:16 +0000 Subject: [PATCH 07/16] Fix a typo in the showdb usage message. FossilOrigin-Name: 6c66beae97ba1799c908d3a33371dedbc7f3f58c --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/showdb.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 91db86833d..e9f109a9a7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sperformance\simprovement\sand\ssize\sreduction\sfor\sthe\sbtree-page\sspace\nallocator. -D 2014-08-20T00:54:46.809 +C Fix\sa\stypo\sin\sthe\sshowdb\susage\smessage. +D 2014-08-20T10:42:16.102 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1164,7 +1164,7 @@ F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/pagesig.c ff0ca355fd3c2398e933da5e22439bbff89b803b F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/showdb.c b9ee6b6c81a094bf33badbf7e9da34cdbc0cce25 +F tool/showdb.c bd073a78bce714a0e42d92ea474b3eb8cb53be5d F tool/showjournal.c 053eb1cc774710c6890b7dd6293300cc297b16a5 F tool/showstat4.c c39279d6bd37cb999b634f0064f6f86ad7af008f F tool/showwal.c 3209120269cdf9380f091459e47b776b4f81dfd3 @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d280157da0b5275f3e3c875d2dcfb9998d374ac0 -R 020501de111b3b2380806f2152969bc3 -U drh -Z 17df18c00e8e514c309dda1b0357fb11 +P 73637d12e31f5489efe37d8cf4ab50a1911d4c75 +R d268dbd0231a0e3f9784dd51ed74231a +U dan +Z b16b223d7974024b463d42100aaa47bd diff --git a/manifest.uuid b/manifest.uuid index 0e6072d88f..45aa98f21f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -73637d12e31f5489efe37d8cf4ab50a1911d4c75 \ No newline at end of file +6c66beae97ba1799c908d3a33371dedbc7f3f58c \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index 1a51e9d1a2..82b8c9f14f 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -957,7 +957,7 @@ static void usage(const char *argv0){ " NNNbdCCC Decode cell CCC on btree page NNN\n" " NNNt Decode freelist trunk page NNN\n" " NNNtd Show leaf freelist pages on the decode\n" - " NNNtr Recurisvely decode freelist starting at NNN\n" + " NNNtr Recursively decode freelist starting at NNN\n" ); } From 4c04f3c8bd1edb345186ae80d8539a684d676d74 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 11:56:14 +0000 Subject: [PATCH 08/16] Further size reduction and performance improvement in btree.c:allocateSpace(). FossilOrigin-Name: 1cb1cd64930a6bc371143f7d2e77eb1c51498cb0 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 24 +++++++++++------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index e9f109a9a7..6883385671 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sthe\sshowdb\susage\smessage. -D 2014-08-20T10:42:16.102 +C Further\ssize\sreduction\sand\sperformance\simprovement\sin\sbtree.c:allocateSpace(). +D 2014-08-20T11:56:14.338 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c c580f3fb3b3d1bf968e5c7e6a0ad48b7b0bd4366 +F src/btree.c 398ecbdb4a19230940955c10b4f35de958e9a05c F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 73637d12e31f5489efe37d8cf4ab50a1911d4c75 -R d268dbd0231a0e3f9784dd51ed74231a -U dan -Z b16b223d7974024b463d42100aaa47bd +P 6c66beae97ba1799c908d3a33371dedbc7f3f58c +R 28706ecaca72a1e3574ba7b8d51854c6 +U drh +Z ca9532aeb7742cb91c75177cb9ee4fbc diff --git a/manifest.uuid b/manifest.uuid index 45aa98f21f..d1bf93d7a5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c66beae97ba1799c908d3a33371dedbc7f3f58c \ No newline at end of file +1cb1cd64930a6bc371143f7d2e77eb1c51498cb0 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 2ed304d04b..61848dcb83 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1222,20 +1222,15 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ return SQLITE_CORRUPT_BKPT; } } + + /* If there is enough space between gap and top for one more cell pointer + ** array entry offset, and if the freelist is not empty, then search the + ** freelist looking for a free slot big enough to satisfy the request. + */ testcase( gap+2==top ); testcase( gap+1==top ); testcase( gap==top ); - - if( data[hdr+7]>=60 ){ - /* Always defragment highly fragmented pages */ - rc = defragmentPage(pPage); - if( rc ) return rc; - top = get2byteNotZero(&data[hdr+5]); - }else if( gap+2<=top ){ - /* Search the freelist looking for a free slot big enough to satisfy - ** the request. The allocation is made from the first free slot in - ** the list that is large enough to accommodate it. - */ + if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){ int pc, addr; for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){ int size; /* Size of the free slot */ @@ -1248,6 +1243,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ testcase( x==4 ); testcase( x==3 ); if( x<4 ){ + if( data[hdr+7]>=60 ) goto defragment_page; /* Remove the slot from the free-list. Update the number of ** fragmented bytes within the page. */ memcpy(&data[addr], &data[pc], 2); @@ -1265,11 +1261,13 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ } } - /* Check to make sure there is enough space in the gap to satisfy - ** the allocation. If not, defragment. + /* The request could not be fulfilled using a freelist slot. Check + ** to see if defragmentation is necessary. */ testcase( gap+2+nByte==top ); if( gap+2+nByte>top ){ +defragment_page: + assert( pPage->nCell>0 ); rc = defragmentPage(pPage); if( rc ) return rc; top = get2byteNotZero(&data[hdr+5]); From 905552628c4812e47ab9172911650ef5e4778e64 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 13:17:43 +0000 Subject: [PATCH 09/16] Change an assert() added by the previous commit into a testcase(). Fix a separate assert() in btree.c:freeSpace(). FossilOrigin-Name: fe51d3aa0ce7021213293a0647e31164073e78f7 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6883385671..7a156440dc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\ssize\sreduction\sand\sperformance\simprovement\sin\sbtree.c:allocateSpace(). -D 2014-08-20T11:56:14.338 +C Change\san\sassert()\sadded\sby\sthe\sprevious\scommit\sinto\sa\stestcase().\nFix\sa\sseparate\sassert()\sin\sbtree.c:freeSpace(). +D 2014-08-20T13:17:43.884 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 398ecbdb4a19230940955c10b4f35de958e9a05c +F src/btree.c 53eb576f72093d5138f5b7468994121c6eb6fe98 F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6c66beae97ba1799c908d3a33371dedbc7f3f58c -R 28706ecaca72a1e3574ba7b8d51854c6 +P 1cb1cd64930a6bc371143f7d2e77eb1c51498cb0 +R 2da2148faf73b1d43a764ae813ef9e60 U drh -Z ca9532aeb7742cb91c75177cb9ee4fbc +Z 36b8d62cf946d2fc64ee098831079eb8 diff --git a/manifest.uuid b/manifest.uuid index d1bf93d7a5..4a04c24fb1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1cb1cd64930a6bc371143f7d2e77eb1c51498cb0 \ No newline at end of file +fe51d3aa0ce7021213293a0647e31164073e78f7 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 61848dcb83..a09b82fe5e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1267,7 +1267,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ testcase( gap+2+nByte==top ); if( gap+2+nByte>top ){ defragment_page: - assert( pPage->nCell>0 ); + testcase( pPage->nCell==0 ); rc = defragmentPage(pPage); if( rc ) return rc; top = get2byteNotZero(&data[hdr+5]); @@ -1306,7 +1306,7 @@ static int freeSpace(MemPage *pPage, int start, int size){ assert( start>=pPage->hdrOffset+6+pPage->childPtrSize ); assert( (start + size) <= (int)pPage->pBt->usableSize ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); - assert( size>=0 ); /* Minimum cell size is 4 */ + assert( size>=4 ); /* Minimum cell size is 4 */ if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){ /* Overwrite deleted information with zeros when the secure_delete From fb90841adf94e9edbfa02d4506a26d2a05da11e9 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 13:25:06 +0000 Subject: [PATCH 10/16] Add SQLITE_API macros in front of interface routines in the test_intarray.c extension. FossilOrigin-Name: eea0661798e10018615854c871f24be0f8bb2ff9 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/test_intarray.c | 4 ++-- src/test_intarray.h | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index e9f109a9a7..bee5fb1b55 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sthe\sshowdb\susage\smessage. -D 2014-08-20T10:42:16.102 +C Add\sSQLITE_API\smacros\sin\sfront\sof\sinterface\sroutines\sin\sthe\stest_intarray.c\nextension. +D 2014-08-20T13:25:06.147 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -252,8 +252,8 @@ F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f F src/test_func.c d3013ce36f19ac72a99c73864930fd1fa41832f8 F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd F src/test_init.c 66b33120ffe9cd853b5a905ec850d51151337b32 -F src/test_intarray.c 87847c71c3c36889c0bcc9c4baf9d31881665d61 -F src/test_intarray.h 2ece66438cfd177b78d1bfda7a4180cd3a10844d +F src/test_intarray.c db4614c2262a06abc4409dc048d59c580c38320f +F src/test_intarray.h 9dc57417fb65bc7835cc18548852cc08cc062202 F src/test_journal.c f5c0a05b7b3d5930db769b5ee6c3766dc2221a64 F src/test_loadext.c a5251f956ab6af21e138dc1f9c0399394a510cb4 F src/test_malloc.c 1ff5b1243d96124c9a180f3b89424820a1f337f3 @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 73637d12e31f5489efe37d8cf4ab50a1911d4c75 -R d268dbd0231a0e3f9784dd51ed74231a -U dan -Z b16b223d7974024b463d42100aaa47bd +P 6c66beae97ba1799c908d3a33371dedbc7f3f58c +R 0e361fd9748a232cee30a1097c2f8f6b +U drh +Z c85b6dec89d4d1dc359d8501fa41031d diff --git a/manifest.uuid b/manifest.uuid index 45aa98f21f..bf670ea860 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c66beae97ba1799c908d3a33371dedbc7f3f58c \ No newline at end of file +eea0661798e10018615854c871f24be0f8bb2ff9 \ No newline at end of file diff --git a/src/test_intarray.c b/src/test_intarray.c index f5c3d9e405..efcd21d404 100644 --- a/src/test_intarray.c +++ b/src/test_intarray.c @@ -216,7 +216,7 @@ static sqlite3_module intarrayModule = { ** explicitly by the application, the virtual table will be dropped implicitly ** by the system when the database connection is closed. */ -int sqlite3_intarray_create( +SQLITE_API int sqlite3_intarray_create( sqlite3 *db, const char *zName, sqlite3_intarray **ppReturn @@ -250,7 +250,7 @@ int sqlite3_intarray_create( ** any query against the corresponding virtual table. If the integer ** array does change or is deallocated undefined behavior will result. */ -int sqlite3_intarray_bind( +SQLITE_API int sqlite3_intarray_bind( sqlite3_intarray *pIntArray, /* The intarray object to bind to */ int nElements, /* Number of elements in the intarray */ sqlite3_int64 *aElements, /* Content of the intarray */ diff --git a/src/test_intarray.h b/src/test_intarray.h index 6d26235a87..84b1f3fe66 100644 --- a/src/test_intarray.h +++ b/src/test_intarray.h @@ -102,7 +102,7 @@ typedef struct sqlite3_intarray sqlite3_intarray; ** explicitly by the application, the virtual table will be dropped implicitly ** by the system when the database connection is closed. */ -int sqlite3_intarray_create( +SQLITE_API int sqlite3_intarray_create( sqlite3 *db, const char *zName, sqlite3_intarray **ppReturn @@ -115,7 +115,7 @@ int sqlite3_intarray_create( ** any query against the corresponding virtual table. If the integer ** array does change or is deallocated undefined behavior will result. */ -int sqlite3_intarray_bind( +SQLITE_API int sqlite3_intarray_bind( sqlite3_intarray *pIntArray, /* The intarray object to bind to */ int nElements, /* Number of elements in the intarray */ sqlite3_int64 *aElements, /* Content of the intarray */ From 7fb91646b56fb33bad80abd34a8d34938fb461c5 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 14:37:09 +0000 Subject: [PATCH 11/16] Refactor local variable names in the freeSpace() routine of btree.c for improved understandability. FossilOrigin-Name: 7e63089a191f29aefde05e89bb612f3036cfa034 --- manifest | 13 ++++---- manifest.uuid | 2 +- src/btree.c | 85 +++++++++++++++++++++++++++------------------------ 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/manifest b/manifest index c03b96d1a8..c1cbe5415f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Size\sreduction\sand\sperformance\simprovements\sin\sbtree.c\sand\sthe\nallocateSpace()\sroutine.\s\sAlso\sfix\san\sassert()\sin\sfreeSpace(). -D 2014-08-20T13:35:45.034 +C Refactor\slocal\svariable\snames\sin\sthe\sfreeSpace()\sroutine\sof\sbtree.c\sfor\nimproved\sunderstandability. +D 2014-08-20T14:37:09.167 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 53eb576f72093d5138f5b7468994121c6eb6fe98 +F src/btree.c c1235eacb8d4de12850daccb1636763218da3381 F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b @@ -1186,8 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P eea0661798e10018615854c871f24be0f8bb2ff9 fe51d3aa0ce7021213293a0647e31164073e78f7 -R 3c51b363f531f6f6895a1e7e29ea4492 -T +closed fe51d3aa0ce7021213293a0647e31164073e78f7 +P 121308fa869ad490a6924798d276c0ff32759acc +R 332118792b6ef82f7eceb02b0d545622 U drh -Z 25da1aeccb4d6e0fa0390c2ee1a22b6e +Z accc32db7c4714707b5e7cc22312c49c diff --git a/manifest.uuid b/manifest.uuid index aa49654c6a..1b60255c36 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -121308fa869ad490a6924798d276c0ff32759acc \ No newline at end of file +7e63089a191f29aefde05e89bb612f3036cfa034 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a09b82fe5e..ac13b0f3da 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1290,28 +1290,30 @@ defragment_page: /* ** Return a section of the pPage->aData to the freelist. -** The first byte of the new free block is pPage->aDisk[start] -** and the size of the block is "size" bytes. +** The first byte of the new free block is pPage->aData[iStart] +** and the size of the block is iSize bytes. ** ** Most of the effort here is involved in coalesing adjacent ** free blocks into a single big free block. */ -static int freeSpace(MemPage *pPage, int start, int size){ - int addr, pbegin, hdr; - int iLast; /* Largest possible freeblock offset */ - unsigned char *data = pPage->aData; +static int freeSpace(MemPage *pPage, int iStart, int iSize){ + int iPtr; /* Address of pointer to next freeblock */ + int iFreeBlk; /* Address of the next freeblock */ + int hdr; /* Page header size. 0 or 100 */ + int iLast; /* Largest possible freeblock offset */ + unsigned char *data = pPage->aData; /* Page content */ assert( pPage->pBt!=0 ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); - assert( start>=pPage->hdrOffset+6+pPage->childPtrSize ); - assert( (start + size) <= (int)pPage->pBt->usableSize ); + assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); + assert( (iStart + iSize) <= (int)pPage->pBt->usableSize ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); - assert( size>=4 ); /* Minimum cell size is 4 */ + assert( iSize>=4 ); /* Minimum cell size is 4 */ if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){ /* Overwrite deleted information with zeros when the secure_delete ** option is enabled */ - memset(&data[start], 0, size); + memset(&data[iStart], 0, iSize); } /* Add the space back into the linked list of freeblocks. Note that @@ -1324,53 +1326,56 @@ static int freeSpace(MemPage *pPage, int start, int size){ ** the freelist. */ hdr = pPage->hdrOffset; - addr = hdr + 1; + iPtr = hdr + 1; iLast = pPage->pBt->usableSize - 4; - assert( start<=iLast ); - while( (pbegin = get2byte(&data[addr]))0 ){ - if( pbegin0 ){ + if( iFreeBlkiLast ){ + if( iFreeBlk>iLast ){ return SQLITE_CORRUPT_BKPT; } - assert( pbegin>addr || pbegin==0 ); - put2byte(&data[addr], start); - put2byte(&data[start], pbegin); - put2byte(&data[start+2], size); - pPage->nFree = pPage->nFree + (u16)size; + assert( iFreeBlk>iPtr || iFreeBlk==0 ); + put2byte(&data[iPtr], iStart); + put2byte(&data[iStart], iFreeBlk); + put2byte(&data[iStart+2], iSize); + pPage->nFree = pPage->nFree + (u16)iSize; /* Coalesce adjacent free blocks */ - addr = hdr + 1; - while( (pbegin = get2byte(&data[addr]))>0 ){ - int pnext, psize, x; - assert( pbegin>addr ); - assert( pbegin <= (int)pPage->pBt->usableSize-4 ); - pnext = get2byte(&data[pbegin]); - psize = get2byte(&data[pbegin+2]); - if( pbegin + psize + 3 >= pnext && pnext>0 ){ - int frag = pnext - (pbegin+psize); - if( (frag<0) || (frag>(int)data[hdr+7]) ){ + iPtr = hdr + 1; + while( (iFreeBlk = get2byte(&data[iPtr]))>0 ){ + int iNextBlk; /* Next freeblock after iFreeBlk */ + int szFreeBlk; /* Size of iFreeBlk */ + assert( iFreeBlk>iPtr ); + assert( iFreeBlk <= (int)pPage->pBt->usableSize-4 ); + iNextBlk = get2byte(&data[iFreeBlk]); + szFreeBlk = get2byte(&data[iFreeBlk+2]); + if( iFreeBlk + szFreeBlk + 3 >= iNextBlk && iNextBlk>0 ){ + int nFrag; /* Fragment bytes in between iFreeBlk and iNextBlk */ + int x; /* Temp value */ + nFrag = iNextBlk - (iFreeBlk+szFreeBlk); + if( (nFrag<0) || (nFrag>(int)data[hdr+7]) ){ return SQLITE_CORRUPT_BKPT; } - data[hdr+7] -= (u8)frag; - x = get2byte(&data[pnext]); - put2byte(&data[pbegin], x); - x = pnext + get2byte(&data[pnext+2]) - pbegin; - put2byte(&data[pbegin+2], x); + data[hdr+7] -= (u8)nFrag; + x = get2byte(&data[iNextBlk]); + put2byte(&data[iFreeBlk], x); + x = iNextBlk + get2byte(&data[iNextBlk+2]) - iFreeBlk; + put2byte(&data[iFreeBlk+2], x); }else{ - addr = pbegin; + iPtr = iFreeBlk; } } /* If the cell content area begins with a freeblock, remove it. */ if( data[hdr+1]==data[hdr+5] && data[hdr+2]==data[hdr+6] ){ int top; - pbegin = get2byte(&data[hdr+1]); - memcpy(&data[hdr+1], &data[pbegin], 2); - top = get2byte(&data[hdr+5]) + get2byte(&data[pbegin+2]); + iFreeBlk = get2byte(&data[hdr+1]); + memcpy(&data[hdr+1], &data[iFreeBlk], 2); + top = get2byte(&data[hdr+5]) + get2byte(&data[iFreeBlk+2]); put2byte(&data[hdr+5], top); } assert( sqlite3PagerIswriteable(pPage->pDbPage) ); From 5f5c753efbbe23df1e52a0560c2b7abbc0f3c334 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 17:56:27 +0000 Subject: [PATCH 12/16] Reimplement the freeSpace() routine in btree.c so that it runs faster. FossilOrigin-Name: fe4fd014b42b7b158ca968f1535b5636c67769f6 --- manifest | 12 ++--- manifest.uuid | 2 +- src/btree.c | 125 +++++++++++++++++++++++++------------------------- 3 files changed, 70 insertions(+), 69 deletions(-) diff --git a/manifest b/manifest index c1cbe5415f..4fe8e5ec20 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Refactor\slocal\svariable\snames\sin\sthe\sfreeSpace()\sroutine\sof\sbtree.c\sfor\nimproved\sunderstandability. -D 2014-08-20T14:37:09.167 +C Reimplement\sthe\sfreeSpace()\sroutine\sin\sbtree.c\sso\sthat\sit\sruns\sfaster. +D 2014-08-20T17:56:27.585 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c c1235eacb8d4de12850daccb1636763218da3381 +F src/btree.c fe2d11c8c0d99e324614141ad012b37d0601cf59 F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 121308fa869ad490a6924798d276c0ff32759acc -R 332118792b6ef82f7eceb02b0d545622 +P 7e63089a191f29aefde05e89bb612f3036cfa034 +R cbff1ae81d05ca3b78b420deaaa6083f U drh -Z accc32db7c4714707b5e7cc22312c49c +Z d684bbbc1bfe7cdee532398c2232ddf8 diff --git a/manifest.uuid b/manifest.uuid index 1b60255c36..238682a66d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e63089a191f29aefde05e89bb612f3036cfa034 \ No newline at end of file +fe4fd014b42b7b158ca968f1535b5636c67769f6 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ac13b0f3da..c10e2f1c32 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1293,92 +1293,93 @@ defragment_page: ** The first byte of the new free block is pPage->aData[iStart] ** and the size of the block is iSize bytes. ** -** Most of the effort here is involved in coalesing adjacent -** free blocks into a single big free block. +** Adjacent freeblocks are coalesced. +** +** Note that even though the freeblock list was checked by btreeInitPage(), +** that routine will not detect overlap between cells or freeblocks. Nor +** does it detect cells or freeblocks that encrouch into the reserved bytes +** at the end of the page. So do additional corruption checks inside this +** routine and return SQLITE_CORRUPT if any problems are found. */ -static int freeSpace(MemPage *pPage, int iStart, int iSize){ - int iPtr; /* Address of pointer to next freeblock */ - int iFreeBlk; /* Address of the next freeblock */ - int hdr; /* Page header size. 0 or 100 */ - int iLast; /* Largest possible freeblock offset */ +static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ + u16 iPtr; /* Address of pointer to next freeblock */ + u16 iFreeBlk; /* Address of the next freeblock */ + u8 hdr; /* Page header size. 0 or 100 */ + u8 nFrag = 0; /* Reduction in fragmentation */ + u16 iOrigSize = iSize; /* Original value of iSize */ + u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */ + u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ unsigned char *data = pPage->aData; /* Page content */ assert( pPage->pBt!=0 ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); - assert( (iStart + iSize) <= (int)pPage->pBt->usableSize ); + assert( iEnd <= pPage->pBt->usableSize ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( iSize>=4 ); /* Minimum cell size is 4 */ + assert( iStart<=iLast ); + /* Overwrite deleted information with zeros when the secure_delete + ** option is enabled */ if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){ - /* Overwrite deleted information with zeros when the secure_delete - ** option is enabled */ memset(&data[iStart], 0, iSize); } - /* Add the space back into the linked list of freeblocks. Note that - ** even though the freeblock list was checked by btreeInitPage(), - ** btreeInitPage() did not detect overlapping cells or - ** freeblocks that overlapped cells. Nor does it detect when the - ** cell content area exceeds the value in the page header. If these - ** situations arise, then subsequent insert operations might corrupt - ** the freelist. So we do need to check for corruption while scanning - ** the freelist. + /* The list of freeblocks must be in ascending order. Find the + ** spot on the list where iStart should be inserted. */ hdr = pPage->hdrOffset; iPtr = hdr + 1; - iLast = pPage->pBt->usableSize - 4; - assert( iStart<=iLast ); - while( (iFreeBlk = get2byte(&data[iPtr]))0 ){ - if( iFreeBlk0 && iFreeBlkiLast ){ - return SQLITE_CORRUPT_BKPT; - } + if( iFreeBlk>iLast ) return SQLITE_CORRUPT_BKPT; assert( iFreeBlk>iPtr || iFreeBlk==0 ); - put2byte(&data[iPtr], iStart); - put2byte(&data[iStart], iFreeBlk); - put2byte(&data[iStart+2], iSize); - pPage->nFree = pPage->nFree + (u16)iSize; - /* Coalesce adjacent free blocks */ - iPtr = hdr + 1; - while( (iFreeBlk = get2byte(&data[iPtr]))>0 ){ - int iNextBlk; /* Next freeblock after iFreeBlk */ - int szFreeBlk; /* Size of iFreeBlk */ - assert( iFreeBlk>iPtr ); - assert( iFreeBlk <= (int)pPage->pBt->usableSize-4 ); - iNextBlk = get2byte(&data[iFreeBlk]); - szFreeBlk = get2byte(&data[iFreeBlk+2]); - if( iFreeBlk + szFreeBlk + 3 >= iNextBlk && iNextBlk>0 ){ - int nFrag; /* Fragment bytes in between iFreeBlk and iNextBlk */ - int x; /* Temp value */ - nFrag = iNextBlk - (iFreeBlk+szFreeBlk); - if( (nFrag<0) || (nFrag>(int)data[hdr+7]) ){ - return SQLITE_CORRUPT_BKPT; - } - data[hdr+7] -= (u8)nFrag; - x = get2byte(&data[iNextBlk]); - put2byte(&data[iFreeBlk], x); - x = iNextBlk + get2byte(&data[iNextBlk+2]) - iFreeBlk; - put2byte(&data[iFreeBlk+2], x); - }else{ - iPtr = iFreeBlk; + /* At this point: + ** iFreeBlk: First freeblock after iStart, or zero if none + ** iPtr: The address of a pointer iFreeBlk + ** + ** Check to see if iFreeBlk should be coalesced onto the end of iStart. + */ + if( iFreeBlk && iEnd+3>=iFreeBlk ){ + nFrag = iFreeBlk - iEnd; + if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_BKPT; + iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); + iSize = iEnd - iStart; + iFreeBlk = get2byte(&data[iFreeBlk]); + } + + /* If iPtr is another freeblock (that is, if iPtr is not the freelist pointer + ** in the page header) then check to see if iStart should be coalesced + ** onto the end of iPtr. + */ + if( iPtr>hdr+1 ){ + int iPtrEnd = iPtr + get2byte(&data[iPtr+2]); + if( iPtrEnd+3>=iStart ){ + if( iPtrEnd>iStart ) return SQLITE_CORRUPT_BKPT; + nFrag += iStart - iPtrEnd; + iSize = iEnd - iPtr; + iStart = iPtr; } } + if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_BKPT; - /* If the cell content area begins with a freeblock, remove it. */ - if( data[hdr+1]==data[hdr+5] && data[hdr+2]==data[hdr+6] ){ - int top; - iFreeBlk = get2byte(&data[hdr+1]); - memcpy(&data[hdr+1], &data[iFreeBlk], 2); - top = get2byte(&data[hdr+5]) + get2byte(&data[iFreeBlk+2]); - put2byte(&data[hdr+5], top); + data[hdr+7] -= nFrag; + if( iPtr==hdr+1 && iStart==get2byte(&data[hdr+5]) ){ + /* The new freeblock is at the beginning of the cell content area, + ** so just extend the cell content area rather than create another + ** freelist entry */ + put2byte(&data[hdr+1], iFreeBlk); + put2byte(&data[hdr+5], iEnd); + }else{ + /* Insert the new freeblock into the freelist */ + put2byte(&data[iPtr], iStart); + put2byte(&data[iStart], iFreeBlk); + put2byte(&data[iStart+2], iSize); } - assert( sqlite3PagerIswriteable(pPage->pDbPage) ); + pPage->nFree += iOrigSize; return SQLITE_OK; } From 7bc4c454dab1568702db8ef230c624edc35ed815 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 18:43:44 +0000 Subject: [PATCH 13/16] A small performance improvement in freeSpace() by special-casing the relatively common case of an empty freelist. FossilOrigin-Name: 49f44d355ff70744e4951baca2481c7c2b6c02b3 --- manifest | 12 ++++---- manifest.uuid | 2 +- src/btree.c | 76 +++++++++++++++++++++++++++------------------------ 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/manifest b/manifest index 4fe8e5ec20..0e55755198 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reimplement\sthe\sfreeSpace()\sroutine\sin\sbtree.c\sso\sthat\sit\sruns\sfaster. -D 2014-08-20T17:56:27.585 +C A\ssmall\sperformance\simprovement\sin\sfreeSpace()\sby\sspecial-casing\sthe\nrelatively\scommon\scase\sof\san\sempty\sfreelist. +D 2014-08-20T18:43:44.510 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c fe2d11c8c0d99e324614141ad012b37d0601cf59 +F src/btree.c 4195fed5741b4dbcc9831b623aec487258f3e62d F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b @@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7e63089a191f29aefde05e89bb612f3036cfa034 -R cbff1ae81d05ca3b78b420deaaa6083f +P fe4fd014b42b7b158ca968f1535b5636c67769f6 +R 865eceb09aea170bb70d44b771b85e6e U drh -Z d684bbbc1bfe7cdee532398c2232ddf8 +Z 0631afdcc5729e41fc50a75336710200 diff --git a/manifest.uuid b/manifest.uuid index 238682a66d..2bb2527d30 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe4fd014b42b7b158ca968f1535b5636c67769f6 \ No newline at end of file +49f44d355ff70744e4951baca2481c7c2b6c02b3 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index c10e2f1c32..56718b69d6 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1330,47 +1330,51 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ */ hdr = pPage->hdrOffset; iPtr = hdr + 1; - while( (iFreeBlk = get2byte(&data[iPtr]))>0 && iFreeBlkiLast ) return SQLITE_CORRUPT_BKPT; - assert( iFreeBlk>iPtr || iFreeBlk==0 ); - - /* At this point: - ** iFreeBlk: First freeblock after iStart, or zero if none - ** iPtr: The address of a pointer iFreeBlk - ** - ** Check to see if iFreeBlk should be coalesced onto the end of iStart. - */ - if( iFreeBlk && iEnd+3>=iFreeBlk ){ - nFrag = iFreeBlk - iEnd; - if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_BKPT; - iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); - iSize = iEnd - iStart; - iFreeBlk = get2byte(&data[iFreeBlk]); - } - - /* If iPtr is another freeblock (that is, if iPtr is not the freelist pointer - ** in the page header) then check to see if iStart should be coalesced - ** onto the end of iPtr. - */ - if( iPtr>hdr+1 ){ - int iPtrEnd = iPtr + get2byte(&data[iPtr+2]); - if( iPtrEnd+3>=iStart ){ - if( iPtrEnd>iStart ) return SQLITE_CORRUPT_BKPT; - nFrag += iStart - iPtrEnd; - iSize = iEnd - iPtr; - iStart = iPtr; + if( data[iPtr+1]==0 && data[iPtr]==0 ){ + iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */ + }else{ + while( (iFreeBlk = get2byte(&data[iPtr]))>0 && iFreeBlkiLast ) return SQLITE_CORRUPT_BKPT; + assert( iFreeBlk>iPtr || iFreeBlk==0 ); + + /* At this point: + ** iFreeBlk: First freeblock after iStart, or zero if none + ** iPtr: The address of a pointer iFreeBlk + ** + ** Check to see if iFreeBlk should be coalesced onto the end of iStart. + */ + if( iFreeBlk && iEnd+3>=iFreeBlk ){ + nFrag = iFreeBlk - iEnd; + if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_BKPT; + iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); + iSize = iEnd - iStart; + iFreeBlk = get2byte(&data[iFreeBlk]); + } + + /* If iPtr is another freeblock (that is, if iPtr is not the freelist pointer + ** in the page header) then check to see if iStart should be coalesced + ** onto the end of iPtr. + */ + if( iPtr>hdr+1 ){ + int iPtrEnd = iPtr + get2byte(&data[iPtr+2]); + if( iPtrEnd+3>=iStart ){ + if( iPtrEnd>iStart ) return SQLITE_CORRUPT_BKPT; + nFrag += iStart - iPtrEnd; + iSize = iEnd - iPtr; + iStart = iPtr; + } + } + if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_BKPT; + data[hdr+7] -= nFrag; } - if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_BKPT; - - data[hdr+7] -= nFrag; - if( iPtr==hdr+1 && iStart==get2byte(&data[hdr+5]) ){ + if( iStart==get2byte(&data[hdr+5]) ){ /* The new freeblock is at the beginning of the cell content area, ** so just extend the cell content area rather than create another ** freelist entry */ + if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_BKPT; put2byte(&data[hdr+1], iFreeBlk); put2byte(&data[hdr+5], iEnd); }else{ From f3f69ac942f6cbe0f143659399281c162ad1e743 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 23:38:07 +0000 Subject: [PATCH 14/16] Enhancements to skip-scan such that it is operable when a middle column of an index is skipped while the left-most column is constrained in the WHERE clause. FossilOrigin-Name: bc985caa7816f1f873ad8e4467c5278399f315ce --- manifest | 13 ++++---- manifest.uuid | 2 +- src/where.c | 21 +++++++++---- test/skipscan3.test | 73 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 test/skipscan3.test diff --git a/manifest b/manifest index 0e55755198..928130ab8a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\ssmall\sperformance\simprovement\sin\sfreeSpace()\sby\sspecial-casing\sthe\nrelatively\scommon\scase\sof\san\sempty\sfreelist. -D 2014-08-20T18:43:44.510 +C Enhancements\sto\sskip-scan\ssuch\sthat\sit\sis\soperable\swhen\sa\smiddle\scolumn\sof\nan\sindex\sis\sskipped\swhile\sthe\sleft-most\scolumn\sis\sconstrained\sin\sthe\sWHERE\nclause. +D 2014-08-20T23:38:07.310 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c ab20f9c24a422ee8900831b343c3d1e5e7aca87b +F src/where.c 4c499d185827a492643cf017ae5e3aa0523f9f18 F src/whereInt.h 923820bee9726033a501a08d2fc69b9c1ee4feb3 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -832,6 +832,7 @@ F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329 F test/skipscan1.test 28c7faa41a0d7265040ecb0a0abd90c0904270b2 F test/skipscan2.test d1d1450952b7275f0b0a3a981f0230532743951a +F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5 F test/skipscan5.test d8b9692b702745a0e41c23f9da6beac81df01196 F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24 @@ -1186,7 +1187,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P fe4fd014b42b7b158ca968f1535b5636c67769f6 -R 865eceb09aea170bb70d44b771b85e6e +P 49f44d355ff70744e4951baca2481c7c2b6c02b3 +R 96923099996337b045b25027695cfca6 U drh -Z 0631afdcc5729e41fc50a75336710200 +Z 1b9938878e462b798940573e6153541a diff --git a/manifest.uuid b/manifest.uuid index 2bb2527d30..c25a80761d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -49f44d355ff70744e4951baca2481c7c2b6c02b3 \ No newline at end of file +bc985caa7816f1f873ad8e4467c5278399f315ce \ No newline at end of file diff --git a/src/where.c b/src/where.c index 9c30136e87..6a4299cc9a 100644 --- a/src/where.c +++ b/src/where.c @@ -3781,8 +3781,8 @@ static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){ sqlite3DebugPrintf(" %12s", pItem->zAlias ? pItem->zAlias : pTab->zName); if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){ - const char *zName; - if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){ + const char *zName; + if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){ if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){ int i = sqlite3Strlen30(zName) - 1; while( zName[i]!='_' ) i--; @@ -3803,7 +3803,11 @@ static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){ sqlite3DebugPrintf(" %-19s", z); sqlite3_free(z); } - sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); + if( p->wsFlags & WHERE_SKIPSCAN ){ + sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip); + }else{ + sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); + } sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); #ifdef SQLITE_ENABLE_TREE_EXPLAIN /* If the 0x100 bit of wheretracing is set, then show all of the constraint @@ -4316,8 +4320,7 @@ static int whereLoopAddBtreeIndex( ** On the other hand, the extra seeks could end up being significantly ** more expensive. */ assert( 42==sqlite3LogEst(18) ); - if( pTerm==0 - && saved_nEq==saved_nSkip + if( saved_nEq==saved_nSkip && saved_nEq+1nKeyCol && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK @@ -4328,9 +4331,17 @@ static int whereLoopAddBtreeIndex( pNew->aLTerm[pNew->nLTerm++] = 0; pNew->wsFlags |= WHERE_SKIPSCAN; nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1]; + if( pTerm ){ + /* TUNING: When estimating skip-scan for a term that is also indexable, + ** increase the cost of the skip-scan by 2x, to make it a little less + ** desirable than the regular index lookup. */ + nIter += 10; assert( 10==sqlite3LogEst(2) ); + } pNew->nOut -= nIter; whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul); pNew->nOut = saved_nOut; + pNew->u.btree.nEq = saved_nEq; + pNew->u.btree.nSkip = saved_nSkip; } for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */ diff --git a/test/skipscan3.test b/test/skipscan3.test new file mode 100644 index 0000000000..260d11cac9 --- /dev/null +++ b/test/skipscan3.test @@ -0,0 +1,73 @@ +# 2014-08-20 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests of the "skip-scan" query strategy. +# In particular, this file looks at skipping intermediate terms +# in an index. For example, if (a,b,c) are indexed, and we have +# "WHERE a=?1 AND c=?2" - verify that skip-scan can still be used. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test skipscan3-1.1 { + CREATE TABLE t1(a,b,c,d,PRIMARY KEY(a,b,c)); + WITH RECURSIVE + c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t1(a,b,c,d) + SELECT 1, 1, x, printf('x%04d',x) FROM c; + ANALYZE; +} {} + +# This version has long used skip-scan because of the "+a" +# +do_execsql_test skipscan3-1.2eqp { + EXPLAIN QUERY PLAN SELECT d FROM t1 WHERE +a=1 AND c=32; +} {/*ANY(a) AND ANY(b)*/} +do_execsql_test skipscan3-1.2 { + SELECT d FROM t1 WHERE +a=1 AND c=32; +} {x0032} + +# This version (with "a" instead of "+a") should use skip-scan but +# did not prior to changes implemented on 2014-08-20 +# +do_execsql_test skipscan3-1.3eqp { + EXPLAIN QUERY PLAN SELECT d FROM t1 WHERE a=1 AND c=32; +} {/*ANY(a) AND ANY(b)*/} +do_execsql_test skipscan3-1.3 { + SELECT d FROM t1 WHERE a=1 AND c=32; +} {x0032} + +# Repeat the test on a WITHOUT ROWID table +# +do_execsql_test skipscan3-2.1 { + CREATE TABLE t2(a,b,c,d,PRIMARY KEY(a,b,c)) WITHOUT ROWID; + WITH RECURSIVE + c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t2(a,b,c,d) + SELECT 1, 1, x, printf('x%04d',x) FROM c; + ANALYZE; +} {} +do_execsql_test skipscan3-2.2eqp { + EXPLAIN QUERY PLAN SELECT d FROM t2 WHERE +a=1 AND c=32; +} {/*ANY(a) AND ANY(b)*/} +do_execsql_test skipscan3-2.2 { + SELECT d FROM t2 WHERE +a=1 AND c=32; +} {x0032} +do_execsql_test skipscan3-2.3eqp { + EXPLAIN QUERY PLAN SELECT d FROM t2 WHERE a=1 AND c=32; +} {/*ANY(a) AND ANY(b)*/} +do_execsql_test skipscan3-2.3 { + SELECT d FROM t2 WHERE a=1 AND c=32; +} {x0032} + + +finish_test From b614eab3d2da06fea1c23eb3dbc08816ed178b5e Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 Aug 2014 23:42:50 +0000 Subject: [PATCH 15/16] Increase the version number to 3.8.7 FossilOrigin-Name: 91594aae0725388765070c80039dfe1bf126392d --- VERSION | 2 +- configure | 18 +++++++++--------- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index 2e14a9557d..4351a7e3a3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.8.6 +3.8.7 diff --git a/configure b/configure index 8748a98406..9b8266d812 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.62 for sqlite 3.8.6. +# Generated by GNU Autoconf 2.62 for sqlite 3.8.7. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. @@ -743,8 +743,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='sqlite' PACKAGE_TARNAME='sqlite' -PACKAGE_VERSION='3.8.6' -PACKAGE_STRING='sqlite 3.8.6' +PACKAGE_VERSION='3.8.7' +PACKAGE_STRING='sqlite 3.8.7' PACKAGE_BUGREPORT='' # Factoring default headers for most tests. @@ -1483,7 +1483,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sqlite 3.8.6 to adapt to many kinds of systems. +\`configure' configures sqlite 3.8.7 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1548,7 +1548,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sqlite 3.8.6:";; + short | recursive ) echo "Configuration of sqlite 3.8.7:";; esac cat <<\_ACEOF @@ -1664,7 +1664,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sqlite configure 3.8.6 +sqlite configure 3.8.7 generated by GNU Autoconf 2.62 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1678,7 +1678,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sqlite $as_me 3.8.6, which was +It was created by sqlite $as_me 3.8.7, which was generated by GNU Autoconf 2.62. Invocation command line was $ $0 $@ @@ -14021,7 +14021,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sqlite $as_me 3.8.6, which was +This file was extended by sqlite $as_me 3.8.7, which was generated by GNU Autoconf 2.62. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -14074,7 +14074,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -sqlite config.status 3.8.6 +sqlite config.status 3.8.7 configured by $0, generated by GNU Autoconf 2.62, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/manifest b/manifest index 928130ab8a..292e662207 100644 --- a/manifest +++ b/manifest @@ -1,12 +1,12 @@ -C Enhancements\sto\sskip-scan\ssuch\sthat\sit\sis\soperable\swhen\sa\smiddle\scolumn\sof\nan\sindex\sis\sskipped\swhile\sthe\sleft-most\scolumn\sis\sconstrained\sin\sthe\sWHERE\nclause. -D 2014-08-20T23:38:07.310 +C Increase\sthe\sversion\snumber\sto\s3.8.7 +D 2014-08-20T23:42:50.860 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.msc 5b04e657cf08a9ac7fc47d876c5c8be962c47d6b F Makefile.vxworks 034289efa9d591b04b1a73598623119c306cbba0 F README.md 64f270c43c38c46de749e419c22f0ae2f4499fe8 -F VERSION 1c877615a9db323e3cd301e3d57d853f9d5c4a07 +F VERSION 53a0b870e7f16d3b06623c31d233a304c163a6af F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 F addopcodes.awk 9eb448a552d5c0185cf62c463f9c173cedae3811 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 @@ -38,7 +38,7 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 F config.h.in 0921066a13130082764ab4ab6456f7b5bebe56de F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure 513f1e2464c3673bcdb5471b13d98e7eeb6f5ca2 x +F configure ad59a5f48b3c59a92b5506040a22fbe3f733a9d8 x F configure.ac 4cf9f60785143fa141b10962ccc885d973792e9a F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html 334dbf6621b8fb8790297ec1abf3cfa4621709d1 @@ -1187,7 +1187,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 49f44d355ff70744e4951baca2481c7c2b6c02b3 -R 96923099996337b045b25027695cfca6 +P bc985caa7816f1f873ad8e4467c5278399f315ce +R 69e5d59c0ae1acccebd6955e02833316 U drh -Z 1b9938878e462b798940573e6153541a +Z 5338496858d2cbdf1a890a2630150d12 diff --git a/manifest.uuid b/manifest.uuid index c25a80761d..d619efb0e7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bc985caa7816f1f873ad8e4467c5278399f315ce \ No newline at end of file +91594aae0725388765070c80039dfe1bf126392d \ No newline at end of file From b6b4b79f344096791542265763467fc90f139c2e Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Aug 2014 14:10:23 +0000 Subject: [PATCH 16/16] Fix a faulty assert() statement. Add comments to clarify the behavior of the sqlite3OpenTableAndIndices() routine in insert.c. Add test cases to verify that the assert() statement is not firing inappropriately. Ticket [369d57fb8e5ccdff06f1]. FossilOrigin-Name: 7029b3404d3f5f698a496934f3a3f2972051b257 --- ext/rtree/rtreeF.test | 81 +++++++++++++++++++++++++++++++++++++++++++ manifest | 15 ++++---- manifest.uuid | 2 +- src/delete.c | 8 +++-- src/insert.c | 9 +++-- 5 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 ext/rtree/rtreeF.test diff --git a/ext/rtree/rtreeF.test b/ext/rtree/rtreeF.test new file mode 100644 index 0000000000..c9620d34f7 --- /dev/null +++ b/ext/rtree/rtreeF.test @@ -0,0 +1,81 @@ +# 2014-08-21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file contains tests for the r-tree module. +# +# This file contains test cases for the ticket +# [369d57fb8e5ccdff06f197a37147a88f9de95cda] (2014-08-21) +# +# The following SQL causes an assertion fault while running +# sqlite3_prepare() on the DELETE statement: +# +# CREATE TABLE t1(x); +# CREATE TABLE t2(y); +# CREATE VIRTUAL TABLE t3 USING rtree(a,b,c); +# CREATE TRIGGER t2del AFTER DELETE ON t2 WHEN (SELECT 1 from t1) BEGIN +# DELETE FROM t3 WHERE a=old.y; +# END; +# DELETE FROM t2 WHERE y=1; +# + +if {![info exists testdir]} { + set testdir [file join [file dirname [info script]] .. .. test] +} +source $testdir/tester.tcl +ifcapable !rtree { finish_test ; return } + +do_execsql_test rtreeF-1.1 { + CREATE TABLE t1(x); + CREATE TABLE t2(y); + CREATE VIRTUAL TABLE t3 USING rtree(a,b,c); + CREATE TRIGGER t2dwl AFTER DELETE ON t2 WHEN (SELECT 1 from t1) BEGIN + DELETE FROM t3 WHERE a=old.y; + END; + + INSERT INTO t1(x) VALUES(999); + INSERT INTO t2(y) VALUES(1),(2),(3),(4),(5); + INSERT INTO t3(a,b,c) VALUES(1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,6,7); + + SELECT a FROM t3 ORDER BY a; + SELECT '|'; + SELECT y FROM t2 ORDER BY y; +} {1 2 3 4 5 | 1 2 3 4 5} +do_execsql_test rtreeF-1.2 { + DELETE FROM t2 WHERE y=3; + + SELECT a FROM t3 ORDER BY a; + SELECT '|'; + SELECT y FROM t2 ORDER BY y; +} {1 2 4 5 | 1 2 4 5} +do_execsql_test rtreeF-1.3 { + DELETE FROM t1; + DELETE FROM t2 WHERE y=5; + + SELECT a FROM t3 ORDER BY a; + SELECT '|'; + SELECT y FROM t2 ORDER BY y; +} {1 2 4 5 | 1 2 4} +do_execsql_test rtreeF-1.4 { + INSERT INTO t1 DEFAULT VALUES; + DELETE FROM t2 WHERE y=5; + + SELECT a FROM t3 ORDER BY a; + SELECT '|'; + SELECT y FROM t2 ORDER BY y; +} {1 2 4 5 | 1 2 4} +do_execsql_test rtreeF-1.5 { + DELETE FROM t2 WHERE y=2; + + SELECT a FROM t3 ORDER BY a; + SELECT '|'; + SELECT y FROM t2 ORDER BY y; +} {1 4 5 | 1 4} + +finish_test diff --git a/manifest b/manifest index 292e662207..1e5132fbcf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sversion\snumber\sto\s3.8.7 -D 2014-08-20T23:42:50.860 +C Fix\sa\sfaulty\sassert()\sstatement.\s\sAdd\scomments\sto\sclarify\sthe\sbehavior\sof\nthe\ssqlite3OpenTableAndIndices()\sroutine\sin\sinsert.c.\s\sAdd\stest\scases\sto\nverify\sthat\sthe\sassert()\sstatement\sis\snot\sfiring\sinappropriately.\nTicket\s[369d57fb8e5ccdff06f1]. +D 2014-08-21T14:10:23.770 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -138,6 +138,7 @@ F ext/rtree/rtreeB.test c85f9ce78766c4e68b8b89fbf2979ee9cfa82b4e F ext/rtree/rtreeC.test df158dcc81f1a43ce7eef361af03c48ec91f1e06 F ext/rtree/rtreeD.test 636630357638f5983701550b37f0f5867130d2ca F ext/rtree/rtreeE.test 388c1c8602c3ce55c15f03b509e9cf545fb7c41f +F ext/rtree/rtreeF.test 66deb9fd1611c7ca2e374adba63debdc2dbb12b4 F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195 F ext/rtree/rtree_util.tcl 06aab2ed5b826545bf215fff90ecb9255a8647ea F ext/rtree/sqlite3rtree.h 83349d519fe5f518b3ea025d18dd1fe51b1684bd @@ -175,7 +176,7 @@ F src/callback.c fcff28cf0df2403dd2f313bb8d1b8f31f6f3cd64 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a F src/date.c 593c744b2623971e45affd0bde347631bdfa4625 -F src/delete.c bcf8f72126cea80fc3d5bc5494cf19b3f8935aaf +F src/delete.c 5adcd322c6b08fc25d215d780ca62cebce66304d F src/expr.c f749009cf4a8534efb5e0d5cd7c9fb1fb0f2836c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 8545f3b36da47473e10800ea4fb0810fd4062514 @@ -184,7 +185,7 @@ F src/global.c 1e4bd956dc2f608f87d2a929abc4a20db65f30e4 F src/hash.c d139319967164f139c8d1bb8a11b14db9c4ba3cd F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 991e4964e9295da3993e2c0f81c7faf642371848 +F src/insert.c d1a104e67b33314d4cc5c1356147446086ab9fc8 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c febc2a9e7ad6c1a6191c7b5b9170b325d263f343 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b @@ -1187,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P bc985caa7816f1f873ad8e4467c5278399f315ce -R 69e5d59c0ae1acccebd6955e02833316 +P 91594aae0725388765070c80039dfe1bf126392d +R 25e887863ed8cfd2c8a241fac46385f1 U drh -Z 5338496858d2cbdf1a890a2630150d12 +Z ed55b6e966354470a11e6c95fe10b90c diff --git a/manifest.uuid b/manifest.uuid index d619efb0e7..944f894bbc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -91594aae0725388765070c80039dfe1bf126392d \ No newline at end of file +7029b3404d3f5f698a496934f3a3f2972051b257 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index c74d8eab7d..af83903c42 100644 --- a/src/delete.c +++ b/src/delete.c @@ -466,10 +466,11 @@ void sqlite3DeleteFrom( ** triggers. */ if( !isView ){ + testcase( IsVirtual(pTab) ); sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen, &iDataCur, &iIdxCur); - assert( pPk || iDataCur==iTabCur ); - assert( pPk || iIdxCur==iDataCur+1 ); + assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur ); + assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 ); } /* Set up a loop over the rowids/primary-keys that were found in the @@ -477,7 +478,8 @@ void sqlite3DeleteFrom( */ if( okOnePass ){ /* Just one row. Hence the top-of-loop is a no-op */ - assert( nKey==nPk ); /* OP_Found will use an unpacked key */ + assert( nKey==nPk ); /* OP_Found will use an unpacked key */ + assert( !IsVirtual(pTab) ); if( aToOpen[iDataCur-iTabCur] ){ assert( pPk!=0 ); sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); diff --git a/src/insert.c b/src/insert.c index 5964b91ca4..3e6982d836 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1612,6 +1612,9 @@ void sqlite3CompleteInsertion( ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range ** of *piIdxCurs, depending on where the PRIMARY KEY index appears on the ** pTab->pIndex list. +** +** If pTab is a virtual table, then this routine is a no-op and the +** *piDataCur and *piIdxCur values are left uninitialized. */ int sqlite3OpenTableAndIndices( Parse *pParse, /* Parsing context */ @@ -1630,9 +1633,9 @@ int sqlite3OpenTableAndIndices( assert( op==OP_OpenRead || op==OP_OpenWrite ); if( IsVirtual(pTab) ){ - assert( aToOpen==0 ); - *piDataCur = 0; - *piIdxCur = 1; + /* This routine is a no-op for virtual tables. Leave the output + ** variables *piDataCur and *piIdxCur uninitialized so that valgrind + ** can detect if they are used by mistake in the caller. */ return 0; } iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);