From 8e86b6a3df4749565a173c9dff48d6d516b09af9 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 28 May 2014 03:27:42 +0000 Subject: [PATCH 01/12] Revise locking retry semantics in Win32 VFS to abort early if the file handle is reported as invalid. FossilOrigin-Name: d43e2e59b5647655595fd953febf2beefa480006 --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/os_win.c | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index faef47fa27..618ec27c47 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\show\sOSTRACE\sreports\slogically\sboolean\sresults\sin\sthe\sWin32\sVFS. -D 2014-05-28T03:23:55.937 +C Revise\slocking\sretry\ssemantics\sin\sWin32\sVFS\sto\sabort\searly\sif\sthe\sfile\shandle\sis\sreported\sas\sinvalid. +D 2014-05-28T03:27:42.937 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -206,7 +206,7 @@ F src/os.h 60d419395e32a8029fa380a80a3da2e9030f635e F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c ae4b5240af4619d711301d7992396e182585269f -F src/os_win.c 648f842876e25391b7c454c8e49f7db1fd981d65 +F src/os_win.c a5b9ed90eed522925135f1cc5f0e737a624a6b5c F src/os_win.h 057344a6720b4c8405d9bd98f58cb37a6ee46c25 F src/pager.c f6bb1fa6cdf2062f2d8aec3e64db302bca519ab8 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 @@ -1173,7 +1173,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b8b66103de8c554cb87df40bf040760ec29f2ae1 -R fb2228bf340b8e64476c0b547456f447 +P c405f971cf03e29110019ff863cbfb026d97e1e6 +R 80dc0ba2eb26692fe89f4430050446dd +T *branch * winLockHandle +T *sym-winLockHandle * +T -sym-trunk * U mistachkin -Z 33db4268ebdb5368353cf9e380a10aca +Z 89844ed2f261cecaceceb182643fd2e9 diff --git a/manifest.uuid b/manifest.uuid index a5c805d0f6..ec0e3fa20e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c405f971cf03e29110019ff863cbfb026d97e1e6 \ No newline at end of file +d43e2e59b5647655595fd953febf2beefa480006 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 21f633e486..eb7e87f431 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2924,8 +2924,16 @@ static int winLock(sqlite3_file *id, int locktype){ ** If you are using this code as a model for alternative VFSes, do not ** copy this retry logic. It is a hack intended for Windows only. */ + lastErrno = osGetLastError(); OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n", pFile->h, cnt, res)); + if( lastErrno==ERROR_INVALID_HANDLE ){ + pFile->lastErrno = lastErrno; + rc = SQLITE_IOERR_LOCK; + OSTRACE(("LOCK-FAIL file=%p, count=%d, rc=%s\n", + pFile->h, cnt, sqlite3ErrName(rc))); + return rc; + } if( cnt ) sqlite3_win32_sleep(1); } gotPendingLock = res; From 3c4461f47a005fdea02e4cd25d0e714750e8f0d9 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 29 May 2014 20:39:59 +0000 Subject: [PATCH 02/12] Fix a harmless compiler warning in the command-line shell code. FossilOrigin-Name: a80527f60b4856e869f25e7b13afde351bc26a25 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 5ca3da5016..abdeead218 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sto\sthe\sEXPLAIN\sindentation\slogic\sin\sthe\scommand-line\sshell. -D 2014-05-29T20:17:57.027 +C Fix\sa\sharmless\scompiler\swarning\sin\sthe\scommand-line\sshell\scode. +D 2014-05-29T20:39:59.843 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -221,7 +221,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 7df17ec5506c2427576d412bee0e6ea740e12563 -F src/shell.c 33f6c0bc0e32eae099f7c2b79cfa7515b4b4702c +F src/shell.c d4ec3e1473501e78f39627787c8d356c0f5452d1 F src/sqlite.h.in 564fc23db33870b5096b20d72df7491ce0b8b74f F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1173,7 +1173,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 48dce821a07ac29da6ce05e92cf3f6e52b6eb388 -R f3f6ddac33e05ba165213ff981b802f2 +P 8f916ed1e185ac728e00624d90e1d7bd2dda4469 +R e88640dd77d6321637c2833220e39939 U drh -Z 830218d29106127a2f4cf14b2b59a5e2 +Z 271b40f418717eb27805b21d52c6570f diff --git a/manifest.uuid b/manifest.uuid index 16ffe06ff6..16ca89683b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8f916ed1e185ac728e00624d90e1d7bd2dda4469 \ No newline at end of file +a80527f60b4856e869f25e7b13afde351bc26a25 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 9b45a20592..526ddbbdec 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2998,7 +2998,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"", zCmd, azArg[i]); } - system(zCmd); + (void)system(zCmd); sqlite3_free(zCmd); }else From 6b98d67b2b71680943326322270ade738962fddc Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 30 May 2014 16:42:35 +0000 Subject: [PATCH 03/12] Add tests for the invalid file handle detection logic in the winLock() function. FossilOrigin-Name: ed5a9eb4f30a395bc641e79254217c7d7cf0aa5d --- manifest | 21 ++++++++----------- manifest.uuid | 2 +- src/os_win.c | 11 ++++++++++ src/sqlite.h.in | 7 +++++++ src/test1.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ test/win32lock.test | 50 +++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 126 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 618ec27c47..79d8e7466f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\slocking\sretry\ssemantics\sin\sWin32\sVFS\sto\sabort\searly\sif\sthe\sfile\shandle\sis\sreported\sas\sinvalid. -D 2014-05-28T03:27:42.937 +C Add\stests\sfor\sthe\sinvalid\sfile\shandle\sdetection\slogic\sin\sthe\swinLock()\sfunction. +D 2014-05-30T16:42:35.024 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -206,7 +206,7 @@ F src/os.h 60d419395e32a8029fa380a80a3da2e9030f635e F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c ae4b5240af4619d711301d7992396e182585269f -F src/os_win.c a5b9ed90eed522925135f1cc5f0e737a624a6b5c +F src/os_win.c 8dbf6c11780fe2eb96c1f289e664d0c7b2911d37 F src/os_win.h 057344a6720b4c8405d9bd98f58cb37a6ee46c25 F src/pager.c f6bb1fa6cdf2062f2d8aec3e64db302bca519ab8 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 @@ -222,7 +222,7 @@ F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 7df17ec5506c2427576d412bee0e6ea740e12563 F src/shell.c bfac06fb15f3cd0d447e2e72ab3a283fac301813 -F src/sqlite.h.in 564fc23db33870b5096b20d72df7491ce0b8b74f +F src/sqlite.h.in a98eb3e8c86c934ea6f5bcfc6b69653dde2f4ed4 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqliteInt.h fccdc735c27b3dc12322fec7cdad8bc76be8d00b @@ -230,7 +230,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e F src/tclsqlite.c e87c99e28a145943666b51b212dacae35fcea0bd -F src/test1.c 899bddeb0c7fb2b8062de6f03af4a4e4f48f9df5 +F src/test1.c 4edf8810c86d77ae7ac6d56d563965a9beeea2ce F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df @@ -1110,7 +1110,7 @@ F test/whereI.test 1d89199697919d4930be05a71e7fe620f114e622 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c -F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361 +F test/win32lock.test 31ac36515037a6244204d234aa117d88e1657acb F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d F test/with1.test 268081a6b14817a262ced4d0ee34d4d2a1dd2068 F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 @@ -1173,10 +1173,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 c405f971cf03e29110019ff863cbfb026d97e1e6 -R 80dc0ba2eb26692fe89f4430050446dd -T *branch * winLockHandle -T *sym-winLockHandle * -T -sym-trunk * +P d43e2e59b5647655595fd953febf2beefa480006 +R 8cf30fccc468f8f912423f19e0dc97b6 U mistachkin -Z 89844ed2f261cecaceceb182643fd2e9 +Z eef6c127dd0b165b8d2b10d5b85e8cb6 diff --git a/manifest.uuid b/manifest.uuid index ec0e3fa20e..39fd773c43 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d43e2e59b5647655595fd953febf2beefa480006 \ No newline at end of file +ed5a9eb4f30a395bc641e79254217c7d7cf0aa5d \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index eb7e87f431..015b6c61da 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -3177,6 +3177,17 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){ OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); return SQLITE_OK; } +#ifdef SQLITE_TEST + case SQLITE_FCNTL_WIN32_SET_HANDLE: { + LPHANDLE phFile = (LPHANDLE)pArg; + HANDLE hOldFile = pFile->h; + pFile->h = *phFile; + *phFile = hOldFile; + OSTRACE(("FCNTL oldFile=%p, newFile=%p, rc=SQLITE_OK\n", + hOldFile, pFile->h)); + return SQLITE_OK; + } +#endif case SQLITE_FCNTL_TEMPFILENAME: { char *zTFile = 0; int rc = winGetTempname(pFile->pVfs, &zTFile); diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9be07fc1e6..21ab67a4c2 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -942,6 +942,12 @@ struct sqlite3_io_methods { ** on whether or not the file has been renamed, moved, or deleted since it ** was first opened. ** +**
  • [[SQLITE_FCNTL_WIN32_SET_HANDLE]] +** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This +** opcode causes the xFileControl method to swap the file handle with the one +** pointed to by the pArg argument. This capability is used during testing +** and only needs to be supported when SQLITE_TEST is defined. +** ** */ #define SQLITE_FCNTL_LOCKSTATE 1 @@ -965,6 +971,7 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_HAS_MOVED 20 #define SQLITE_FCNTL_SYNC 21 #define SQLITE_FCNTL_COMMIT_PHASETWO 22 +#define SQLITE_FCNTL_WIN32_SET_HANDLE 23 /* ** CAPI3REF: Mutex Handle diff --git a/src/test1.c b/src/test1.c index 44f56a6c84..a99b26ffd0 100644 --- a/src/test1.c +++ b/src/test1.c @@ -117,6 +117,16 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ return TCL_OK; } +#if SQLITE_OS_WIN +/* +** Decode a Win32 HANDLE object. +*/ +int getWin32Handle(Tcl_Interp *interp, const char *zA, LPHANDLE phFile){ + *phFile = (HANDLE)sqlite3TestTextToPtr(zA); + return TCL_OK; +} +#endif + extern const char *sqlite3ErrName(int); #define t1ErrorName sqlite3ErrName @@ -5210,6 +5220,7 @@ static int file_control_lockproxy_test( return TCL_OK; } +#if SQLITE_OS_WIN /* ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY ** @@ -5243,6 +5254,42 @@ static int file_control_win32_av_retry( return TCL_OK; } +/* +** tclcmd: file_control_win32_set_handle DB HANDLE +** +** This TCL command runs the sqlite3_file_control interface with +** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode. +*/ +static int file_control_win32_set_handle( + ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int objc, /* Number of arguments */ + Tcl_Obj *CONST objv[] /* Command arguments */ +){ + sqlite3 *db; + int rc; + HANDLE hFile = NULL; + char z[100]; + + if( objc!=3 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", + Tcl_GetStringFromObj(objv[0], 0), " DB HANDLE", 0); + return TCL_ERROR; + } + if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ + return TCL_ERROR; + } + if( getWin32Handle(interp, Tcl_GetString(objv[2]), &hFile) ){ + return TCL_ERROR; + } + rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_SET_HANDLE, + (void*)&hFile); + sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile); + Tcl_AppendResult(interp, z, (char*)0); + return TCL_OK; +} +#endif + /* ** tclcmd: file_control_persist_wal DB PERSIST-FLAG ** @@ -6472,7 +6519,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "file_control_lockproxy_test", file_control_lockproxy_test, 0 }, { "file_control_chunksize_test", file_control_chunksize_test, 0 }, { "file_control_sizehint_test", file_control_sizehint_test, 0 }, +#if SQLITE_OS_WIN { "file_control_win32_av_retry", file_control_win32_av_retry, 0 }, + { "file_control_win32_set_handle", file_control_win32_set_handle, 0 }, +#endif { "file_control_persist_wal", file_control_persist_wal, 0 }, { "file_control_powersafe_overwrite",file_control_powersafe_overwrite,0}, { "file_control_vfsname", file_control_vfsname, 0 }, diff --git a/test/win32lock.test b/test/win32lock.test index 724172065f..2eb6aaca2e 100644 --- a/test/win32lock.test +++ b/test/win32lock.test @@ -24,7 +24,7 @@ db close sqlite3_shutdown test_sqlite3_log xLog proc xLog {error_code msg} { - lappend ::log $msg + lappend ::log $msg } sqlite3 db test.db db eval {PRAGMA mmap_size=0} @@ -128,7 +128,53 @@ while {1} { file_control_win32_av_retry db 10 25 sqlite3_test_control_pending_byte $old_pending_byte db close +forcedelete test.db + +sqlite3 db test.db +sqlite3 db2 test.db + +do_test win32lock-3.0 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(3); + } +} {} + +do_test win32lock-3.1 { + db eval { + BEGIN EXCLUSIVE; + INSERT INTO t1 VALUES(4); + } +} {} + +do_test win32lock-3.2 { + catchsql { + BEGIN EXCLUSIVE; + INSERT INTO t1 VALUES(5); + COMMIT; + } db2 +} {1 {database is locked}} + +do_test win32lock-3.3 { + db eval { + COMMIT; + } +} {} + +do_test win32lock-3.4 { + set handle [lindex [file_control_win32_set_handle db 0] end] + list [catchsql { + BEGIN EXCLUSIVE; + INSERT INTO t1 VALUES(6); + COMMIT; + }] [file_control_win32_set_handle db $handle] +} {{1 {disk I/O error}} {0 0}} + +db2 close +db close sqlite3_shutdown -test_sqlite3_log +test_sqlite3_log sqlite3_initialize finish_test From ff9fcd5a14cdc2dd1df2f0beb00484735b05b9f5 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 30 May 2014 16:54:09 +0000 Subject: [PATCH 04/12] Add extra checking of the database extended error code. FossilOrigin-Name: f2906c44519d76db5bc36013369ae498b80655a8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/win32lock.test | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 79d8e7466f..ea0a4260d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sfor\sthe\sinvalid\sfile\shandle\sdetection\slogic\sin\sthe\swinLock()\sfunction. -D 2014-05-30T16:42:35.024 +C Add\sextra\schecking\sof\sthe\sdatabase\sextended\serror\scode. +D 2014-05-30T16:54:09.869 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1110,7 +1110,7 @@ F test/whereI.test 1d89199697919d4930be05a71e7fe620f114e622 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c -F test/win32lock.test 31ac36515037a6244204d234aa117d88e1657acb +F test/win32lock.test 71642fa56e9b06e5cfffe6bad67cb8c1eb2c555a F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d F test/with1.test 268081a6b14817a262ced4d0ee34d4d2a1dd2068 F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775 @@ -1173,7 +1173,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 d43e2e59b5647655595fd953febf2beefa480006 -R 8cf30fccc468f8f912423f19e0dc97b6 +P ed5a9eb4f30a395bc641e79254217c7d7cf0aa5d +R 35776e018c929a9d3407d29571ba8a8f U mistachkin -Z eef6c127dd0b165b8d2b10d5b85e8cb6 +Z b80ed398d4e8aaa5357d010e1790f177 diff --git a/manifest.uuid b/manifest.uuid index 39fd773c43..5210d89d20 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed5a9eb4f30a395bc641e79254217c7d7cf0aa5d \ No newline at end of file +f2906c44519d76db5bc36013369ae498b80655a8 \ No newline at end of file diff --git a/test/win32lock.test b/test/win32lock.test index 2eb6aaca2e..cff1ed3d87 100644 --- a/test/win32lock.test +++ b/test/win32lock.test @@ -169,8 +169,8 @@ do_test win32lock-3.4 { BEGIN EXCLUSIVE; INSERT INTO t1 VALUES(6); COMMIT; - }] [file_control_win32_set_handle db $handle] -} {{1 {disk I/O error}} {0 0}} + }] [file_control_win32_set_handle db $handle] [sqlite3_extended_errcode db] +} {{1 {disk I/O error}} {0 0} SQLITE_IOERR_LOCK} db2 close db close From 7ef4d1c40366a3870d35a99b101442f28f9ecd4e Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 31 May 2014 15:39:53 +0000 Subject: [PATCH 05/12] Fix a compile of harmless static analyzer warnings. FossilOrigin-Name: 7e287f2055dcd82c92d1711aec97cb6552a354bb --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 1 + tool/mkkeywordhash.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 55df20ee81..df06f52983 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\slocking\sretry\ssemantics\sin\sWin32\sVFS\sto\sabort\searly\sif\sthe\sfile\shandle\sis\sreported\sas\sinvalid. -D 2014-05-30T21:01:41.061 +C Fix\sa\scompile\sof\sharmless\sstatic\sanalyzer\swarnings. +D 2014-05-31T15:39:53.464 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -216,7 +216,7 @@ F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c 102e6f5a2fbc646154463eb856d1fd716867b64c F src/pragma.c 810ef31ccfaa233201dcf100637a9777cc24e897 F src/prepare.c 677521ab7132615a8a26107a1d1c3132f44ae337 -F src/printf.c e5a0005f8b3de21f85da6a709d2fbee76775bf4b +F src/printf.c af06f66927919730f03479fed6ae9854f73419f4 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be @@ -1137,7 +1137,7 @@ F tool/lemon.c 07aba6270d5a5016ba8107b09e431eea4ecdc123 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh f8d8dbf7d62f409ebed5134998bf5b51d7266383 -F tool/mkkeywordhash.c c9e05e4a7bcab8fab9f583d5b321fb72f565ad97 +F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 78a77b2c554d534c6f2dc903130186ed15715460 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 @@ -1173,7 +1173,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 a80527f60b4856e869f25e7b13afde351bc26a25 f2906c44519d76db5bc36013369ae498b80655a8 -R 43b1f325d24aa652957b56aa0239ea0b -U mistachkin -Z 56ea1620022ea76ba550a9a9fe3cd6a5 +P a4df4a5b34111f755ffd9ee6f089ff05d03ebc7a +R 2d19a2ada3f5fefd918cda5ebc3435ec +U drh +Z 8c6dc131bc227333f4313c945c3b7bef diff --git a/manifest.uuid b/manifest.uuid index e2c6345389..989543cb0b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a4df4a5b34111f755ffd9ee6f089ff05d03ebc7a \ No newline at end of file +7e287f2055dcd82c92d1711aec97cb6552a354bb \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 01209c042d..37910804d2 100644 --- a/src/printf.c +++ b/src/printf.c @@ -756,6 +756,7 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ zNew = sqlite3_realloc(zOld, p->nAlloc); } if( zNew ){ + assert( p->zText!=0 || p->nChar==0 ); if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); p->zText = zNew; }else{ diff --git a/tool/mkkeywordhash.c b/tool/mkkeywordhash.c index a467931c30..721611f5a3 100644 --- a/tool/mkkeywordhash.c +++ b/tool/mkkeywordhash.c @@ -370,7 +370,7 @@ int main(int argc, char **argv){ Keyword *p = &aKeywordTable[i]; p->len = (int)strlen(p->zName); assert( p->lenzOrigName) ); - strcpy(p->zOrigName, p->zName); + memcpy(p->zOrigName, p->zName, p->len+1); totalLen += p->len; p->hash = (UpperToLower[(int)p->zName[0]]*4) ^ (UpperToLower[(int)p->zName[p->len-1]]*3) ^ p->len; From 01f3754dcd9669b9fb2f9d945d3d8d1b03cb1e74 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 31 May 2014 15:43:33 +0000 Subject: [PATCH 06/12] Fix a harmless "scan-build" compiler warning in the command-line shell. FossilOrigin-Name: 39fafe0a19ff346a2354f00b03f8e8e4b8b0524c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index df06f52983..19a562db3c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scompile\sof\sharmless\sstatic\sanalyzer\swarnings. -D 2014-05-31T15:39:53.464 +C Fix\sa\sharmless\s"scan-build"\scompiler\swarning\sin\sthe\scommand-line\sshell. +D 2014-05-31T15:43:33.950 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -221,7 +221,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be F src/select.c 7df17ec5506c2427576d412bee0e6ea740e12563 -F src/shell.c d4ec3e1473501e78f39627787c8d356c0f5452d1 +F src/shell.c 98ce7f52445aa0c2eac3d4553a4cdcbb6402a670 F src/sqlite.h.in a98eb3e8c86c934ea6f5bcfc6b69653dde2f4ed4 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1173,7 +1173,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 a4df4a5b34111f755ffd9ee6f089ff05d03ebc7a -R 2d19a2ada3f5fefd918cda5ebc3435ec +P 7e287f2055dcd82c92d1711aec97cb6552a354bb +R 7e70d3d08723eec61780bac69ffa27e8 U drh -Z 8c6dc131bc227333f4313c945c3b7bef +Z 0b7f4da5b5f8e964f7f7fb0aa6199d46 diff --git a/manifest.uuid b/manifest.uuid index 989543cb0b..a35a2086fa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e287f2055dcd82c92d1711aec97cb6552a354bb \ No newline at end of file +39fafe0a19ff346a2354f00b03f8e8e4b8b0524c \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 526ddbbdec..1f8681f639 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2425,8 +2425,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ }else if( c=='i' && strncmp(azArg[0], "import", n)==0 ){ - char *zTable = azArg[2]; /* Insert data into this table */ - char *zFile = azArg[1]; /* Name of file to extra content from */ + char *zTable; /* Insert data into this table */ + char *zFile; /* Name of file to extra content from */ sqlite3_stmt *pStmt = NULL; /* A statement */ int nCol; /* Number of columns in the table */ int nByte; /* Number of bytes in an SQL string */ @@ -2441,6 +2441,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ fprintf(stderr, "Usage: .import FILE TABLE\n"); goto meta_command_exit; } + zFile = azArg[1]; + zTable = azArg[2]; seenInterrupt = 0; memset(&sCsv, 0, sizeof(sCsv)); open_db(p, 0); From 5f43812af82eb69019571ae594204232da616c75 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 2 Jun 2014 09:39:24 +0000 Subject: [PATCH 07/12] Add the "valgrind-nolookaside" permutation to permutations.test. FossilOrigin-Name: 8e8472d9b689d128eb11d3111e009161cf4580f7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/permutations.test | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 19a562db3c..5e7b19d8e8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\s"scan-build"\scompiler\swarning\sin\sthe\scommand-line\sshell. -D 2014-05-31T15:43:33.950 +C Add\sthe\s"valgrind-nolookaside"\spermutation\sto\spermutations.test. +D 2014-06-02T09:39:24.180 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -746,7 +746,7 @@ F test/pagesize.test 1dd51367e752e742f58e861e65ed7390603827a0 F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test b98fc868d71eb5619d42a1702e9ab91718cbed54 -F test/permutations.test d8946218493c77806ec1029df473d8ed4ad9aef6 +F test/permutations.test bc474bafb022cc5014ef3a9c3d5ab61d6d6f587c F test/pragma.test adb21a90875bc54a880fa939c4d7c46598905aa0 F test/pragma2.test aea7b3d82c76034a2df2b38a13745172ddc0bc13 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 @@ -1173,7 +1173,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 7e287f2055dcd82c92d1711aec97cb6552a354bb -R 7e70d3d08723eec61780bac69ffa27e8 -U drh -Z 0b7f4da5b5f8e964f7f7fb0aa6199d46 +P 39fafe0a19ff346a2354f00b03f8e8e4b8b0524c +R 387ada14b86204efc12685ecd89ec07f +U dan +Z e06809476b8cf9300fa9e3eaa704baed diff --git a/manifest.uuid b/manifest.uuid index a35a2086fa..e444e47797 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -39fafe0a19ff346a2354f00b03f8e8e4b8b0524c \ No newline at end of file +8e8472d9b689d128eb11d3111e009161cf4580f7 \ No newline at end of file diff --git a/test/permutations.test b/test/permutations.test index 0e5cc2c8d2..c3f4ddf9f5 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -158,6 +158,28 @@ test_suite "valgrind" -prefix "" -description { unset -nocomplain ::G(valgrind) } +test_suite "valgrind-nolookaside" -prefix "" -description { + Run the "veryquick" test suite with a couple of multi-process tests (that + fail under valgrind) omitted. +} -files [ + test_set $allquicktests -exclude *malloc* *ioerr* *fault* wal.test atof1.test +] -initialize { + set ::G(valgrind) 1 + catch {db close} + sqlite3_shutdown + sqlite3_config_lookaside 0 0 + sqlite3_initialize + autoinstall_test_functions +} -shutdown { + catch {db close} + sqlite3_shutdown + sqlite3_config_lookaside 100 500 + sqlite3_initialize + autoinstall_test_functions + unset -nocomplain ::G(valgrind) +} + + test_suite "quick" -prefix "" -description { Quick test suite. Runs in around 10 minutes on a workstation. } -files [ From 2504c6c632681da85a8a6a46e9acd6ab4bf7ae20 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 2 Jun 2014 11:26:33 +0000 Subject: [PATCH 08/12] Fix the query planner so that it once again knows that queries without a FROM clause will never return more than one row and hence do not require sorting. FossilOrigin-Name: 9f18b303cd1bc5779d82669884f802c7889b4947 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/where.c | 4 ++-- test/orderby1.test | 12 +++++++++++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 5e7b19d8e8..3d8587fb61 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"valgrind-nolookaside"\spermutation\sto\spermutations.test. -D 2014-06-02T09:39:24.180 +C Fix\sthe\squery\splanner\sso\sthat\sit\sonce\sagain\sknows\sthat\squeries\swithout\sa\nFROM\sclause\swill\snever\sreturn\smore\sthan\sone\srow\sand\shence\sdo\snot\srequire\nsorting. +D 2014-06-02T11:26:33.102 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -294,7 +294,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c b3be5eb4193b6327c4a02fe91411df503fe770e8 +F src/where.c 308ed08c648fb7e3d7ba5896363dd86b2a0cc616 F src/whereInt.h 6804c2e5010378568c2bb1350477537755296a46 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -726,7 +726,7 @@ F test/notnull.test f8fcf58669ddba79274daa2770d61dfad8274f62 F test/null.test a8b09b8ed87852742343b33441a9240022108993 F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1 F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 -F test/orderby1.test 9b524aff9147288da43a6d7ddfdcff47fa2303c6 +F test/orderby1.test 2a6164169199ed53c99089b087ef653e480f63ac F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04 F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99 F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4 @@ -1173,7 +1173,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 39fafe0a19ff346a2354f00b03f8e8e4b8b0524c -R 387ada14b86204efc12685ecd89ec07f -U dan -Z e06809476b8cf9300fa9e3eaa704baed +P 8e8472d9b689d128eb11d3111e009161cf4580f7 +R 9d072715608349b4afa2f27606dc53c0 +U drh +Z c7f9af8be8da856d6f5f7578b5205ca0 diff --git a/manifest.uuid b/manifest.uuid index e444e47797..9593e5bd41 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8e8472d9b689d128eb11d3111e009161cf4580f7 \ No newline at end of file +9f18b303cd1bc5779d82669884f802c7889b4947 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 25c1c04148..ccecccb12e 100644 --- a/src/where.c +++ b/src/where.c @@ -5297,7 +5297,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ /* TUNING: For simple queries, only the best path is tracked. ** For 2-way joins, the 5 best paths are followed. ** For joins of 3 or more tables, track the 10 best paths */ - mxChoice = (nLoop==1) ? 1 : (nLoop==2 ? 5 : 10); + mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10); assert( nLoop<=pWInfo->pTabList->nSrc ); WHERETRACE(0x002, ("---- begin solver\n")); @@ -5327,7 +5327,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ aFrom[0].isOrdered = 0; nOrderBy = 0; }else{ - aFrom[0].isOrdered = -1; + aFrom[0].isOrdered = nLoop>0 ? -1 : 1; nOrderBy = pWInfo->pOrderBy->nExpr; } diff --git a/test/orderby1.test b/test/orderby1.test index d4795671dd..30c8df2d22 100644 --- a/test/orderby1.test +++ b/test/orderby1.test @@ -452,6 +452,16 @@ do_test 4.0 { } } {1 13 1 14 1 15 1 16} - +# No sorting of queries that omit the FROM clause. +# +do_execsql_test 5.0 { + EXPLAIN QUERY PLAN SELECT 5 ORDER BY 1 +} {} +do_execsql_test 5.1 { + EXPLAIN QUERY PLAN SELECT 5 UNION ALL SELECT 3 ORDER BY 1 +} {~/B-TREE/} +do_execsql_test 5.2 { + SELECT 5 UNION ALL SELECT 3 ORDER BY 1 +} {3 5} finish_test From 974db61d9da64a8e343c4734ec896ee941f9b50c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 2 Jun 2014 18:24:55 +0000 Subject: [PATCH 09/12] Fix a typo in a requirements mark comment in a test script. No changes to code. FossilOrigin-Name: 75ff459b06e1a5c180d316d227ce2f73c99a1f52 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/e_insert.test | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3d8587fb61..83f779bee0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\squery\splanner\sso\sthat\sit\sonce\sagain\sknows\sthat\squeries\swithout\sa\nFROM\sclause\swill\snever\sreturn\smore\sthan\sone\srow\sand\shence\sdo\snot\srequire\nsorting. -D 2014-06-02T11:26:33.102 +C Fix\sa\stypo\sin\sa\srequirements\smark\scomment\sin\sa\stest\sscript.\s\sNo\schanges\sto\ncode. +D 2014-06-02T18:24:55.152 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -444,7 +444,7 @@ F test/e_dropview.test 0c9f7f60989164a70a67a9d9c26d1083bc808306 F test/e_expr.test 5c71d183fbf519a4769fd2e2124afdc70b5b1f42 F test/e_fkey.test a1783fe1f759e1990e6a11adfcf0702dac4d0707 F test/e_fts3.test 5c02288842e4f941896fd44afdef564dd5fc1459 -F test/e_insert.test 1e44f84d2abe44d66e4fbf198be4b20e3cc724a0 +F test/e_insert.test 7b2fa9cd1456f83474d6c5d27db3abaeb8be2023 F test/e_reindex.test 396b7b4f0a66863b4e95116a67d93b227193e589 F test/e_resolve.test dcce9308fb13b934ce29591105d031d3e14fbba6 F test/e_select.test 52692ff3849541e828ad4661fe3773a9b8711763 @@ -1173,7 +1173,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 8e8472d9b689d128eb11d3111e009161cf4580f7 -R 9d072715608349b4afa2f27606dc53c0 +P 9f18b303cd1bc5779d82669884f802c7889b4947 +R d2860e47e4361323fe5044697b7809e3 U drh -Z c7f9af8be8da856d6f5f7578b5205ca0 +Z 3c888acab84366f73445c2218a0f8a8d diff --git a/manifest.uuid b/manifest.uuid index 9593e5bd41..2dd57bbecb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f18b303cd1bc5779d82669884f802c7889b4947 \ No newline at end of file +75ff459b06e1a5c180d316d227ce2f73c99a1f52 \ No newline at end of file diff --git a/test/e_insert.test b/test/e_insert.test index adda996b5a..0ea4b76bb5 100644 --- a/test/e_insert.test +++ b/test/e_insert.test @@ -174,9 +174,9 @@ do_insert_tests e_insert-1.2 -error { 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} } -# EVIDENCE-OF: R-34231-22576 In this case the result of evaluating the -# left-most expression in each term of the VALUES list is inserted into -# the left-most column of the each new row, and forth for each +# EVIDENCE-OF: R-29730-42609 In this case the result of evaluating the +# left-most expression from each term of the VALUES list is inserted +# into the left-most column of each new row, and so forth for each # subsequent expression. # delete_all_data From 7f80c7146f2c32777b5d4caebb80141a07cfc4f4 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 2 Jun 2014 21:00:34 +0000 Subject: [PATCH 10/12] Remove the WHERE_LIKELIHOOD bit, as it does not seem to effect any result. FossilOrigin-Name: 1cbe7a0883e081611a50524517d70e0b6c5199d2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 2 -- src/whereInt.h | 1 - 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 83f779bee0..c9a894b1f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sa\srequirements\smark\scomment\sin\sa\stest\sscript.\s\sNo\schanges\sto\ncode. -D 2014-06-02T18:24:55.152 +C Remove\sthe\sWHERE_LIKELIHOOD\sbit,\sas\sit\sdoes\snot\sseem\sto\seffect\sany\sresult. +D 2014-06-02T21:00:34.572 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -294,8 +294,8 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 308ed08c648fb7e3d7ba5896363dd86b2a0cc616 -F src/whereInt.h 6804c2e5010378568c2bb1350477537755296a46 +F src/where.c a7d59dd5d5bf6d6ab905fb549567a0a11376de25 +F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1173,7 +1173,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 9f18b303cd1bc5779d82669884f802c7889b4947 -R d2860e47e4361323fe5044697b7809e3 +P 75ff459b06e1a5c180d316d227ce2f73c99a1f52 +R 48bae0e8ed57c3dbc05f2ecb6659ff4f U drh -Z 3c888acab84366f73445c2218a0f8a8d +Z ba8e8519c6b4bbb2b73e8471af00ac41 diff --git a/manifest.uuid b/manifest.uuid index 2dd57bbecb..9feaf6cdcf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -75ff459b06e1a5c180d316d227ce2f73c99a1f52 \ No newline at end of file +1cbe7a0883e081611a50524517d70e0b6c5199d2 \ No newline at end of file diff --git a/src/where.c b/src/where.c index ccecccb12e..f914004b25 100644 --- a/src/where.c +++ b/src/where.c @@ -4286,7 +4286,6 @@ static int whereLoopAddBtreeIndex( testcase( eOp & WO_IN ); pNew->nOut += pTerm->truthProb; pNew->nOut -= nIn; - pNew->wsFlags |= WHERE_LIKELIHOOD; }else{ #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 tRowcnt nOut = 0; @@ -4295,7 +4294,6 @@ static int whereLoopAddBtreeIndex( && pNew->u.btree.nEq<=pProbe->nSampleCol && OptimizationEnabled(db, SQLITE_Stat3) && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) - && (pNew->wsFlags & WHERE_LIKELIHOOD)==0 ){ Expr *pExpr = pTerm->pExpr; if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){ diff --git a/src/whereInt.h b/src/whereInt.h index 010cd6e8ae..72e7530db9 100644 --- a/src/whereInt.h +++ b/src/whereInt.h @@ -458,4 +458,3 @@ struct WhereInfo { #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ -#define WHERE_LIKELIHOOD 0x00020000 /* A likelihood() is affecting nOut */ From 5a0b8b124bdc75c6af5c170edb0f7045d246ff9c Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 3 Jun 2014 11:32:38 +0000 Subject: [PATCH 11/12] Add a test to double-check that [1cbe7a0883] did not affect anything. FossilOrigin-Name: c6b512a724aebcd084aad2a80d020b95773b3012 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/cost.test | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c9a894b1f1..0fb3575a64 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\sWHERE_LIKELIHOOD\sbit,\sas\sit\sdoes\snot\sseem\sto\seffect\sany\sresult. -D 2014-06-02T21:00:34.572 +C Add\sa\stest\sto\sdouble-check\sthat\s[1cbe7a0883]\sdid\snot\saffect\sanything. +D 2014-06-03T11:32:38.148 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -409,7 +409,7 @@ F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 F test/corruptG.test 1ab3bf97ee7bdba70e0ff3ba2320657df55d1804 F test/corruptH.test 88ed71a086e13591c917aac6de32750e7c7281cb F test/corruptI.test b3e4203d420490fc3d3062711597bc1dea06a789 -F test/cost.test 04842adec34311d70c3f3c5fd698b22be54138fd +F test/cost.test 19d314526616ce4473eb4e4e450fcb94499ce318 F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 F test/crash.test fb9dc4a02dcba30d4aa5c2c226f98b220b2b959f @@ -1173,7 +1173,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 75ff459b06e1a5c180d316d227ce2f73c99a1f52 -R 48bae0e8ed57c3dbc05f2ecb6659ff4f -U drh -Z ba8e8519c6b4bbb2b73e8471af00ac41 +P 1cbe7a0883e081611a50524517d70e0b6c5199d2 +R 88f7e0a0a79929d11635773b81944233 +U dan +Z 719afb30fb3906ea3990e2a028510bfb diff --git a/manifest.uuid b/manifest.uuid index 9feaf6cdcf..de0da9651b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1cbe7a0883e081611a50524517d70e0b6c5199d2 \ No newline at end of file +c6b512a724aebcd084aad2a80d020b95773b3012 \ No newline at end of file diff --git a/test/cost.test b/test/cost.test index c413c3cdfa..92fff9c888 100644 --- a/test/cost.test +++ b/test/cost.test @@ -244,6 +244,47 @@ foreach {tn nTerm nRow} { } +#------------------------------------------------------------------------- +# + +ifcapable stat4 { + do_execsql_test 10.1 { + CREATE TABLE t6(a, b, c); + CREATE INDEX t6i1 ON t6(a, b); + CREATE INDEX t6i2 ON t6(c); + } + + do_test 10.2 { + for {set i 0} {$i < 16} {incr i} { + execsql { INSERT INTO t6 VALUES($i%4, 'xyz', $i%8) } + } + execsql ANALYZE + } {} + + do_eqp_test 10.3 { + SELECT rowid FROM t6 WHERE a=0 AND c=0 + } { + 0 0 0 {SEARCH TABLE t6 USING INDEX t6i2 (c=?)} + } + + do_eqp_test 10.4 { + SELECT rowid FROM t6 WHERE a=0 AND b='xyz' AND c=0 + } { + 0 0 0 {SEARCH TABLE t6 USING INDEX t6i2 (c=?)} + } + + do_eqp_test 10.5 { + SELECT rowid FROM t6 WHERE likelihood(a=0, 0.1) AND c=0 + } { + 0 0 0 {SEARCH TABLE t6 USING INDEX t6i1 (a=?)} + } + + do_eqp_test 10.6 { + SELECT rowid FROM t6 WHERE likelihood(a=0, 0.1) AND b='xyz' AND c=0 + } { + 0 0 0 {SEARCH TABLE t6 USING INDEX t6i1 (a=? AND b=?)} + } +} finish_test From d0dc5d4984ce9ff0e155a94929db118047ef1a6d Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 3 Jun 2014 14:42:34 +0000 Subject: [PATCH 12/12] Avoid closing a pseudo-table associated with sorting in a co-routine since that pseudo-table might be used again in an outer loop. FossilOrigin-Name: 6d81805298ea882f5fee99504d5a95f1a762a90b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/select.c | 3 --- test/orderby1.test | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 0fb3575a64..20001ad2d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\sto\sdouble-check\sthat\s[1cbe7a0883]\sdid\snot\saffect\sanything. -D 2014-06-03T11:32:38.148 +C Avoid\sclosing\sa\spseudo-table\sassociated\swith\ssorting\sin\sa\sco-routine\ssince\nthat\spseudo-table\smight\sbe\sused\sagain\sin\san\souter\sloop. +D 2014-06-03T14:42:34.857 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -220,7 +220,7 @@ F src/printf.c af06f66927919730f03479fed6ae9854f73419f4 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66 F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be -F src/select.c 7df17ec5506c2427576d412bee0e6ea740e12563 +F src/select.c 6762c62e11b504aa014edceab8886495165e3a77 F src/shell.c 98ce7f52445aa0c2eac3d4553a4cdcbb6402a670 F src/sqlite.h.in a98eb3e8c86c934ea6f5bcfc6b69653dde2f4ed4 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e @@ -726,7 +726,7 @@ F test/notnull.test f8fcf58669ddba79274daa2770d61dfad8274f62 F test/null.test a8b09b8ed87852742343b33441a9240022108993 F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1 F test/openv2.test 0d3040974bf402e19b7df4b783e447289d7ab394 -F test/orderby1.test 2a6164169199ed53c99089b087ef653e480f63ac +F test/orderby1.test 12426f99518cde45f34215ca6a0ebc0e9bc5c77a F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04 F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99 F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4 @@ -1173,7 +1173,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 1cbe7a0883e081611a50524517d70e0b6c5199d2 -R 88f7e0a0a79929d11635773b81944233 -U dan -Z 719afb30fb3906ea3990e2a028510bfb +P c6b512a724aebcd084aad2a80d020b95773b3012 +R 679d3413ba6dc377c3eacd5814f0f801 +U drh +Z d6f5ccfdba8b994a53e0334e1b572467 diff --git a/manifest.uuid b/manifest.uuid index de0da9651b..40af1ce51c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6b512a724aebcd084aad2a80d020b95773b3012 \ No newline at end of file +6d81805298ea882f5fee99504d5a95f1a762a90b \ No newline at end of file diff --git a/src/select.c b/src/select.c index ba6f6551af..6ceb3fe946 100644 --- a/src/select.c +++ b/src/select.c @@ -1226,9 +1226,6 @@ static void generateSortTail( } if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn); sqlite3VdbeResolveLabel(v, addrBreak); - if( eDest==SRT_Output || eDest==SRT_Coroutine ){ - sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0); - } } /* diff --git a/test/orderby1.test b/test/orderby1.test index 30c8df2d22..e06c9f19a0 100644 --- a/test/orderby1.test +++ b/test/orderby1.test @@ -464,4 +464,22 @@ do_execsql_test 5.2 { SELECT 5 UNION ALL SELECT 3 ORDER BY 1 } {3 5} +# The following test (originally derived from a single test within fuzz.test) +# verifies that a PseudoTable cursor is not closed prematurely in a deeply +# nested query. This test caused a segfault on 3.8.5 beta. +# +do_execsql_test 6.0 { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + INSERT INTO abc VALUES(7, 8, 9); + SELECT ( + SELECT 'hardware' FROM ( + SELECT 'software' ORDER BY 'firmware' ASC, 'sportswear' DESC + ) GROUP BY 1 HAVING length(b) + ) + FROM abc; +} {hardware hardware hardware} + + finish_test