From 0c9a8e345e99a056a2f5f4a8346127a178dde1da Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 29 Aug 2013 21:26:26 +0000 Subject: [PATCH 01/22] Never leave an open file descriptor pointing into the middle of the database file if the file descriptor number is 2 or less. FossilOrigin-Name: 3426673e4659eb68dbd14a3e41d4620d748432db --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/os_unix.c | 3 +++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 86dc44c7b9..dfc119dc5e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Restore\sfix\s[f15591f802],\swhich\swas\saccidentally\sclobbered\sby\sthe\sstat4\smerge. -D 2013-08-29T14:56:14.988 +C Never\sleave\san\sopen\sfile\sdescriptor\spointing\sinto\sthe\smiddle\sof\sthe\ndatabase\sfile\sif\sthe\sfile\sdescriptor\snumber\sis\s2\sor\sless. +D 2013-08-29T21:26:26.071 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -202,7 +202,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c c27a14a05061e4e690bd3949dc0246bda35e399d +F src/os_unix.c 94c7edbd75b0fb4fe477ccb3ba73a9bddaff9592 F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c @@ -1109,7 +1109,10 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P c1152bdcbb5ac185f743015fff63769effa81b4b -R ef3cf6caed80e05bf3e44c08e4ed05a0 -U dan -Z a6b4620a23effa55e7cb7c1762a8f7ee +P d4b6ad3333cc3bad500c2ebf7a6ea552b6762b69 +R 97c4ef1fd2ecd2ffa8c4e00f7258a86d +T *branch * overwrite-avoidance +T *sym-overwrite-avoidance * +T -sym-trunk * +U drh +Z c59ed8dd8c6786bd9c8e9cf6a1823506 diff --git a/manifest.uuid b/manifest.uuid index 9346487f5c..147586abe5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d4b6ad3333cc3bad500c2ebf7a6ea552b6762b69 \ No newline at end of file +3426673e4659eb68dbd14a3e41d4620d748432db \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 580f8e60e7..32201c988e 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -588,6 +588,7 @@ static int robust_open(const char *z, int f, mode_t m){ osFchmod(fd, m); } } + if( fd<=2 ) lseek(fd, 0, SEEK_END); #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); #endif @@ -3133,6 +3134,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ pBuf = (void*)(got + (char*)pBuf); } }while( got>0 ); + if( id->h<=2 ) lseek(id->h, 0, SEEK_END); TIMER_END; OSTRACE(("READ %-3d %5d %7lld %llu\n", id->h, got+prior, offset-prior, TIMER_ELAPSED)); @@ -3232,6 +3234,7 @@ static int seekAndWriteFd( rc = osWrite(fd, pBuf, nBuf); }while( rc<0 && errno==EINTR ); #endif + if( fd<=2 ) lseek(fd, 0, SEEK_END); TIMER_END; OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED)); From 35a0379a050250fb269fb4cab93c3ea2e0783892 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 29 Aug 2013 23:34:53 +0000 Subject: [PATCH 02/22] Change the unix VFS so that it refuses to open a database file using a file descriptor less than 3. FossilOrigin-Name: 66dddda06898abbf97fe0ac6a10ce1527ca8605e --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/os_unix.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index dfc119dc5e..de5d40e963 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Never\sleave\san\sopen\sfile\sdescriptor\spointing\sinto\sthe\smiddle\sof\sthe\ndatabase\sfile\sif\sthe\sfile\sdescriptor\snumber\sis\s2\sor\sless. -D 2013-08-29T21:26:26.071 +C Change\sthe\sunix\sVFS\sso\sthat\sit\srefuses\sto\sopen\sa\sdatabase\sfile\susing\na\sfile\sdescriptor\sless\sthan\s3. +D 2013-08-29T23:34:53.402 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -202,7 +202,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c 94c7edbd75b0fb4fe477ccb3ba73a9bddaff9592 +F src/os_unix.c 45d425550a86e6464b494574df43b6e2efc98003 F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c @@ -1109,10 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P d4b6ad3333cc3bad500c2ebf7a6ea552b6762b69 -R 97c4ef1fd2ecd2ffa8c4e00f7258a86d -T *branch * overwrite-avoidance -T *sym-overwrite-avoidance * -T -sym-trunk * +P 3426673e4659eb68dbd14a3e41d4620d748432db +R fe0bcec8f0ab9128b1355459470b05e0 U drh -Z c59ed8dd8c6786bd9c8e9cf6a1823506 +Z 4edcc0d4a963da6c4b3d4505d80b9383 diff --git a/manifest.uuid b/manifest.uuid index 147586abe5..92e6bed271 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3426673e4659eb68dbd14a3e41d4620d748432db \ No newline at end of file +66dddda06898abbf97fe0ac6a10ce1527ca8605e \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 32201c988e..a90c8eede5 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -551,6 +551,31 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ return 0; } +/* +** If fd is a file descriptor that would be dangerous to use for an +** ordinary file, the close it, reopen it as /dev/null to get it out +** of the way, then return true. +** +** If fd is safe, return 0. +** +** It is dangerous to have a database file open of file descriptors 1 or +** 2 because those normally mean standard output and standard error. Other +** components of the system might write directly to those file descriptors +** and overwrite parts of the database file. Something like this happened +** on 2013-08-29 to the canonical Fossil repository when some error caused +** the database file to be opened on file descriptor 2 and later an assert() +** fired and wrote error message text into file descriptor 2, corrupting +** the repository. +*/ +static int isReservedFd(int fd, const char *z, int f, int m){ + if( fd<0 || fd>2 ) return 0; + sqlite3_log(SQLITE_WARNING, + "attempt to open \"%s\" as file descriptor %d", z, fd); + osClose(fd); + (void)osOpen("/dev/null",f,m); + return 1; +} + /* ** Invoke open(). Do so multiple times, until it either succeeds or ** fails for some reason other than EINTR. @@ -577,7 +602,7 @@ static int robust_open(const char *z, int f, mode_t m){ #else fd = osOpen(z,f,m2); #endif - }while( fd<0 && errno==EINTR ); + }while( (fd<0 && errno==EINTR) || isReservedFd(fd,z,f,m2) ); if( fd>=0 ){ if( m!=0 ){ struct stat statbuf; @@ -588,7 +613,6 @@ static int robust_open(const char *z, int f, mode_t m){ osFchmod(fd, m); } } - if( fd<=2 ) lseek(fd, 0, SEEK_END); #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); #endif @@ -3100,6 +3124,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ #endif TIMER_START; assert( cnt==(cnt&0x1ffff) ); + assert( id->h>2 ); cnt &= 0x1ffff; do{ #if defined(USE_PREAD) @@ -3134,7 +3159,6 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ pBuf = (void*)(got + (char*)pBuf); } }while( got>0 ); - if( id->h<=2 ) lseek(id->h, 0, SEEK_END); TIMER_END; OSTRACE(("READ %-3d %5d %7lld %llu\n", id->h, got+prior, offset-prior, TIMER_ELAPSED)); @@ -3215,6 +3239,7 @@ static int seekAndWriteFd( int rc = 0; /* Value returned by system call */ assert( nBuf==(nBuf&0x1ffff) ); + assert( fd>2 ); nBuf &= 0x1ffff; TIMER_START; @@ -3234,7 +3259,6 @@ static int seekAndWriteFd( rc = osWrite(fd, pBuf, nBuf); }while( rc<0 && errno==EINTR ); #endif - if( fd<=2 ) lseek(fd, 0, SEEK_END); TIMER_END; OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED)); From 5128d009c6259bc2c0d7ef9dd99da368c43c08e8 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 30 Aug 2013 06:20:23 +0000 Subject: [PATCH 03/22] Improvements to the robust_open() logic in the unix VFS so that if an attempt is made to open a repository on file descriptors 0, 1, or 2, and blocking that file descriptor by opening it on /dev/null fails, then the open will fail. FossilOrigin-Name: d9c018f8155ab48df8e0e02519bba50588fe49fc --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 39 ++++++++++++--------------------------- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/manifest b/manifest index aba50366ba..dcc9ba19af 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\sunix\sVFS\sdefensive\sagainst\sthe\serror\sof\shaving\sa\sdatabase\sfile\sopen\non\sfile\sdescriptors\s1\sor\s2,\sas\san\serror\smessage\smight\seasily\sbe\swritten\sonto\nthose\sfile\sdescriptors\sand\sthus\soverwrite\sand\scorrupt\sthe\sdatabase. -D 2013-08-29T23:36:49.784 +C Improvements\sto\sthe\srobust_open()\slogic\sin\sthe\sunix\sVFS\sso\sthat\sif\san\sattempt\nis\smade\sto\sopen\sa\srepository\son\sfile\sdescriptors\s0,\s1,\sor\s2,\sand\sblocking\nthat\sfile\sdescriptor\sby\sopening\sit\son\s/dev/null\sfails,\sthen\sthe\sopen\swill\nfail. +D 2013-08-30T06:20:23.091 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -202,7 +202,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c 45d425550a86e6464b494574df43b6e2efc98003 +F src/os_unix.c 81271e38084e74ddc6602ee5a80ea0a7d5dfacf9 F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P d4b6ad3333cc3bad500c2ebf7a6ea552b6762b69 66dddda06898abbf97fe0ac6a10ce1527ca8605e -R fe0bcec8f0ab9128b1355459470b05e0 +P 30d38cc44904d93508b87e373b2f45d5f93e556b +R f7758c6eac86fc614b8a8bb0a78752f4 U drh -Z 9dc425ab0a1c3ed5b98a1a49ce3d4048 +Z 3dd4af0a8c411dcbaa133c8880e5be77 diff --git a/manifest.uuid b/manifest.uuid index d0b72f4090..70f0bca9ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30d38cc44904d93508b87e373b2f45d5f93e556b \ No newline at end of file +d9c018f8155ab48df8e0e02519bba50588fe49fc \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index a90c8eede5..8688a652f5 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -551,31 +551,6 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ return 0; } -/* -** If fd is a file descriptor that would be dangerous to use for an -** ordinary file, the close it, reopen it as /dev/null to get it out -** of the way, then return true. -** -** If fd is safe, return 0. -** -** It is dangerous to have a database file open of file descriptors 1 or -** 2 because those normally mean standard output and standard error. Other -** components of the system might write directly to those file descriptors -** and overwrite parts of the database file. Something like this happened -** on 2013-08-29 to the canonical Fossil repository when some error caused -** the database file to be opened on file descriptor 2 and later an assert() -** fired and wrote error message text into file descriptor 2, corrupting -** the repository. -*/ -static int isReservedFd(int fd, const char *z, int f, int m){ - if( fd<0 || fd>2 ) return 0; - sqlite3_log(SQLITE_WARNING, - "attempt to open \"%s\" as file descriptor %d", z, fd); - osClose(fd); - (void)osOpen("/dev/null",f,m); - return 1; -} - /* ** Invoke open(). Do so multiple times, until it either succeeds or ** fails for some reason other than EINTR. @@ -596,13 +571,23 @@ static int isReservedFd(int fd, const char *z, int f, int m){ static int robust_open(const char *z, int f, mode_t m){ int fd; mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS; - do{ + while(1){ #if defined(O_CLOEXEC) fd = osOpen(z,f|O_CLOEXEC,m2); #else fd = osOpen(z,f,m2); #endif - }while( (fd<0 && errno==EINTR) || isReservedFd(fd,z,f,m2) ); + if( fd<0 ){ + if( errno==EINTR ) continue; + break; + } + if( fd>2 ) break; + osClose(fd); + sqlite3_log(SQLITE_WARNING, + "attempt to open \"%s\" as file descriptor %d", z, fd); + fd = -1; + if( osOpen("/dev/null", f, m)<0 ) break; + } if( fd>=0 ){ if( m!=0 ){ struct stat statbuf; From 43398081a87710d1a83e3ca35d2e93fa8e5ce8f0 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 30 Aug 2013 13:29:51 +0000 Subject: [PATCH 04/22] Add a test for fts4 unicode61 option remove_diacritics=0. FossilOrigin-Name: 6bf7ae6ff6b18712544ddeafb6848b3b27ff22d2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fts4unicode.test | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index dcc9ba19af..5c27035d74 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\srobust_open()\slogic\sin\sthe\sunix\sVFS\sso\sthat\sif\san\sattempt\nis\smade\sto\sopen\sa\srepository\son\sfile\sdescriptors\s0,\s1,\sor\s2,\sand\sblocking\nthat\sfile\sdescriptor\sby\sopening\sit\son\s/dev/null\sfails,\sthen\sthe\sopen\swill\nfail. -D 2013-08-30T06:20:23.091 +C Add\sa\stest\sfor\sfts4\sunicode61\soption\sremove_diacritics=0. +D 2013-08-30T13:29:51.754 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -557,7 +557,7 @@ F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891 F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7 F test/fts4merge4.test c19c85ca1faa7b6d536832b49c12e1867235f584 F test/fts4noti.test aed33ba44808852dcb24bf70fa132e7bf530f057 -F test/fts4unicode.test c8ac44217bf6c17812b03eaafa6c06995ad304c2 +F test/fts4unicode.test 5fa8e0a7899d906d114345c605250ebfa9d8ed28 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/func.test cd25cf605c5a345d038dc7b84232204c6a901c84 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 30d38cc44904d93508b87e373b2f45d5f93e556b -R f7758c6eac86fc614b8a8bb0a78752f4 -U drh -Z 3dd4af0a8c411dcbaa133c8880e5be77 +P d9c018f8155ab48df8e0e02519bba50588fe49fc +R ea091c59207c769dfe7c01daedbc5f93 +U dan +Z c2684be8ef49bf7c2f428934c35768a0 diff --git a/manifest.uuid b/manifest.uuid index 70f0bca9ea..47941bce42 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d9c018f8155ab48df8e0e02519bba50588fe49fc \ No newline at end of file +6bf7ae6ff6b18712544ddeafb6848b3b27ff22d2 \ No newline at end of file diff --git a/test/fts4unicode.test b/test/fts4unicode.test index aee7f05b1b..8149bb172d 100644 --- a/test/fts4unicode.test +++ b/test/fts4unicode.test @@ -402,5 +402,40 @@ foreach {tn1 c} { } } +#------------------------------------------------------------------------- +# Cursory test of remove_diacritics=0. +# +# 00C4;LATIN CAPITAL LETTER A WITH DIAERESIS +# 00D6;LATIN CAPITAL LETTER O WITH DIAERESIS +# 00E4;LATIN SMALL LETTER A WITH DIAERESIS +# 00F6;LATIN SMALL LETTER O WITH DIAERESIS +# +do_execsql_test 8.1.1 " + CREATE VIRTUAL TABLE t3 USING fts4(tokenize=unicode61 'remove_diacritics=1'); + INSERT INTO t3 VALUES('o'); + INSERT INTO t3 VALUES('a'); + INSERT INTO t3 VALUES('O'); + INSERT INTO t3 VALUES('A'); + INSERT INTO t3 VALUES('\xD6'); + INSERT INTO t3 VALUES('\xC4'); + INSERT INTO t3 VALUES('\xF6'); + INSERT INTO t3 VALUES('\xE4'); +" +do_execsql_test 8.1.2 { + SELECT rowid FROM t3 WHERE t3 MATCH 'o'; +} {1 3 5 7} +do_execsql_test 8.1.3 { + SELECT rowid FROM t3 WHERE t3 MATCH 'a'; +} {2 4 6 8} +do_execsql_test 8.2.1 { + CREATE VIRTUAL TABLE t4 USING fts4(tokenize=unicode61 "remove_diacritics=0"); + INSERT INTO t4 SELECT * FROM t3; +} +do_execsql_test 8.2.2 { + SELECT rowid FROM t4 WHERE t4 MATCH 'o'; +} {1 3} +do_execsql_test 8.2.3 { + SELECT rowid FROM t4 WHERE t4 MATCH 'a'; +} {2 4} finish_test From 77a3fdc1b063dd3775fa1da843d5cc404fdf3f1c Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 30 Aug 2013 14:24:12 +0000 Subject: [PATCH 05/22] Add the SQLITE_MINIMUM_FILE_DESCRIPTOR compile-time option, for control over exactly which low-numbered file descriptors SQLite will use. FossilOrigin-Name: ba5190534330a25722eeb7ea9c42da7a6d146014 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 11 ++++++++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 5c27035d74..56b314ac29 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\sfor\sfts4\sunicode61\soption\sremove_diacritics=0. -D 2013-08-30T13:29:51.754 +C Add\sthe\sSQLITE_MINIMUM_FILE_DESCRIPTOR\scompile-time\soption,\sfor\scontrol\sover\nexactly\swhich\slow-numbered\sfile\sdescriptors\sSQLite\swill\suse. +D 2013-08-30T14:24:12.062 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -202,7 +202,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c 81271e38084e74ddc6602ee5a80ea0a7d5dfacf9 +F src/os_unix.c 7d5f3c51db561804e3ff3d47970a58bc6ea4d662 F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P d9c018f8155ab48df8e0e02519bba50588fe49fc -R ea091c59207c769dfe7c01daedbc5f93 -U dan -Z c2684be8ef49bf7c2f428934c35768a0 +P 6bf7ae6ff6b18712544ddeafb6848b3b27ff22d2 +R f869b9c4782ea4938d88f3fd8f2e185a +U drh +Z 55a1a5eb28d49163aa7c79ea9937ef28 diff --git a/manifest.uuid b/manifest.uuid index 47941bce42..cbc2987dde 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6bf7ae6ff6b18712544ddeafb6848b3b27ff22d2 \ No newline at end of file +ba5190534330a25722eeb7ea9c42da7a6d146014 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 8688a652f5..797ace031d 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -551,6 +551,15 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ return 0; } +/* +** Do not accept any file descriptor less than this value, in order to avoid +** opening database file using file descriptors that are commonly used for +** standard input, output, and error. +*/ +#ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR +# define SQLITE_MINIMUM_FILE_DESCRIPTOR 3 +#endif + /* ** Invoke open(). Do so multiple times, until it either succeeds or ** fails for some reason other than EINTR. @@ -581,7 +590,7 @@ static int robust_open(const char *z, int f, mode_t m){ if( errno==EINTR ) continue; break; } - if( fd>2 ) break; + if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; osClose(fd); sqlite3_log(SQLITE_WARNING, "attempt to open \"%s\" as file descriptor %d", z, fd); From f46af73720a6478e0f54b4769ba1907a988ce72d Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 30 Aug 2013 17:35:44 +0000 Subject: [PATCH 06/22] If the cost of two whereLoop objects is the same in every way except that one has fewer expected output rows than the other, then choose the one with fewer output rows. FossilOrigin-Name: 79e458ef7acfddbc189163e3e958da529becb130 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 10 +++++++--- test/whereF.test | 7 +++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 56b314ac29..40b0c08cea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_MINIMUM_FILE_DESCRIPTOR\scompile-time\soption,\sfor\scontrol\sover\nexactly\swhich\slow-numbered\sfile\sdescriptors\sSQLite\swill\suse. -D 2013-08-30T14:24:12.062 +C If\sthe\scost\sof\stwo\swhereLoop\sobjects\sis\sthe\ssame\sin\severy\sway\sexcept\sthat\none\shas\sfewer\sexpected\soutput\srows\sthan\sthe\sother,\sthen\schoose\sthe\sone\swith\nfewer\soutput\srows. +D 2013-08-30T17:35:44.308 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c cad6497f79307c2c94aaf72e64866bb33cf99d59 +F src/where.c 97fc542b38b3816c9b52cc2b2f0463e1de764d94 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1056,7 +1056,7 @@ F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test d6f4ecd4fa2d9429681a5b22a25d2bda8e86ab8a F test/whereD.test 6c2feb79ef1f68381b07f39017fe5f9b96da8d62 F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f -F test/whereF.test 136a7301512d72a08a272806c8767066311b7bc1 +F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 6bf7ae6ff6b18712544ddeafb6848b3b27ff22d2 -R f869b9c4782ea4938d88f3fd8f2e185a +P ba5190534330a25722eeb7ea9c42da7a6d146014 +R 1b70f1acf0bcfec841a600fcdc82af8f U drh -Z 55a1a5eb28d49163aa7c79ea9937ef28 +Z 482da10fef5b3db6e155cce4ef946cbe diff --git a/manifest.uuid b/manifest.uuid index cbc2987dde..5128d39ea5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ba5190534330a25722eeb7ea9c42da7a6d146014 \ No newline at end of file +79e458ef7acfddbc189163e3e958da529becb130 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 9e3a72e2d8..fc67b0ec06 100644 --- a/src/where.c +++ b/src/where.c @@ -4169,9 +4169,11 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ if( (p->prereq & pTemplate->prereq)==p->prereq && p->rSetup<=pTemplate->rSetup && p->rRun<=pTemplate->rRun + && p->nOut<=pTemplate->nOut ){ /* This branch taken when p is equal or better than pTemplate in - ** all of (1) dependences (2) setup-cost, and (3) run-cost. */ + ** all of (1) dependences (2) setup-cost, (3) run-cost, and + ** (4) number of output rows. */ assert( p->rSetup==pTemplate->rSetup ); if( p->nLTermnLTerm && (p->wsFlags & WHERE_INDEXED)!=0 @@ -4191,11 +4193,13 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ } if( (p->prereq & pTemplate->prereq)==pTemplate->prereq && p->rRun>=pTemplate->rRun + && p->nOut>=pTemplate->nOut && ALWAYS(p->rSetup>=pTemplate->rSetup) /* See SETUP-INVARIANT above */ ){ /* Overwrite an existing WhereLoop with a better one: one that is - ** better at one of (1) dependences, (2) setup-cost, or (3) run-cost - ** and is no worse in any of those categories. */ + ** better at one of (1) dependences, (2) setup-cost, (3) run-cost + ** or (4) number of output rows, and is no worse in any of those + ** categories. */ pNext = p->pNextLoop; break; } diff --git a/test/whereF.test b/test/whereF.test index c98312a262..b9580bb196 100644 --- a/test/whereF.test +++ b/test/whereF.test @@ -112,4 +112,11 @@ foreach {tn sql} { } {/.*SCAN TABLE t2\y.*SEARCH TABLE t1\y.*/} } +do_execsql_test 4.0 { + CREATE TABLE t4(a,b,c,d,e, PRIMARY KEY(a,b,c)); + CREATE INDEX t4adc ON t4(a,d,c); + CREATE UNIQUE INDEX t4aebc ON t4(a,e,b,c); + EXPLAIN QUERY PLAN SELECT rowid FROM t4 WHERE a=? AND b=?; +} {/a=. AND b=./} + finish_test From e56dd3ad7b8d9df78597ad610e6fa57bffc3c9a2 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 30 Aug 2013 17:50:35 +0000 Subject: [PATCH 07/22] Fix comment typos in the where.c module. No code changes. FossilOrigin-Name: 1e0b77cf0edf3d26f76d83aa5466e9ec0e60a710 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 40b0c08cea..088690155d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\scost\sof\stwo\swhereLoop\sobjects\sis\sthe\ssame\sin\severy\sway\sexcept\sthat\none\shas\sfewer\sexpected\soutput\srows\sthan\sthe\sother,\sthen\schoose\sthe\sone\swith\nfewer\soutput\srows. -D 2013-08-30T17:35:44.308 +C Fix\scomment\stypos\sin\sthe\swhere.c\smodule.\s\sNo\scode\schanges. +D 2013-08-30T17:50:35.740 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 97fc542b38b3816c9b52cc2b2f0463e1de764d94 +F src/where.c 83f6106e0edfa23d1258c617cd58e3125277a363 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ba5190534330a25722eeb7ea9c42da7a6d146014 -R 1b70f1acf0bcfec841a600fcdc82af8f +P 79e458ef7acfddbc189163e3e958da529becb130 +R 11e0df2697ccef8d248e0028842ddb62 U drh -Z 482da10fef5b3db6e155cce4ef946cbe +Z 34db069768d39fa7815ab1043f1fae87 diff --git a/manifest.uuid b/manifest.uuid index 5128d39ea5..f13affc075 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -79e458ef7acfddbc189163e3e958da529becb130 \ No newline at end of file +1e0b77cf0edf3d26f76d83aa5466e9ec0e60a710 \ No newline at end of file diff --git a/src/where.c b/src/where.c index fc67b0ec06..235277d63d 100644 --- a/src/where.c +++ b/src/where.c @@ -185,9 +185,9 @@ static int whereLoopResize(sqlite3*, WhereLoop*, int); ** that implement some or all of a query plan. ** ** Think of each WhereLoop object as a node in a graph with arcs -** showing dependences and costs for travelling between nodes. (That is +** showing dependencies and costs for travelling between nodes. (That is ** not a completely accurate description because WhereLoop costs are a -** vector, not a scalar, and because dependences are many-to-one, not +** vector, not a scalar, and because dependencies are many-to-one, not ** one-to-one as are graph nodes. But it is a useful visualization aid.) ** Then a WherePath object is a path through the graph that visits some ** or all of the WhereLoop objects once. @@ -4172,7 +4172,7 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ && p->nOut<=pTemplate->nOut ){ /* This branch taken when p is equal or better than pTemplate in - ** all of (1) dependences (2) setup-cost, (3) run-cost, and + ** all of (1) dependencies (2) setup-cost, (3) run-cost, and ** (4) number of output rows. */ assert( p->rSetup==pTemplate->rSetup ); if( p->nLTermnLTerm @@ -4197,7 +4197,7 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ && ALWAYS(p->rSetup>=pTemplate->rSetup) /* See SETUP-INVARIANT above */ ){ /* Overwrite an existing WhereLoop with a better one: one that is - ** better at one of (1) dependences, (2) setup-cost, (3) run-cost + ** better at one of (1) dependencies, (2) setup-cost, (3) run-cost ** or (4) number of output rows, and is no worse in any of those ** categories. */ pNext = p->pNextLoop; From 79e8445f63e8807632b52ecb14f9d4be2fa266a8 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 30 Aug 2013 19:59:48 +0000 Subject: [PATCH 08/22] Fix comment typo in analyze.c. No changes to code. FossilOrigin-Name: dbc31750440226702fbf88f1bf6140ef403c9be1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/analyze.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 088690155d..5348607766 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scomment\stypos\sin\sthe\swhere.c\smodule.\s\sNo\scode\schanges. -D 2013-08-30T17:50:35.740 +C Fix\scomment\stypo\sin\sanalyze.c.\sNo\schanges\sto\scode. +D 2013-08-30T19:59:48.378 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -157,7 +157,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 2af0330bb1b601af7a7789bf7229675fd772a083 -F src/analyze.c 7f869a251f3d58d3b95883eeae425d4ee17a66bd +F src/analyze.c be10d32609e8228b14069aa879f259f3be5437b6 F src/attach.c fea00cab11c854646a27641a263f5876569a51f9 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 2f1987981139bd2f6d8c728d64bf09fb387443c3 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 79e458ef7acfddbc189163e3e958da529becb130 -R 11e0df2697ccef8d248e0028842ddb62 -U drh -Z 34db069768d39fa7815ab1043f1fae87 +P 1e0b77cf0edf3d26f76d83aa5466e9ec0e60a710 +R 0c643291a27e5ba88460789684f4b782 +U mistachkin +Z 1a1cfa9c3206e22f52ca4af3c75be88f diff --git a/manifest.uuid b/manifest.uuid index f13affc075..3302345cb0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e0b77cf0edf3d26f76d83aa5466e9ec0e60a710 \ No newline at end of file +dbc31750440226702fbf88f1bf6140ef403c9be1 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 46ebac4c3a..25bf5ca4a4 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -33,7 +33,7 @@ ** version of sqlite_stat3 and is only available when compiled with ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.0 and later. It is ** not possible to enable both STAT3 and STAT4 at the same time. If they -** are both enabled, then STAT4 is precedence. +** are both enabled, then STAT4 takes precedence. ** ** For most applications, sqlite_stat1 provides all the statisics required ** for the query planner to make good choices. From ad4c7aa10fd8563550a0465879cab5a1bbea04bb Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 30 Aug 2013 20:19:52 +0000 Subject: [PATCH 09/22] Fix compiler warnings in analyze.c. FossilOrigin-Name: 5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/analyze.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 5348607766..9b210d3d88 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scomment\stypo\sin\sanalyze.c.\sNo\schanges\sto\scode. -D 2013-08-30T19:59:48.378 +C Fix\scompiler\swarnings\sin\sanalyze.c. +D 2013-08-30T20:19:52.698 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -157,7 +157,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 2af0330bb1b601af7a7789bf7229675fd772a083 -F src/analyze.c be10d32609e8228b14069aa879f259f3be5437b6 +F src/analyze.c 128f85d9bd7e79e93b8b27aa2bb54a43ad0c00f3 F src/attach.c fea00cab11c854646a27641a263f5876569a51f9 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 2f1987981139bd2f6d8c728d64bf09fb387443c3 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 1e0b77cf0edf3d26f76d83aa5466e9ec0e60a710 -R 0c643291a27e5ba88460789684f4b782 -U mistachkin -Z 1a1cfa9c3206e22f52ca4af3c75be88f +P dbc31750440226702fbf88f1bf6140ef403c9be1 +R 5df52e9a380e1241cf1df8d1d5fbe7ea +U dan +Z 33fcbfc1bf7d299e3e7e4e929460c0cd diff --git a/manifest.uuid b/manifest.uuid index 3302345cb0..e0a1d44337 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dbc31750440226702fbf88f1bf6140ef403c9be1 \ No newline at end of file +5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 25bf5ca4a4..d70f77e779 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -345,7 +345,7 @@ static void statInit( p->iGet = -1; p->mxSample = mxSample; - p->nPSample = sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1; + p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1); p->current.anLt = &p->current.anEq[nColUp]; sqlite3_randomness(sizeof(p->iPrn), &p->iPrn); @@ -424,7 +424,7 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){ Stat4Sample *pSample; int i; i64 iSeq; - i64 iPos; + int iPos; assert( IsStat4 || nEqZero==0 ); @@ -1333,7 +1333,7 @@ static void initAvgEq(Index *pIdx){ for(iCol=0; iColnColumn; iCol++){ int i; /* Used to iterate through samples */ tRowcnt sumEq = 0; /* Sum of the nEq values */ - int nSum = 0; /* Number of terms contributing to sumEq */ + tRowcnt nSum = 0; /* Number of terms contributing to sumEq */ tRowcnt avgEq = 0; tRowcnt nDLt = pFinal->anDLt[iCol]; From d95a3d3527d6d3db37759cdbda7850fdd52c1090 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 30 Aug 2013 21:52:38 +0000 Subject: [PATCH 10/22] Add support for Cygwin when handling temporary file names. Improve error codes and diagnostic messages for temporary file name handling on Windows. Rename winConvertUtf8Filename to winConvertFromUtf8Filename. Improve placement and comments for forward function declarations. FossilOrigin-Name: a411df725153119acb3bcf44fb71deecaa307887 --- manifest | 23 ++++---- manifest.uuid | 2 +- src/main.c | 2 + src/os_unix.c | 4 +- src/os_win.c | 151 ++++++++++++++++++++++++++++++++++++++++++------ src/sqlite.h.in | 2 + 6 files changed, 154 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index 9b210d3d88..40a9efb0be 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scompiler\swarnings\sin\sanalyze.c. -D 2013-08-30T20:19:52.698 +C Add\ssupport\sfor\sCygwin\swhen\shandling\stemporary\sfile\snames.\s\sImprove\serror\scodes\sand\sdiagnostic\smessages\sfor\stemporary\sfile\sname\shandling\son\sWindows.\s\sRename\swinConvertUtf8Filename\sto\swinConvertFromUtf8Filename.\s\sImprove\splacement\sand\scomments\sfor\sforward\sfunction\sdeclarations. +D 2013-08-30T21:52:38.235 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -185,7 +185,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c dc02c7c118d58049e0cccc6c9c47c0a4d3e2bcda +F src/main.c c4c781b06faa2ce4040c32a75fd931a07ba7054e F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -202,8 +202,8 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c 7d5f3c51db561804e3ff3d47970a58bc6ea4d662 -F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5 +F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6 +F src/os_win.c 8e87c2718975bc3cd8d86bf3ff2cc3bbafbc7eaf F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f @@ -218,7 +218,7 @@ F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c dbe064d404bb497acd8a44c066cd6b8460a71236 -F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff +F src/sqlite.h.in ec40aa958a270416fb04b4f72210357bf163d2c5 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqliteInt.h 600086a5082e2291b0aeeefcfbb546f2bbda67b2 @@ -1109,7 +1109,10 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P dbc31750440226702fbf88f1bf6140ef403c9be1 -R 5df52e9a380e1241cf1df8d1d5fbe7ea -U dan -Z 33fcbfc1bf7d299e3e7e4e929460c0cd +P 5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 +R 72dd46cadd0f990a967d544f6edf59de +T *branch * cygwinTempPath +T *sym-cygwinTempPath * +T -sym-trunk * +U mistachkin +Z 23133362076223f26c27390373169480 diff --git a/manifest.uuid b/manifest.uuid index e0a1d44337..44a442d40d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 \ No newline at end of file +a411df725153119acb3bcf44fb71deecaa307887 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 7e817e5953..4697009666 100644 --- a/src/main.c +++ b/src/main.c @@ -1107,6 +1107,7 @@ const char *sqlite3ErrName(int rc){ case SQLITE_IOERR_DELETE_NOENT: zName = "SQLITE_IOERR_DELETE_NOENT";break; case SQLITE_IOERR_MMAP: zName = "SQLITE_IOERR_MMAP"; break; case SQLITE_IOERR_GETTEMPPATH: zName = "SQLITE_IOERR_GETTEMPPATH"; break; + case SQLITE_IOERR_CONVPATH: zName = "SQLITE_IOERR_CONVPATH"; break; case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break; case SQLITE_CORRUPT_VTAB: zName = "SQLITE_CORRUPT_VTAB"; break; case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break; @@ -1115,6 +1116,7 @@ const char *sqlite3ErrName(int rc){ case SQLITE_CANTOPEN_NOTEMPDIR: zName = "SQLITE_CANTOPEN_NOTEMPDIR";break; case SQLITE_CANTOPEN_ISDIR: zName = "SQLITE_CANTOPEN_ISDIR"; break; case SQLITE_CANTOPEN_FULLPATH: zName = "SQLITE_CANTOPEN_FULLPATH"; break; + case SQLITE_CANTOPEN_CONVPATH: zName = "SQLITE_CANTOPEN_CONVPATH"; break; case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break; diff --git a/src/os_unix.c b/src/os_unix.c index 797ace031d..cd8cec0046 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -5338,6 +5338,7 @@ static int fillInUnixFile( */ static const char *unixTempFileDir(void){ static const char *azDirs[] = { + 0, 0, 0, "/var/tmp", @@ -5350,7 +5351,8 @@ static const char *unixTempFileDir(void){ const char *zDir = 0; azDirs[0] = sqlite3_temp_directory; - if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); + if( !azDirs[1] ) azDirs[1] = getenv("SQLITE_TMPDIR"); + if( !azDirs[2] ) azDirs[2] = getenv("TMPDIR"); for(i=0; i0 -/* Forward references to VFS methods */ +/* Forward references to VFS helper methods used for memory mapped files */ +static int winMapfile(winFile*, sqlite3_int64); static int winUnmapfile(winFile*); #endif @@ -2870,11 +2871,10 @@ static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){ } } -/* Forward declaration */ +/* Forward references to VFS helper methods used for temporary files */ static int winGetTempname(sqlite3_vfs *, char **); -#if SQLITE_MAX_MMAP_SIZE>0 -static int winMapfile(winFile*, sqlite3_int64); -#endif +static int winIsDir(const void *); +static BOOL winIsDriveLetterAndColon(const char *); /* ** Control and query of the open file handle. @@ -3909,13 +3909,32 @@ static const sqlite3_io_methods winIoMethod = { ** sqlite3_vfs object. */ +/* +** Convert a filename from whatever the underlying operating system +** supports for filenames into UTF-8. Space to hold the result is +** obtained from malloc and must be freed by the calling function. +*/ +static char *winConvertToUtf8Filename(const void *zFilename){ + char *zConverted = 0; + if( osIsNT() ){ + zConverted = winUnicodeToUtf8(zFilename); + } +#ifdef SQLITE_WIN32_HAS_ANSI + else{ + zConverted = sqlite3_win32_mbcs_to_utf8(zFilename); + } +#endif + /* caller will handle out of memory */ + return zConverted; +} + /* ** Convert a UTF-8 filename into whatever form the underlying ** operating system wants filenames in. Space to hold the result ** is obtained from malloc and must be freed by the calling ** function. */ -static void *winConvertUtf8Filename(const char *zFilename){ +static void *winConvertFromUtf8Filename(const char *zFilename){ void *zConverted = 0; if( osIsNT() ){ zConverted = winUtf8ToUnicode(zFilename); @@ -3980,7 +3999,90 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){ winEndsInDirSep(sqlite3_temp_directory) ? "" : winGetDirDep()); } -#if !SQLITE_OS_WINRT +#if defined(__CYGWIN__) + else{ + static const char *azDirs[] = { + 0, /* getenv("SQLITE_TMPDIR") */ + 0, /* getenv("TMPDIR") */ + 0, /* getenv("TMP") */ + 0, /* getenv("TEMP") */ + 0, /* getenv("USERPROFILE") */ + "/var/tmp", + "/usr/tmp", + "/tmp", + 0 /* List terminator */ + }; + unsigned int i; + const char *zDir = 0; + + if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); + if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); + if( !azDirs[2] ) azDirs[2] = getenv("TMP"); + if( !azDirs[3] ) azDirs[3] = getenv("TEMP"); + if( !azDirs[4] ) azDirs[4] = getenv("USERPROFILE"); + for(i=0; imxPathname+1)<0 ){ - winLogError(SQLITE_CANTOPEN_FULLPATH, (DWORD)errno, "cygwin_conv_path", + winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, "winFullPathname", zRelative); sqlite3_free(zOut); - return SQLITE_CANTOPEN_FULLPATH; + return SQLITE_CANTOPEN_CONVPATH; } sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s", sqlite3_data_directory, winGetDirDep(), zOut); sqlite3_free(zOut); }else{ if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){ - winLogError(SQLITE_CANTOPEN_FULLPATH, (DWORD)errno, "cygwin_conv_path", + winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, "winFullPathname", zRelative); - return SQLITE_CANTOPEN_FULLPATH; + return SQLITE_CANTOPEN_CONVPATH; } } return SQLITE_OK; @@ -4700,7 +4815,7 @@ static int winFullPathname( sqlite3_data_directory, winGetDirDep(), zRelative); return SQLITE_OK; } - zConverted = winConvertUtf8Filename(zRelative); + zConverted = winConvertFromUtf8Filename(zRelative); if( zConverted==0 ){ return SQLITE_IOERR_NOMEM; } @@ -4781,7 +4896,7 @@ static int winFullPathname( */ static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ HANDLE h; - void *zConverted = winConvertUtf8Filename(zFilename); + void *zConverted = winConvertFromUtf8Filename(zFilename); UNUSED_PARAMETER(pVfs); if( zConverted==0 ){ return 0; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index fc76029bcb..1e5a3f22a4 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -474,12 +474,14 @@ int sqlite3_exec( #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) +#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) +#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) From 9f11ef12320a9f8417d4cd0846b11c32051faaf4 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 31 Aug 2013 02:48:56 +0000 Subject: [PATCH 11/22] Improve the consistency of the diagnostic messages on Windows. FossilOrigin-Name: c6f174a0cb27fe79740fffc7ce51081ec52a5dbd --- manifest | 15 +++---- manifest.uuid | 2 +- src/os_win.c | 112 +++++++++++++++++++++++--------------------------- 3 files changed, 58 insertions(+), 71 deletions(-) diff --git a/manifest b/manifest index 40a9efb0be..4c92aed8c7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sCygwin\swhen\shandling\stemporary\sfile\snames.\s\sImprove\serror\scodes\sand\sdiagnostic\smessages\sfor\stemporary\sfile\sname\shandling\son\sWindows.\s\sRename\swinConvertUtf8Filename\sto\swinConvertFromUtf8Filename.\s\sImprove\splacement\sand\scomments\sfor\sforward\sfunction\sdeclarations. -D 2013-08-30T21:52:38.235 +C Improve\sthe\sconsistency\sof\sthe\sdiagnostic\smessages\son\sWindows. +D 2013-08-31T02:48:56.122 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -203,7 +203,7 @@ F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6 -F src/os_win.c 8e87c2718975bc3cd8d86bf3ff2cc3bbafbc7eaf +F src/os_win.c 27ab5a2236e0649bcaa246b5ce80b7289ab31688 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f @@ -1109,10 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 -R 72dd46cadd0f990a967d544f6edf59de -T *branch * cygwinTempPath -T *sym-cygwinTempPath * -T -sym-trunk * +P a411df725153119acb3bcf44fb71deecaa307887 +R bb11e3b1e087c83913695ae6bba44408 U mistachkin -Z 23133362076223f26c27390373169480 +Z b8d9459ebc748b157e98d4dbf0b6c355 diff --git a/manifest.uuid b/manifest.uuid index 44a442d40d..1b8e732303 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a411df725153119acb3bcf44fb71deecaa307887 \ No newline at end of file +c6f174a0cb27fe79740fffc7ce51081ec52a5dbd \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index ab33b52a47..81265a070e 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1761,10 +1761,9 @@ static int winceCreateLock(const char *zFilename, winFile *pFile){ pFile->hMutex = osCreateMutexW(NULL, FALSE, zName); if (!pFile->hMutex){ pFile->lastErrno = osGetLastError(); - winLogError(SQLITE_IOERR, pFile->lastErrno, - "winceCreateLock1", zFilename); sqlite3_free(zName); - return SQLITE_IOERR; + return winLogError(SQLITE_IOERR, pFile->lastErrno, + "winceCreateLock1", zFilename); } /* Acquire the mutex before continuing */ @@ -2100,7 +2099,7 @@ static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){ && ((lastErrno = osGetLastError())!=NO_ERROR)) ){ pFile->lastErrno = lastErrno; winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, - "winSeekFile", pFile->zPath); + "winSeekFile", pFile->zPath); OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h)); return 1; } @@ -2121,7 +2120,7 @@ static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){ if(!bRet){ pFile->lastErrno = osGetLastError(); winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, - "winSeekFile", pFile->zPath); + "winSeekFile", pFile->zPath); OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h)); return 1; } @@ -2254,7 +2253,7 @@ static int winRead( pFile->lastErrno = lastErrno; OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h)); return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, - "winRead", pFile->zPath); + "winRead", pFile->zPath); } winLogIoerr(nRetry); if( nRead<(DWORD)amt ){ @@ -2360,11 +2359,12 @@ static int winWrite( if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ) || ( pFile->lastErrno==ERROR_DISK_FULL )){ OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h)); - return SQLITE_FULL; + return winLogError(SQLITE_FULL, pFile->lastErrno, + "winWrite1", pFile->zPath); } OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h)); return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, - "winWrite", pFile->zPath); + "winWrite2", pFile->zPath); }else{ winLogIoerr(nRetry); } @@ -2488,7 +2488,7 @@ static int winSync(sqlite3_file *id, int flags){ pFile->lastErrno = osGetLastError(); OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, - "winSync", pFile->zPath); + "winSync", pFile->zPath); } #endif } @@ -2529,7 +2529,7 @@ static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ && ((lastErrno = osGetLastError())!=NO_ERROR) ){ pFile->lastErrno = lastErrno; rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, - "winFileSize", pFile->zPath); + "winFileSize", pFile->zPath); } } #endif @@ -2624,7 +2624,7 @@ static int winUnlockReadLock(winFile *pFile){ if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){ pFile->lastErrno = lastErrno; winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno, - "winUnlockReadLock", pFile->zPath); + "winUnlockReadLock", pFile->zPath); } OSTRACE(("READ-UNLOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res))); return res; @@ -2837,7 +2837,7 @@ static int winUnlock(sqlite3_file *id, int locktype){ /* This should never happen. We should always be able to ** reacquire the read lock */ rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(), - "winUnlock", pFile->zPath); + "winUnlock", pFile->zPath); } } if( type>=RESERVED_LOCK ){ @@ -2952,7 +2952,7 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){ if( rc==SQLITE_OK ){ *(char**)pArg = zTFile; } - OSTRACE(("FCNTL file=%p, rc=%d\n", pFile->h, rc)); + OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); return rc; } #if SQLITE_MAX_MMAP_SIZE>0 @@ -2970,7 +2970,7 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){ rc = winMapfile(pFile, -1); } } - OSTRACE(("FCNTL file=%p, rc=%d\n", pFile->h, rc)); + OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); return rc; } #endif @@ -3286,7 +3286,7 @@ static int winOpenSharedMemory(winFile *pDbFd){ rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); if( rc!=SQLITE_OK ){ rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(), - "winOpenShm", pDbFd->zPath); + "winOpenShm", pDbFd->zPath); } } if( rc==SQLITE_OK ){ @@ -3546,7 +3546,7 @@ static int winShmMap( rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); if( rc!=SQLITE_OK ){ rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(), - "winShmMap1", pDbFd->zPath); + "winShmMap1", pDbFd->zPath); goto shmpage_out; } @@ -3561,7 +3561,7 @@ static int winShmMap( rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); if( rc!=SQLITE_OK ){ rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(), - "winShmMap2", pDbFd->zPath); + "winShmMap2", pDbFd->zPath); goto shmpage_out; } } @@ -3615,7 +3615,7 @@ static int winShmMap( if( !pMap ){ pShmNode->lastErrno = osGetLastError(); rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno, - "winShmMap3", pDbFd->zPath); + "winShmMap3", pDbFd->zPath); if( hMap ) osCloseHandle(hMap); goto shmpage_out; } @@ -3663,7 +3663,7 @@ static int winUnmapfile(winFile *pFile){ "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile, pFile->pMapRegion)); return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, - "winUnmap1", pFile->zPath); + "winUnmapfile1", pFile->zPath); } pFile->pMapRegion = 0; pFile->mmapSize = 0; @@ -3675,7 +3675,7 @@ static int winUnmapfile(winFile *pFile){ OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, hMap=%p, rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile, pFile->hMap)); return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, - "winUnmap2", pFile->zPath); + "winUnmapfile2", pFile->zPath); } pFile->hMap = NULL; } @@ -3750,10 +3750,10 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){ if( pFd->hMap==NULL ){ pFd->lastErrno = osGetLastError(); rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, - "winMapfile", pFd->zPath); + "winMapfile1", pFd->zPath); /* Log the error, but continue normal operation using xRead/xWrite */ - OSTRACE(("MAP-FILE-CREATE pid=%lu, pFile=%p, rc=SQLITE_IOERR_MMAP\n", - osGetCurrentProcessId(), pFd)); + OSTRACE(("MAP-FILE-CREATE pid=%lu, pFile=%p, rc=%s\n", + osGetCurrentProcessId(), pFd, sqlite3ErrName(rc))); return SQLITE_OK; } assert( (nMap % winSysInfo.dwPageSize)==0 ); @@ -3767,10 +3767,11 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){ osCloseHandle(pFd->hMap); pFd->hMap = NULL; pFd->lastErrno = osGetLastError(); - winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, - "winMapfile", pFd->zPath); - OSTRACE(("MAP-FILE-MAP pid=%lu, pFile=%p, rc=SQLITE_IOERR_MMAP\n", - osGetCurrentProcessId(), pFd)); + rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, + "winMapfile2", pFd->zPath); + /* Log the error, but continue normal operation using xRead/xWrite */ + OSTRACE(("MAP-FILE-MAP pid=%lu, pFile=%p, rc=%s\n", + osGetCurrentProcessId(), pFd, sqlite3ErrName(rc))); return SQLITE_OK; } pFd->pMapRegion = pNew; @@ -4050,10 +4051,9 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){ osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir, zConverted, nBuf+1)<0 ){ sqlite3_free(zConverted); - winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno, - "cygwin_conv_path", zDir); OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n")); - return SQLITE_IOERR_CONVPATH; + return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno, + "winGetTempname1", zDir); } if( winIsDir(zConverted) ){ /* At this point, we know the candidate directory exists and should @@ -4094,10 +4094,9 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){ if( osGetTempPathW(nBuf, zWidePath)==0 ){ sqlite3_free(zWidePath); sqlite3_free(zBuf); - winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), - "winGetTempname", 0); OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); - return SQLITE_IOERR_GETTEMPPATH; + return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), + "winGetTempname1", 0); } zMulti = winUnicodeToUtf8(zWidePath); if( zMulti ){ @@ -4122,10 +4121,9 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){ } if( osGetTempPathA(nBuf, zMbcsPath)==0 ){ sqlite3_free(zBuf); - winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), - "winGetTempname", 0); OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); - return SQLITE_IOERR_GETTEMPPATH; + return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), + "winGetTempname2", 0); } zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); if( zUtf8 ){ @@ -4148,7 +4146,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){ if( (nLen + sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX) + 18) >= nBuf ){ sqlite3_free(zBuf); OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n")); - return SQLITE_ERROR; + return winLogError(SQLITE_ERROR, 0, "winGetTempname3", 0); } sqlite3_snprintf(nBuf-18-nLen, zBuf+nLen, SQLITE_TEMP_FILE_PREFIX); @@ -4585,8 +4583,7 @@ static int winDelete( } #endif if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ - rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, - "winDelete", zFilename); + rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); }else{ winLogIoerr(cnt); } @@ -4640,9 +4637,9 @@ static int winAccess( }else{ winLogIoerr(cnt); if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ - winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename); sqlite3_free(zConverted); - return SQLITE_IOERR_ACCESS; + return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", + zFilename); }else{ attr = INVALID_FILE_ATTRIBUTES; } @@ -4744,24 +4741,21 @@ static int winFullPathname( */ char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 ); if( !zOut ){ - winLogError(SQLITE_IOERR_NOMEM, 0, "winFullPathname", zRelative); return SQLITE_IOERR_NOMEM; } if( cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){ - winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, "winFullPathname", - zRelative); sqlite3_free(zOut); - return SQLITE_CANTOPEN_CONVPATH; + return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, + "winFullPathname1", zRelative); } sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%s%s", sqlite3_data_directory, winGetDirDep(), zOut); sqlite3_free(zOut); }else{ if( cygwin_conv_path(CCP_POSIX_TO_WIN_A, zRelative, zFull, nFull)<0 ){ - winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, "winFullPathname", - zRelative); - return SQLITE_CANTOPEN_CONVPATH; + return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, + "winFullPathname2", zRelative); } } return SQLITE_OK; @@ -4794,7 +4788,7 @@ static int winFullPathname( /* If this path name begins with "/X:", where "X" is any alphabetic ** character, discard the initial "/" from the pathname. */ - if( zRelative[0]=='/' && sqlite3Isalpha(zRelative[1]) && zRelative[2]==':' ){ + if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){ zRelative++; } @@ -4823,10 +4817,9 @@ static int winFullPathname( LPWSTR zTemp; nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0); if( nByte==0 ){ - winLogError(SQLITE_ERROR, osGetLastError(), - "GetFullPathNameW1", zConverted); sqlite3_free(zConverted); - return SQLITE_CANTOPEN_FULLPATH; + return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), + "winFullPathname1", zRelative); } nByte += 3; zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); @@ -4836,11 +4829,10 @@ static int winFullPathname( } nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); if( nByte==0 ){ - winLogError(SQLITE_ERROR, osGetLastError(), - "GetFullPathNameW2", zConverted); sqlite3_free(zConverted); sqlite3_free(zTemp); - return SQLITE_CANTOPEN_FULLPATH; + return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), + "winFullPathname2", zRelative); } sqlite3_free(zConverted); zOut = winUnicodeToUtf8(zTemp); @@ -4851,10 +4843,9 @@ static int winFullPathname( char *zTemp; nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0); if( nByte==0 ){ - winLogError(SQLITE_ERROR, osGetLastError(), - "GetFullPathNameA1", zConverted); sqlite3_free(zConverted); - return SQLITE_CANTOPEN_FULLPATH; + return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), + "winFullPathname3", zRelative); } nByte += 3; zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); @@ -4864,11 +4855,10 @@ static int winFullPathname( } nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); if( nByte==0 ){ - winLogError(SQLITE_ERROR, osGetLastError(), - "GetFullPathNameA2", zConverted); sqlite3_free(zConverted); sqlite3_free(zTemp); - return SQLITE_CANTOPEN_FULLPATH; + return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), + "winFullPathname4", zRelative); } sqlite3_free(zConverted); zOut = sqlite3_win32_mbcs_to_utf8(zTemp); From 3fb4b6df07f7ce12bed39aef31590d06d251e2db Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 31 Aug 2013 05:13:22 +0000 Subject: [PATCH 12/22] Fix harmless MSVC compiler warning with MEMDEBUG defined. FossilOrigin-Name: b48cfd2dfca70091a52deeeee16619237e1c270b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/mem2.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4c92aed8c7..0c61c93cf6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sthe\sconsistency\sof\sthe\sdiagnostic\smessages\son\sWindows. -D 2013-08-31T02:48:56.122 +C Fix\sharmless\sMSVC\scompiler\swarning\swith\sMEMDEBUG\sdefined. +D 2013-08-31T05:13:22.387 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -189,7 +189,7 @@ F src/main.c c4c781b06faa2ce4040c32a75fd931a07ba7054e F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa -F src/mem2.c e243acb034f91e75e4c06aed5d3d960025c62d1f +F src/mem2.c dce31758da87ec2cfa52ba4c5df1aed6e07d8e8f F src/mem3.c 61c9d47b792908c532ca3a62b999cf21795c6534 F src/mem5.c 0025308a93838022bd5696cf9627ff4e40b19918 F src/memjournal.c 0683aac6cab6ec2b5374c0db37c0deb2436a3785 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P a411df725153119acb3bcf44fb71deecaa307887 -R bb11e3b1e087c83913695ae6bba44408 +P c6f174a0cb27fe79740fffc7ce51081ec52a5dbd +R bb417a9280c6c7257f662f98515af4c7 U mistachkin -Z b8d9459ebc748b157e98d4dbf0b6c355 +Z ce71d33f787d820719edc5d9e21c8ccd diff --git a/manifest.uuid b/manifest.uuid index 1b8e732303..66324b2b9e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6f174a0cb27fe79740fffc7ce51081ec52a5dbd \ No newline at end of file +b48cfd2dfca70091a52deeeee16619237e1c270b \ No newline at end of file diff --git a/src/mem2.c b/src/mem2.c index d461dffab1..99ea42517e 100644 --- a/src/mem2.c +++ b/src/mem2.c @@ -348,7 +348,7 @@ static void *sqlite3MemRealloc(void *pPrior, int nByte){ pOldHdr = sqlite3MemsysGetHeader(pPrior); pNew = sqlite3MemMalloc(nByte); if( pNew ){ - memcpy(pNew, pPrior, nByteiSize ? nByte : pOldHdr->iSize); + memcpy(pNew, pPrior, (int)(nByteiSize ? nByte : pOldHdr->iSize)); if( nByte>pOldHdr->iSize ){ randomFill(&((char*)pNew)[pOldHdr->iSize], nByte - (int)pOldHdr->iSize); } From 2a43c28f0678bbf98a802c2e93b41156ad8fbd22 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 31 Aug 2013 05:46:42 +0000 Subject: [PATCH 13/22] Avoid commenting out #include statements when building the amalgamation source code file. FossilOrigin-Name: 2fca6d784b000fd3a4d6890e38a0b087767f3a7f --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/mksqlite3c.tcl | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 0c61c93cf6..2863afe545 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\sMSVC\scompiler\swarning\swith\sMEMDEBUG\sdefined. -D 2013-08-31T05:13:22.387 +C Avoid\scommenting\sout\s#include\sstatements\swhen\sbuilding\sthe\samalgamation\ssource\scode\sfile. +D 2013-08-31T05:46:42.494 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1079,7 +1079,7 @@ F tool/mkkeywordhash.c bb52064aa614e1426445e4b2b9b00eeecd23cc79 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 8bce31074e4cbe631bb7676526a048335f4c9f02 -F tool/mksqlite3c.tcl a61fe62a2895ca6458c463fccf1211ca1c000fcf +F tool/mksqlite3c.tcl d8d51141424a0227aecfd7bd07a92304a946b8b2 F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 F tool/mksqlite3internalh.tcl 3dca7bb5374cee003379b8cbac73714f610ef795 F tool/mkvsix.tcl 0be7f7a591f1e83f9199cb82911b66668ca484c9 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P c6f174a0cb27fe79740fffc7ce51081ec52a5dbd -R bb417a9280c6c7257f662f98515af4c7 +P b48cfd2dfca70091a52deeeee16619237e1c270b +R b57559fe8be860201c533ce843be8c05 U mistachkin -Z ce71d33f787d820719edc5d9e21c8ccd +Z 5c7a5afeef353865f26e419014385170 diff --git a/manifest.uuid b/manifest.uuid index 66324b2b9e..895cd83cdf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b48cfd2dfca70091a52deeeee16619237e1c270b \ No newline at end of file +2fca6d784b000fd3a4d6890e38a0b087767f3a7f \ No newline at end of file diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index c93bcea44d..8826f25b77 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -137,10 +137,10 @@ proc section_comment {text} { # Read the source file named $filename and write it into the # sqlite3.c output file. If any #include statements are seen, -# process them approprately. +# process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global available_hdr out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" @@ -166,11 +166,12 @@ proc copy_file {filename} { section_comment "Continuing where we left off in $tail" if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} } - } elseif {![info exists seen_hdr($hdr)]} { - set seen_hdr($hdr) 1 - puts $out $line } else { - puts $out "/* $line */" + set suffix [string toupper [string map [list / _ . _] $hdr]] + puts $out "#ifndef SQLITE_HEADER_$suffix" + puts $out "#define SQLITE_HEADER_$suffix" + puts $out $line + puts $out "#endif" } } elseif {[regexp {^#ifdef __cplusplus} $line]} { puts $out "#if 0" From 3fa2a82b8b345cbb2c400f366421f1abbe65faa8 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 31 Aug 2013 14:56:30 +0000 Subject: [PATCH 14/22] Reenable a test accidentally disabled when the stat4 branch was merged. FossilOrigin-Name: d9fadc8fa6ef02d516678d57896d93e0a5f52cfe --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/alter.test | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 9b210d3d88..4f6ffd175e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scompiler\swarnings\sin\sanalyze.c. -D 2013-08-30T20:19:52.698 +C Reenable\sa\stest\saccidentally\sdisabled\swhen\sthe\sstat4\sbranch\swas\smerged. +D 2013-08-31T14:56:30.692 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 F test/all.test 6ff7b43c2b4b905c74dc4a813d201d0fa64c5783 -F test/alter.test 7e771c3c3f401198557dbbcf4a2c21950ba934f3 +F test/alter.test 775a1dded3f8247983c9a3e767b011d9a5114442 F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060 F test/alter3.test 49c9d9fba2b8fcdce2dedeca97bbf1f369cc548d F test/alter4.test 8e93bf7a7e6919b14b0c9a6c1e4908bcf21b0165 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P dbc31750440226702fbf88f1bf6140ef403c9be1 -R 5df52e9a380e1241cf1df8d1d5fbe7ea +P 5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 +R 1451e706c75b3cfea10ed5a938fdd0ce U dan -Z 33fcbfc1bf7d299e3e7e4e929460c0cd +Z 244a50a69073c5e2d4dc31f3118b8090 diff --git a/manifest.uuid b/manifest.uuid index e0a1d44337..ed7629c778 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 \ No newline at end of file +d9fadc8fa6ef02d516678d57896d93e0a5f52cfe \ No newline at end of file diff --git a/test/alter.test b/test/alter.test index faa6b0d258..1ccea22624 100644 --- a/test/alter.test +++ b/test/alter.test @@ -847,6 +847,7 @@ do_test alter-14.2 { set system_table_list {1 sqlite_master} catchsql ANALYZE ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } +ifcapable stat3 { lappend system_table_list 3 sqlite_stat3 } ifcapable stat4 { lappend system_table_list 4 sqlite_stat4 } foreach {tn tbl} $system_table_list { From 28159a5ee99e55a0f10fb8497a5122112d893222 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 31 Aug 2013 17:01:56 +0000 Subject: [PATCH 15/22] Enhancements to the Win32 API definition macros. FossilOrigin-Name: b1811baab6e35ecb1ba920a7ed3302997758d309 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 2863afe545..c62353483b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\scommenting\sout\s#include\sstatements\swhen\sbuilding\sthe\samalgamation\ssource\scode\sfile. -D 2013-08-31T05:46:42.494 +C Enhancements\sto\sthe\sWin32\sAPI\sdefinition\smacros. +D 2013-08-31T17:01:56.739 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -203,7 +203,7 @@ F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6 -F src/os_win.c 27ab5a2236e0649bcaa246b5ce80b7289ab31688 +F src/os_win.c 896581ee5a2ad261c3410fc84cfb0639ef2a1d56 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P b48cfd2dfca70091a52deeeee16619237e1c270b -R b57559fe8be860201c533ce843be8c05 +P 2fca6d784b000fd3a4d6890e38a0b087767f3a7f +R 81d5e6e46adbe46f943b02ea53b00aff U mistachkin -Z 5c7a5afeef353865f26e419014385170 +Z 8550f042a6eaddfa936a0e87c6856786 diff --git a/manifest.uuid b/manifest.uuid index 895cd83cdf..64c97df68b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2fca6d784b000fd3a4d6890e38a0b087767f3a7f \ No newline at end of file +b1811baab6e35ecb1ba920a7ed3302997758d309 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 81265a070e..34b5834eb8 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -38,7 +38,7 @@ ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions ** based on the sub-platform)? */ -#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) # define SQLITE_WIN32_HAS_ANSI #endif @@ -46,10 +46,19 @@ ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions ** based on the sub-platform)? */ -#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT +#if (SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT) && \ + !defined(SQLITE_WIN32_NO_WIDE) # define SQLITE_WIN32_HAS_WIDE #endif +/* +** Make sure at least one set of Win32 APIs is available. +*/ +#if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE) +# error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\ + must be defined." +#endif + /* ** Maximum pathname length (in chars) for Win32. This should normally be ** MAX_PATH. @@ -1116,7 +1125,7 @@ void sqlite3_win32_sleep(DWORD milliseconds){ ** WinNT/2K/XP so that we will know whether or not we can safely call ** the LockFileEx() API. */ -#if SQLITE_OS_WINCE || SQLITE_OS_WINRT +#if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) # define osIsNT() (1) #elif !defined(SQLITE_WIN32_HAS_WIDE) # define osIsNT() (0) From 4a1aa3851aeceef8e027d35751008b89ca4c62d4 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 31 Aug 2013 17:21:26 +0000 Subject: [PATCH 16/22] Fix a problem causing SQLite not to use stat4 or stat3 data to analyze constraints of the form "column = expr COLLATE collation" (those with an explicit COLLATE on the non-column side of the comparison operator). FossilOrigin-Name: 1e86d81d46c9da6aaee0c6938ee40933f35e3d0d --- manifest | 14 ++--- manifest.uuid | 2 +- src/vdbemem.c | 3 + test/analyze9.test | 135 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4f6ffd175e..0b5fa83aa7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reenable\sa\stest\saccidentally\sdisabled\swhen\sthe\sstat4\sbranch\swas\smerged. -D 2013-08-31T14:56:30.692 +C Fix\sa\sproblem\scausing\sSQLite\snot\sto\suse\sstat4\sor\sstat3\sdata\sto\sanalyze\sconstraints\sof\sthe\sform\s"column\s=\sexpr\sCOLLATE\scollation"\s(those\swith\san\sexplicit\sCOLLATE\son\sthe\snon-column\sside\sof\sthe\scomparison\soperator). +D 2013-08-31T17:21:26.324 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -283,7 +283,7 @@ F src/vdbeInt.h cbe71b8b36d8b3bba5709cc3f436c7e3b47b7b08 F src/vdbeapi.c 96b24b946cf21894f63d9393e821baa2f0a80979 F src/vdbeaux.c c7fe2695e256dbf254113c4fe90d3ec9aabe3bbe F src/vdbeblob.c 5dc79627775bd9a9b494dd956e26297946417d69 -F src/vdbemem.c 4511e1d2304a7d7916d14be20080036331740fcf +F src/vdbemem.c 75ad7fd8f068a8baaba1cf3a84714ef7d3b7a2b8 F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017 F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c @@ -308,7 +308,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test 19151da2c4e918905d2081b74ac5c4d47fc850ab F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test 3095a9ebfea4a2b1f9db60375320ae7f219595ba +F test/analyze9.test 2bc3fb7b0ba7954e2513e69af8608ce5da201418 F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 5bbd2ccb3d2d6286fd667dac2ab658d6b89640a6 -R 1451e706c75b3cfea10ed5a938fdd0ce +P d9fadc8fa6ef02d516678d57896d93e0a5f52cfe +R 549c9915be9450c721bff69cc42a239a U dan -Z 244a50a69073c5e2d4dc31f3118b8090 +Z dce49f1165decc3594690bec1fb4ef74 diff --git a/manifest.uuid b/manifest.uuid index ed7629c778..89b7c2ebb7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d9fadc8fa6ef02d516678d57896d93e0a5f52cfe \ No newline at end of file +1e86d81d46c9da6aaee0c6938ee40933f35e3d0d \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index e6ad291532..dbdfc53074 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1311,6 +1311,9 @@ int sqlite3Stat4ProbeSetValue( alloc.ppRec = ppRec; alloc.iVal = iVal; + /* Skip over any TK_COLLATE nodes */ + pExpr = sqlite3ExprSkipCollate(pExpr); + if( !pExpr ){ pVal = valueNew(pParse->db, &alloc); if( pVal ){ diff --git a/test/analyze9.test b/test/analyze9.test index be52eb94b2..e2528709bf 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -422,5 +422,140 @@ do_eqp_test 9.4.2 { SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5 } {/t1 USING INDEX i1/} +#------------------------------------------------------------------------- +# Check that the planner takes stat4 data into account when considering +# "IS NULL" and "IS NOT NULL" constraints. +# +do_execsql_test 10.1.1 { + DROP TABLE IF EXISTS t3; + CREATE TABLE t3(a, b); + CREATE INDEX t3a ON t3(a); + CREATE INDEX t3b ON t3(b); +} +do_test 10.1.2 { + for {set i 1} {$i < 100} {incr i} { + if {$i>90} { set a $i } else { set a NULL } + set b [expr $i % 5] + execsql "INSERT INTO t3 VALUES($a, $b)" + } + execsql ANALYZE +} {} +do_eqp_test 10.1.3 { + SELECT * FROM t3 WHERE a IS NULL AND b = 2 +} {/t3 USING INDEX t3b/} +do_eqp_test 10.1.4 { + SELECT * FROM t3 WHERE a IS NOT NULL AND b = 2 +} {/t3 USING INDEX t3a/} + +do_execsql_test 10.2.1 { + DROP TABLE IF EXISTS t3; + CREATE TABLE t3(x, a, b); + CREATE INDEX t3a ON t3(x, a); + CREATE INDEX t3b ON t3(x, b); +} +do_test 10.2.2 { + for {set i 1} {$i < 100} {incr i} { + if {$i>90} { set a $i } else { set a NULL } + set b [expr $i % 5] + execsql "INSERT INTO t3 VALUES('xyz', $a, $b)" + } + execsql ANALYZE +} {} +do_eqp_test 10.2.3 { + SELECT * FROM t3 WHERE x = 'xyz' AND a IS NULL AND b = 2 +} {/t3 USING INDEX t3b/} +do_eqp_test 10.2.4 { + SELECT * FROM t3 WHERE x = 'xyz' AND a IS NOT NULL AND b = 2 +} {/t3 USING INDEX t3a/} + +#------------------------------------------------------------------------- +# Check that stat4 data is used correctly with non-default collation +# sequences. +# +foreach {tn schema} { + 1 { + CREATE TABLE t4(a COLLATE nocase, b); + CREATE INDEX t4a ON t4(a); + CREATE INDEX t4b ON t4(b); + } + 2 { + CREATE TABLE t4(a, b); + CREATE INDEX t4a ON t4(a COLLATE nocase); + CREATE INDEX t4b ON t4(b); + } +} { + drop_all_tables + do_test 11.$tn.1 { execsql $schema } {} + + do_test 11.$tn.2 { + for {set i 0} {$i < 100} {incr i} { + if { ($i % 10)==0 } { set a ABC } else { set a DEF } + set b [expr $i % 5] + execsql { INSERT INTO t4 VALUES($a, $b) } + } + execsql ANALYZE + } {} + + do_eqp_test 11.$tn.3 { + SELECT * FROM t4 WHERE a = 'def' AND b = 3; + } {/t4 USING INDEX t4b/} + + if {$tn==1} { + set sql "SELECT * FROM t4 WHERE a = 'abc' AND b = 3;" + do_eqp_test 11.$tn.4 $sql {/t4 USING INDEX t4a/} + } else { + + set sql "SELECT * FROM t4 WHERE a = 'abc' COLLATE nocase AND b = 3;" + do_eqp_test 11.$tn.5 $sql {/t4 USING INDEX t4a/} + + set sql "SELECT * FROM t4 WHERE a COLLATE nocase = 'abc' AND b = 3;" + do_eqp_test 11.$tn.6 $sql {/t4 USING INDEX t4a/} + } +} + +foreach {tn schema} { + 1 { + CREATE TABLE t4(x, a COLLATE nocase, b); + CREATE INDEX t4a ON t4(x, a); + CREATE INDEX t4b ON t4(x, b); + } + 2 { + CREATE TABLE t4(x, a, b); + CREATE INDEX t4a ON t4(x, a COLLATE nocase); + CREATE INDEX t4b ON t4(x, b); + } +} { + drop_all_tables + do_test 12.$tn.1 { execsql $schema } {} + + do_test 12.$tn.2 { + for {set i 0} {$i < 100} {incr i} { + if { ($i % 10)==0 } { set a ABC } else { set a DEF } + set b [expr $i % 5] + execsql { INSERT INTO t4 VALUES(X'abcdef', $a, $b) } + } + execsql ANALYZE + } {} + + do_eqp_test 12.$tn.3 { + SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'def' AND b = 3; + } {/t4 USING INDEX t4b/} + + if {$tn==1} { + set sql "SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' AND b = 3;" + do_eqp_test 12.$tn.4 $sql {/t4 USING INDEX t4a/} + } else { + set sql { + SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' COLLATE nocase AND b = 3 + } + do_eqp_test 12.$tn.5 $sql {/t4 USING INDEX t4a/} + set sql { + SELECT * FROM t4 WHERE x=X'abcdef' AND a COLLATE nocase = 'abc' AND b = 3 + } + do_eqp_test 12.$tn.6 $sql {/t4 USING INDEX t4a/} + } +} + finish_test + From 1a88b14e5d17ba55a5cdcccf0839e30b4a6463a0 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 31 Aug 2013 18:06:52 +0000 Subject: [PATCH 17/22] Revise the amalgamation tool to allow 'duplicate' include files to be retained manually while still preserving the existing line numbers. FossilOrigin-Name: aa48284637b954d63bcf77e19b25e75c7ad1a6d3 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_win.c | 3 ++- tool/mksqlite3c.tcl | 17 +++++++++++------ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index c62353483b..8d15520f4c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhancements\sto\sthe\sWin32\sAPI\sdefinition\smacros. -D 2013-08-31T17:01:56.739 +C Revise\sthe\samalgamation\stool\sto\sallow\s'duplicate'\sinclude\sfiles\sto\sbe\sretained\smanually\swhile\sstill\spreserving\sthe\sexisting\sline\snumbers. +D 2013-08-31T18:06:52.923 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -203,7 +203,7 @@ F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6 -F src/os_win.c 896581ee5a2ad261c3410fc84cfb0639ef2a1d56 +F src/os_win.c bb592dfb850e4ee3e4caecce461dca74dc40936d F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f @@ -1079,7 +1079,7 @@ F tool/mkkeywordhash.c bb52064aa614e1426445e4b2b9b00eeecd23cc79 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 8bce31074e4cbe631bb7676526a048335f4c9f02 -F tool/mksqlite3c.tcl d8d51141424a0227aecfd7bd07a92304a946b8b2 +F tool/mksqlite3c.tcl d344cc3144a0271cd853c5e3df36e9f31d78d619 F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12 F tool/mksqlite3internalh.tcl 3dca7bb5374cee003379b8cbac73714f610ef795 F tool/mkvsix.tcl 0be7f7a591f1e83f9199cb82911b66668ca484c9 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 2fca6d784b000fd3a4d6890e38a0b087767f3a7f -R 81d5e6e46adbe46f943b02ea53b00aff +P b1811baab6e35ecb1ba920a7ed3302997758d309 +R c09e9aaa82ece462d9ada3bc7aee07de U mistachkin -Z 8550f042a6eaddfa936a0e87c6856786 +Z 9761d739f96263a417653d62e6565ea2 diff --git a/manifest.uuid b/manifest.uuid index 64c97df68b..f86d289b7d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b1811baab6e35ecb1ba920a7ed3302997758d309 \ No newline at end of file +aa48284637b954d63bcf77e19b25e75c7ad1a6d3 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 34b5834eb8..72d6e8ba5c 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -17,7 +17,7 @@ #ifdef __CYGWIN__ # include -# include +# include /* amalgamator: keep */ #endif /* @@ -4020,6 +4020,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){ "/var/tmp", "/usr/tmp", "/tmp", + ".", 0 /* List terminator */ }; unsigned int i; diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index 8826f25b77..343f606cfe 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -140,7 +140,7 @@ proc section_comment {text} { # process them appropriately. # proc copy_file {filename} { - global available_hdr out addstatic linemacros + global seen_hdr available_hdr out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" @@ -166,12 +166,17 @@ proc copy_file {filename} { section_comment "Continuing where we left off in $tail" if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} } - } else { - set suffix [string toupper [string map [list / _ . _] $hdr]] - puts $out "#ifndef SQLITE_HEADER_$suffix" - puts $out "#define SQLITE_HEADER_$suffix" + } elseif {![info exists seen_hdr($hdr)]} { + set seen_hdr($hdr) 1 puts $out $line - puts $out "#endif" + } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { + # This include file must be kept because there was a "keep" + # directive inside of a line comment. + puts $out $line + } else { + # Comment out the entire line, replacing any nested comment + # begin/end markers with the harmless substring "**". + puts $out "/* [string map [list /* ** */ **] $line] */" } } elseif {[regexp {^#ifdef __cplusplus} $line]} { puts $out "#if 0" From 575ab2f8f61b04faddd7c36644d804789da50db1 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 2 Sep 2013 07:16:40 +0000 Subject: [PATCH 18/22] Fix a problem with using stat4 data to estimate the number of rows scanned by a range constraint on the second or subsequent column of any index where an affinity transformation must be applied to the constraint argument. FossilOrigin-Name: c21f58d84859e479a6cc619671a0df48b2f9692e --- manifest | 16 +++++++------- manifest.uuid | 2 +- src/where.c | 7 +++++- test/analyze9.test | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 20e7aec2b2..3855207e56 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cleanup\sof\sthe\swindows\sVFS,\sincluding\sadded\ssupport\sfor\sCygwin,\sfixes\nfor\scompiler\swarnings\sunder\sunusual\sconfigurations,\sand\simproved\sdiagnostic\nerror\smessages. -D 2013-08-31T18:36:14.237 +C Fix\sa\sproblem\swith\susing\sstat4\sdata\sto\sestimate\sthe\snumber\sof\srows\sscanned\sby\sa\srange\sconstraint\son\sthe\ssecond\sor\ssubsequent\scolumn\sof\sany\sindex\swhere\san\saffinity\stransformation\smust\sbe\sapplied\sto\sthe\sconstraint\sargument. +D 2013-09-02T07:16:40.805 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 83f6106e0edfa23d1258c617cd58e3125277a363 +F src/where.c a37169b46fc03e381701852e43f85a51710986dd F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -308,7 +308,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test 19151da2c4e918905d2081b74ac5c4d47fc850ab F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test 2bc3fb7b0ba7954e2513e69af8608ce5da201418 +F test/analyze9.test c4717447731bf9bb5751e0785d6337883094db3c F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 1e86d81d46c9da6aaee0c6938ee40933f35e3d0d aa48284637b954d63bcf77e19b25e75c7ad1a6d3 -R 86ece7a1f31f0a8c4eaf6a2aa2ba8fd5 -U drh -Z 6d21523c19e589363df183a571e778f3 +P c94933f13208f3f7d6d1b117ce6d2821100655a4 +R 15f429912bd32e56367e01c1c9d0d2ba +U dan +Z fd6aacb9a694e6de7810fd7923f14ee2 diff --git a/manifest.uuid b/manifest.uuid index 6278beba1b..26c3d8ab8e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c94933f13208f3f7d6d1b117ce6d2821100655a4 \ No newline at end of file +c21f58d84859e479a6cc619671a0df48b2f9692e \ No newline at end of file diff --git a/src/where.c b/src/where.c index 235277d63d..58410ca150 100644 --- a/src/where.c +++ b/src/where.c @@ -2553,7 +2553,12 @@ static int whereRangeScanEst( ){ UnpackedRecord *pRec = pBuilder->pRec; tRowcnt a[2]; - u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity; + u8 aff; + if( nEq==p->nColumn ){ + aff = SQLITE_AFF_INTEGER; + }else{ + aff = p->pTable->aCol[p->aiColumn[nEq]].affinity; + } /* Variable iLower will be set to the estimate of the number of rows in ** the index that are less than the lower bound of the range query. The diff --git a/test/analyze9.test b/test/analyze9.test index e2528709bf..bbd4a4429b 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -556,6 +556,61 @@ foreach {tn schema} { } } +#------------------------------------------------------------------------- +# Check that affinities are taken into account when using stat4 data to +# estimate the number of rows scanned by a rowid constraint. +# +drop_all_tables +do_test 13.1 { + execsql { + CREATE TABLE t1(a, b, c); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b, c); + } + for {set i 0} {$i<100} {incr i} { + if {$i %2} {set a abc} else {set a def} + execsql { INSERT INTO t1(rowid, a, b, c) VALUES($i, $a, $i, $i) } + } + execsql ANALYZE +} {} +do_eqp_test 13.2.1 { + SELECT * FROM t1 WHERE a='abc' AND rowid<15 AND b<20 +} {/SEARCH TABLE t1 USING INDEX i1/} +do_eqp_test 13.2.2 { + SELECT * FROM t1 WHERE a='abc' AND rowid<'15' AND b<20 +} {/SEARCH TABLE t1 USING INDEX i1/} +do_eqp_test 13.3.1 { + SELECT * FROM t1 WHERE a='abc' AND rowid<100 AND b<20 +} {/SEARCH TABLE t1 USING INDEX i2/} +do_eqp_test 13.3.2 { + SELECT * FROM t1 WHERE a='abc' AND rowid<'100' AND b<20 +} {/SEARCH TABLE t1 USING INDEX i2/} + +#------------------------------------------------------------------------- +# Check also that affinities are taken into account when using stat4 data +# to estimate the number of rows scanned by any other constraint on a +# column other than the leftmost. +# +drop_all_tables +do_test 14.1 { + execsql { CREATE TABLE t1(a, b INTEGER, c) } + for {set i 0} {$i<100} {incr i} { + set c [expr $i % 3] + execsql { INSERT INTO t1 VALUES('ott', $i, $c) } + } + execsql { + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(c); + ANALYZE; + } +} {} +do_eqp_test 13.2.1 { + SELECT * FROM t1 WHERE a='ott' AND b<10 AND c=1 +} {/SEARCH TABLE t1 USING INDEX i1/} +do_eqp_test 13.2.2 { + SELECT * FROM t1 WHERE a='ott' AND b<'10' AND c=1 +} {/SEARCH TABLE t1 USING INDEX i1/} + finish_test From 84f48296faace4671b517664c486560194f64eca Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 2 Sep 2013 11:52:11 +0000 Subject: [PATCH 19/22] Add tests to check if ANALYZE is choosing common non-periodic samples for the stat4 table. FossilOrigin-Name: 175842997af134138784bff6f8e93573deb5b36b --- manifest | 12 +++--- manifest.uuid | 2 +- test/analyze9.test | 95 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 101 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 3855207e56..9680d50eec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\susing\sstat4\sdata\sto\sestimate\sthe\snumber\sof\srows\sscanned\sby\sa\srange\sconstraint\son\sthe\ssecond\sor\ssubsequent\scolumn\sof\sany\sindex\swhere\san\saffinity\stransformation\smust\sbe\sapplied\sto\sthe\sconstraint\sargument. -D 2013-09-02T07:16:40.805 +C Add\stests\sto\scheck\sif\sANALYZE\sis\schoosing\scommon\snon-periodic\ssamples\sfor\sthe\sstat4\stable. +D 2013-09-02T11:52:11.512 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -308,7 +308,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test 19151da2c4e918905d2081b74ac5c4d47fc850ab F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test c4717447731bf9bb5751e0785d6337883094db3c +F test/analyze9.test bce50d7448d4c51e1a2fd8efdcf895c2e5042e76 F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P c94933f13208f3f7d6d1b117ce6d2821100655a4 -R 15f429912bd32e56367e01c1c9d0d2ba +P c21f58d84859e479a6cc619671a0df48b2f9692e +R 9fc61f7137863d5244ff2fd6cc214c12 U dan -Z fd6aacb9a694e6de7810fd7923f14ee2 +Z 6c1b0e52f8f47aae31db001aa8668b6b diff --git a/manifest.uuid b/manifest.uuid index 26c3d8ab8e..569ff735b6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c21f58d84859e479a6cc619671a0df48b2f9692e \ No newline at end of file +175842997af134138784bff6f8e93573deb5b36b \ No newline at end of file diff --git a/test/analyze9.test b/test/analyze9.test index bbd4a4429b..415d69a56c 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -611,6 +611,99 @@ do_eqp_test 13.2.2 { SELECT * FROM t1 WHERE a='ott' AND b<'10' AND c=1 } {/SEARCH TABLE t1 USING INDEX i1/} +#------------------------------------------------------------------------- +# By default, 16 non-periodic samples are collected for the stat4 table. +# The following tests attempt to verify that the most common keys are +# being collected. +# +proc check_stat4 {tn} { + db eval ANALYZE + db eval {SELECT a, b, c, d FROM t1} { + incr k($a) + incr k([list $a $b]) + incr k([list $a $b $c]) + if { [info exists k([list $a $b $c $d])]==0 } { incr nRow } + incr k([list $a $b $c $d]) + } + + set L [list] + foreach key [array names k] { + lappend L [list $k($key) $key] + } + + set nSample $nRow + if {$nSample>16} {set nSample 16} + + set nThreshold [lindex [lsort -decr -integer -index 0 $L] [expr $nSample-1] 0] + foreach key [array names k] { + if {$k($key)>$nThreshold} { + set expect($key) 1 + } + if {$k($key)==$nThreshold} { + set possible($key) 1 + } + } + + + set nPossible [expr $nSample - [llength [array names expect]]] + + #puts "EXPECT: [array names expect]" + #puts "POSSIBLE($nPossible/[array size possible]): [array names possible]" + #puts "HAVE: [db eval {SELECT test_decode(sample) FROM sqlite_stat4 WHERE idx='i1'}]" + + db eval {SELECT test_decode(sample) AS s FROM sqlite_stat4 WHERE idx='i1'} { + set seen 0 + for {set i 0} {$i<4} {incr i} { + unset -nocomplain expect([lrange $s 0 $i]) + if {[info exists possible([lrange $s 0 $i])]} { + set seen 1 + unset -nocomplain possible([lrange $s 0 $i]) + } + } + if {$seen} {incr nPossible -1} + } + if {$nPossible<0} {set nPossible 0} + + set res [list [llength [array names expect]] $nPossible] + uplevel [list do_test $tn [list set {} $res] {0 0}] +} + +drop_all_tables +do_test 14.1.1 { + execsql { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX i1 ON t1(a,b,c,d); + } + for {set i 0} {$i < 160} {incr i} { + execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } + if {($i % 10)==0} { execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } } + } +} {} +check_stat4 14.1.2 + +do_test 14.2.1 { + execsql { DELETE FROM t1 } + for {set i 0} {$i < 1600} {incr i} { + execsql { INSERT INTO t1 VALUES($i/10,$i/17,$i/27,$i/37) } + } +} {} +check_stat4 14.2.2 + +do_test 14.3.1 { + for {set i 0} {$i < 10} {incr i} { + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + } +} {} +check_stat4 14.3.2 + finish_test - From b49d1047c6efccc83d5986ed5f07b1372ab0e88c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 2 Sep 2013 18:58:11 +0000 Subject: [PATCH 20/22] Further stat4 related tests. FossilOrigin-Name: 0a702c4b4c35fdbcb62e3ab88b9e57d7ea0052a8 --- manifest | 16 ++-- manifest.uuid | 2 +- src/analyze.c | 24 +++-- test/analyze9.test | 211 +++++++++++++++++++++++++++++++++++++++++ test/permutations.test | 8 ++ 5 files changed, 245 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 9680d50eec..74678df38d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sto\scheck\sif\sANALYZE\sis\schoosing\scommon\snon-periodic\ssamples\sfor\sthe\sstat4\stable. -D 2013-09-02T11:52:11.512 +C Further\sstat4\srelated\stests. +D 2013-09-02T18:58:11.176 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -157,7 +157,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 2af0330bb1b601af7a7789bf7229675fd772a083 -F src/analyze.c 128f85d9bd7e79e93b8b27aa2bb54a43ad0c00f3 +F src/analyze.c 66903e3e5a36eee728c0dc1d574e8cb16059210f F src/attach.c fea00cab11c854646a27641a263f5876569a51f9 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 2f1987981139bd2f6d8c728d64bf09fb387443c3 @@ -308,7 +308,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4 F test/analyze6.test 19151da2c4e918905d2081b74ac5c4d47fc850ab F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88 -F test/analyze9.test bce50d7448d4c51e1a2fd8efdcf895c2e5042e76 +F test/analyze9.test 3b23fc97bcc0f4b5629aacdd8e1aa267114dcc79 F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b @@ -716,7 +716,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 c5e7ae8a18cb8a0ced38dbbc9e2463536c1de45b +F test/permutations.test 47f8c1d3d72ea46863426dcedb1e368f4b6ed70b F test/pragma.test 5e7de6c32a5d764f09437d2025f07e4917b9e178 F test/pragma2.test 224f0381f9411a78ae685cac24c13656a62021b7 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P c21f58d84859e479a6cc619671a0df48b2f9692e -R 9fc61f7137863d5244ff2fd6cc214c12 +P 175842997af134138784bff6f8e93573deb5b36b +R b9c05f2f20c9bc7024ff33ef435a0342 U dan -Z 6c1b0e52f8f47aae31db001aa8668b6b +Z 4390b50c9d94be4a8d0945a9543a37a9 diff --git a/manifest.uuid b/manifest.uuid index 569ff735b6..f4fb99e6d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -175842997af134138784bff6f8e93573deb5b36b \ No newline at end of file +0a702c4b4c35fdbcb62e3ab88b9e57d7ea0052a8 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index d70f77e779..89dc84f2c1 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -468,14 +468,25 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){ p->nSample = p->mxSample-1; } - /* Figure out where in the a[] array the new sample should be inserted. */ + /* The "rows less-than" for the rowid column must be greater than that + ** for the last sample in the p->a[] array. Otherwise, the samples would + ** be out of order. */ +#ifdef SQLITE_ENABLE_STAT4 + assert( p->nSample==0 + || pNew->anLt[p->nCol-1] > p->a[p->nSample-1].anLt[p->nCol-1] ); +#endif + + /* Insert the new sample */ + pSample = &p->a[p->nSample]; + sampleCopy(p, pSample, pNew); + p->nSample++; + +#if 0 iSeq = pNew->anLt[p->nCol-1]; for(iPos=p->nSample; iPos>0; iPos--){ if( iSeq>p->a[iPos-1].anLt[p->nCol-1] ) break; } - /* Insert the new sample */ - pSample = &p->a[iPos]; if( iPos!=p->nSample ){ Stat4Sample *pEnd = &p->a[p->nSample]; tRowcnt *anEq = pEnd->anEq; @@ -486,8 +497,8 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){ pSample->anDLt = anDLt; pSample->anLt = anLt; } - p->nSample++; - sampleCopy(p, pSample, pNew); +#endif + /* Zero the first nEqZero entries in the anEq[] array. */ memset(pSample->anEq, 0, sizeof(tRowcnt)*nEqZero); @@ -584,8 +595,7 @@ static void statPush( assert( iChngnCol ); if( p->nRow==0 ){ - /* anEq[0] is only zero for the very first call to this function. Do - ** appropriate initialization */ + /* This is the first call to this function. Do initialization. */ for(i=0; inCol; i++) p->current.anEq[i] = 1; }else{ /* Second and subsequent calls get processed here */ diff --git a/test/analyze9.test b/test/analyze9.test index 415d69a56c..777e462fdb 100644 --- a/test/analyze9.test +++ b/test/analyze9.test @@ -705,5 +705,216 @@ do_test 14.3.1 { } {} check_stat4 14.3.2 +do_test 14.4.1 { + execsql {DELETE FROM t1} + for {set i 1} {$i < 160} {incr i} { + set b [expr $i % 10] + if {$b==0 || $b==2} {set b 1} + execsql { INSERT INTO t1 VALUES($i/10,$b,$i,$i) } + } +} {} +check_stat4 14.4.2 +db func lrange lrange +db func lindex lindex +do_execsql_test 14.4.3 { + SELECT lrange(test_decode(sample), 0, 1) AS s FROM sqlite_stat4 + WHERE lindex(s, 1)=='1' ORDER BY rowid +} { + {0 1} {1 1} {2 1} {3 1} + {4 1} {5 1} {6 1} {7 1} + {8 1} {9 1} {10 1} {11 1} + {12 1} {13 1} {14 1} {15 1} +} + +#------------------------------------------------------------------------- +# Test that nothing untoward happens if the stat4 table contains entries +# for indexes that do not exist. Or NULL values in the idx column. +# Or NULL values in any of the other columns. +# +drop_all_tables +do_execsql_test 15.1 { + CREATE TABLE x1(a, b, UNIQUE(a, b)); + INSERT INTO x1 VALUES(1, 2); + INSERT INTO x1 VALUES(3, 4); + INSERT INTO x1 VALUES(5, 6); + ANALYZE; + INSERT INTO sqlite_stat4 VALUES(NULL, NULL, NULL, NULL, NULL, NULL); +} +db close +sqlite3 db test.db +do_execsql_test 15.2 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.3 { + INSERT INTO sqlite_stat4 VALUES(42, 42, 42, 42, 42, 42); +} +db close +sqlite3 db test.db +do_execsql_test 15.4 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.5 { + UPDATE sqlite_stat1 SET stat = NULL; +} +db close +sqlite3 db test.db +do_execsql_test 15.6 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.7 { + ANALYZE; + UPDATE sqlite_stat1 SET tbl = 'no such tbl'; +} +db close +sqlite3 db test.db +do_execsql_test 15.8 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.9 { + ANALYZE; + UPDATE sqlite_stat4 SET neq = NULL, nlt=NULL, ndlt=NULL; +} +db close +sqlite3 db test.db +do_execsql_test 15.10 { SELECT * FROM x1 } {1 2 3 4 5 6} + +# This is just for coverage.... +do_execsql_test 15.11 { + ANALYZE; + UPDATE sqlite_stat1 SET stat = stat || ' unordered'; +} +db close +sqlite3 db test.db +do_execsql_test 15.12 { SELECT * FROM x1 } {1 2 3 4 5 6} + +#------------------------------------------------------------------------- +# Test that allocations used for sqlite_stat4 samples are included in +# the quantity returned by SQLITE_DBSTATUS_SCHEMA_USED. +# +set one [string repeat x 1000] +set two [string repeat x 2000] +do_test 16.1 { + reset_db + execsql { + CREATE TABLE t1(a, UNIQUE(a)); + INSERT INTO t1 VALUES($one); + ANALYZE; + } + set nByte [lindex [sqlite3_db_status db SCHEMA_USED 0] 1] + + reset_db + execsql { + CREATE TABLE t1(a, UNIQUE(a)); + INSERT INTO t1 VALUES($two); + ANALYZE; + } + set nByte2 [lindex [sqlite3_db_status db SCHEMA_USED 0] 1] + + expr {$nByte2 > $nByte+950 && $nByte2 < $nByte+1050} +} {1} + +#------------------------------------------------------------------------- +# Test that stat4 data may be used with partial indexes. +# +do_test 17.1 { + reset_db + execsql { + CREATE TABLE t1(a, b, c, d); + CREATE INDEX i1 ON t1(a, b) WHERE d IS NOT NULL; + INSERT INTO t1 VALUES(-1, -1, -1, NULL); + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + } + + for {set i 0} {$i < 32} {incr i} { + if {$i<8} {set b 0} else { set b $i } + execsql { INSERT INTO t1 VALUES($i%2, $b, $i/2, 'abc') } + } + execsql {ANALYZE main.t1} +} {} + +do_catchsql_test 17.1.2 { + ANALYZE temp.t1; +} {1 {no such table: temp.t1}} + +do_eqp_test 17.2 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10; +} {/USING INDEX i1/} +do_eqp_test 17.3 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10; +} {/USING INDEX i1/} + +do_execsql_test 17.4 { + CREATE INDEX i2 ON t1(c); + ANALYZE main.i2; +} +do_eqp_test 17.5 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10; +} {/USING INDEX i1/} +do_eqp_test 17.6 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10; +} {/USING INDEX i2/} + +#------------------------------------------------------------------------- +# +do_test 18.1 { + reset_db + execsql { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + } + for {set i 0} {$i < 9} {incr i} { + execsql { + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + } + } + execsql ANALYZE + execsql { SELECT count(*) FROM sqlite_stat4 } +} {9} + +#------------------------------------------------------------------------- +# For coverage. +# +ifcapable view { + do_test 19.1 { + reset_db + execsql { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x, y); + CREATE VIEW v1 AS SELECT * FROM t1; + ANALYZE; + } + } {} +} +ifcapable auth { + proc authproc {op args} { + if {$op == "SQLITE_ANALYZE"} { return "SQLITE_DENY" } + return "SQLITE_OK" + } + do_test 19.2 { + reset_db + db auth authproc + execsql { + CREATE TABLE t1(x, y); + CREATE VIEW v1 AS SELECT * FROM t1; + } + catchsql ANALYZE + } {1 {not authorized}} +} + finish_test diff --git a/test/permutations.test b/test/permutations.test index 755565f1d7..b9033932d8 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -311,6 +311,14 @@ test_suite "coverage-pager" -description { walfault.test walbak.test journal2.test tkt-9d68c883.test } +test_suite "coverage-analyze" -description { + Coverage tests for file analyze.c. +} -files { + analyze3.test analyze4.test analyze5.test analyze6.test + analyze7.test analyze8.test analyze9.test analyzeA.test + analyze.test mallocA.test +} + lappend ::testsuitelist xxx #------------------------------------------------------------------------- From 05db3c774324a99946d867092c9af282fe177e69 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 2 Sep 2013 20:22:18 +0000 Subject: [PATCH 21/22] Simplify branch coverage testing by interchanging the order of two tests in the whereLoopInsert() function. FossilOrigin-Name: f7079b5365dd6cd8324a4fb23605e81476122ed6 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 74678df38d..15dc352239 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\sstat4\srelated\stests. -D 2013-09-02T18:58:11.176 +C Simplify\sbranch\scoverage\stesting\sby\sinterchanging\sthe\sorder\sof\stwo\stests\nin\sthe\swhereLoopInsert()\sfunction. +D 2013-09-02T20:22:18.651 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c a37169b46fc03e381701852e43f85a51710986dd +F src/where.c 573a815c28a7c70b5148a23ec040bb8992e51e5d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 175842997af134138784bff6f8e93573deb5b36b -R b9c05f2f20c9bc7024ff33ef435a0342 -U dan -Z 4390b50c9d94be4a8d0945a9543a37a9 +P 0a702c4b4c35fdbcb62e3ab88b9e57d7ea0052a8 +R 5255609fa5f702769f786eafe83d1965 +U drh +Z 3ad66b5373e173075a1fd9a0798ca8c7 diff --git a/manifest.uuid b/manifest.uuid index f4fb99e6d6..59f020c938 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a702c4b4c35fdbcb62e3ab88b9e57d7ea0052a8 \ No newline at end of file +f7079b5365dd6cd8324a4fb23605e81476122ed6 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 58410ca150..39650d62e9 100644 --- a/src/where.c +++ b/src/where.c @@ -4180,11 +4180,11 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ ** all of (1) dependencies (2) setup-cost, (3) run-cost, and ** (4) number of output rows. */ assert( p->rSetup==pTemplate->rSetup ); - if( p->nLTermnLTerm + if( p->prereq==pTemplate->prereq + && p->nLTermnLTerm && (p->wsFlags & WHERE_INDEXED)!=0 && (pTemplate->wsFlags & WHERE_INDEXED)!=0 && p->u.btree.pIndex==pTemplate->u.btree.pIndex - && p->prereq==pTemplate->prereq ){ /* Overwrite an existing WhereLoop with an similar one that uses ** more terms of the index */ From 67a5ec7b540ecadafb4595a62df3f03d6f544b80 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 3 Sep 2013 14:03:47 +0000 Subject: [PATCH 22/22] Make sure the omit-noop-left-join optimization is not applied if columns of the LEFT JOIN are used in the ORDER BY clause. Ticket [be84e357c035] FossilOrigin-Name: 0303d6bc7112e6f810ae1bd75cafc5ffc51f5212 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 2 +- test/where.test | 29 +++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 15dc352239..99db51e4ea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sbranch\scoverage\stesting\sby\sinterchanging\sthe\sorder\sof\stwo\stests\nin\sthe\swhereLoopInsert()\sfunction. -D 2013-09-02T20:22:18.651 +C Make\ssure\sthe\somit-noop-left-join\soptimization\sis\snot\sapplied\sif\scolumns\nof\sthe\sLEFT\sJOIN\sare\sused\sin\sthe\sORDER\sBY\sclause.\s\s\nTicket\s[be84e357c035] +D 2013-09-03T14:03:47.008 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 573a815c28a7c70b5148a23ec040bb8992e51e5d +F src/where.c 99477e9dd4d4d33be32115b4fbd18b6f033d045a F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1041,7 +1041,7 @@ F test/walro.test 6cc247a0cc9b36aeea2057dd28a922a1cdfbd630 F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e -F test/where.test da54153a4c1571ea1b95659e5bec8119edf786aa +F test/where.test 8d66dfbfd4d12816f74f854dbf67dee492c06267 F test/where2.test 76d5346f7edb2a6a0442dcf3e9d088ac6903e0b5 F test/where3.test d28c51f257e60be30f74308fa385ceeddfb54a6e F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2 @@ -1109,7 +1109,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 0a702c4b4c35fdbcb62e3ab88b9e57d7ea0052a8 -R 5255609fa5f702769f786eafe83d1965 +P f7079b5365dd6cd8324a4fb23605e81476122ed6 +R ef683c5e75a524283b39e51db1610c55 U drh -Z 3ad66b5373e173075a1fd9a0798ca8c7 +Z 7e7396aa706179eb8731d96e0b228672 diff --git a/manifest.uuid b/manifest.uuid index 59f020c938..4af698a9c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f7079b5365dd6cd8324a4fb23605e81476122ed6 \ No newline at end of file +0303d6bc7112e6f810ae1bd75cafc5ffc51f5212 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 39650d62e9..b633dfd574 100644 --- a/src/where.c +++ b/src/where.c @@ -5909,7 +5909,7 @@ WhereInfo *sqlite3WhereBegin( && OptimizationEnabled(db, SQLITE_OmitNoopJoin) ){ Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet); - if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy); + if( sWLB.pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, sWLB.pOrderBy); while( pWInfo->nLevel>=2 ){ WhereTerm *pTerm, *pEnd; pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop; diff --git a/test/where.test b/test/where.test index 42170ceac7..09ad0bce6d 100644 --- a/test/where.test +++ b/test/where.test @@ -1304,4 +1304,33 @@ do_test where-17.5 { } } {42 1 43 1} +# Ticket [be84e357c035d068135f20bcfe82761bbf95006b] 2013-09-03 +# Segfault during query involving LEFT JOIN column in the ORDER BY clause. +# +do_execsql_test where-18.1 { + CREATE TABLE t181(a); + CREATE TABLE t182(b,c); + INSERT INTO t181 VALUES(1); + SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL; +} {1} +do_execsql_test where-18.2 { + SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +c; +} {1} +do_execsql_test where-18.3 { + SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c; +} {1} +do_execsql_test where-18.4 { + INSERT INTO t181 VALUES(1),(1),(1),(1); + SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +c; +} {1} +do_execsql_test where-18.5 { + INSERT INTO t181 VALUES(2); + SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL, +a; +} {1 2} +do_execsql_test where-18.6 { + INSERT INTO t181 VALUES(2); + SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +a, +c IS NULL; +} {1 2} + + finish_test