From 3535ec3e10555c1b75b4854dd6c7a52b99cde816 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Aug 2013 16:56:44 +0000 Subject: [PATCH 01/19] Remove unreachable branches in expr.c, replacing them with assert() and testcase() statements. FossilOrigin-Name: 9103c27ceb3f4023ea3a41b679a10717d3f80210 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 23e2bb7256..4bb5e63c86 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\s".import"\scommand\sof\sthe\scommand-line\sshell,\sstart\sa\stransaction\nif\sthere\sis\snot\sone\sactive\salready. -D 2013-08-06T14:36:36.363 +C Remove\sunreachable\sbranches\sin\sexpr.c,\sreplacing\sthem\swith\sassert()\sand\ntestcase()\sstatements. +D 2013-08-06T16:56:44.584 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -172,7 +172,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 4262c227bc91cecc61ae37ed3a40f08069cfa267 F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/delete.c 2317c814866d9aa71fea16b3faf4fdd4d6a49b94 -F src/expr.c 7e55edefb8bd0b35b382ce9226c58472cd63a443 +F src/expr.c cd4fb5acb6060a2fec30dc07fef7f8113ff3f8ad F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 914a6bbd987d857c41ac9d244efa6641f36faadb F src/func.c 5c50c1ea31fd864b0fe921fe1a8d4c55acd609ef @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 2b1743d60171635c1e5a6ede6b4928f4671f948d -R 52d68f7d6fd0cf4ecec25cf61e17c3e0 +P 5dcc2d91bd343cd0fac79d3c8f079a5ce534cdf7 +R 4c2c4347dbc9045867f7f93fb89a2b59 U drh -Z 274a34c6d0a826d2bb04d7b9aabecdb7 +Z 4578d43c48945a1e8da3abe73645bfd7 diff --git a/manifest.uuid b/manifest.uuid index a49cab56b3..6f265e5fa6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5dcc2d91bd343cd0fac79d3c8f079a5ce534cdf7 \ No newline at end of file +9103c27ceb3f4023ea3a41b679a10717d3f80210 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 3857d5d841..5fca1f12c0 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1739,10 +1739,11 @@ int sqlite3CodeSubselect( return 0; } pEList = pExpr->x.pSelect->pEList; - if( pKeyInfo && ALWAYS(pEList!=0 && pEList->nExpr>0) ){ - pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, - pEList->a[0].pExpr); - } + assert( pKeyInfo!=0 ); /* OOM will exit after sqlite3Select() */ + assert( pEList!=0 ); + assert( pEList->nExpr>0 ); + pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, + pEList->a[0].pExpr); }else if( ALWAYS(pExpr->x.pList!=0) ){ /* Case 2: expr IN (exprlist) ** From 812ea833435970cd78ff94cf51f75ac4929027d6 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Aug 2013 17:24:23 +0000 Subject: [PATCH 02/19] Add a testcase() macro to verify OOM coverage. FossilOrigin-Name: d43dcbc488120aeb7104ab9e6a27f62bb348bf6a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/expr.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4bb5e63c86..8d38e2ab31 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunreachable\sbranches\sin\sexpr.c,\sreplacing\sthem\swith\sassert()\sand\ntestcase()\sstatements. -D 2013-08-06T16:56:44.584 +C Add\sa\stestcase()\smacro\sto\sverify\sOOM\scoverage. +D 2013-08-06T17:24:23.114 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -172,7 +172,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 4262c227bc91cecc61ae37ed3a40f08069cfa267 F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/delete.c 2317c814866d9aa71fea16b3faf4fdd4d6a49b94 -F src/expr.c cd4fb5acb6060a2fec30dc07fef7f8113ff3f8ad +F src/expr.c 0bbb44462a19169189b2709fbbd800950521b5ae F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 914a6bbd987d857c41ac9d244efa6641f36faadb F src/func.c 5c50c1ea31fd864b0fe921fe1a8d4c55acd609ef @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 5dcc2d91bd343cd0fac79d3c8f079a5ce534cdf7 -R 4c2c4347dbc9045867f7f93fb89a2b59 +P 9103c27ceb3f4023ea3a41b679a10717d3f80210 +R 66ae81cd15b8b8eab1989c80a506936c U drh -Z 4578d43c48945a1e8da3abe73645bfd7 +Z 5187416864919678052fb71ae4c5e22d diff --git a/manifest.uuid b/manifest.uuid index 6f265e5fa6..453fe9f728 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9103c27ceb3f4023ea3a41b679a10717d3f80210 \ No newline at end of file +d43dcbc488120aeb7104ab9e6a27f62bb348bf6a \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 5fca1f12c0..5c5297c187 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1734,12 +1734,13 @@ int sqlite3CodeSubselect( dest.affSdst = (u8)affinity; assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable ); pExpr->x.pSelect->iLimit = 0; + testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */ if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){ sqlite3DbFree(pParse->db, pKeyInfo); return 0; } pEList = pExpr->x.pSelect->pEList; - assert( pKeyInfo!=0 ); /* OOM will exit after sqlite3Select() */ + assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */ assert( pEList!=0 ); assert( pEList->nExpr>0 ); pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, From d9b8c0d7611dc66fc8065ebcfcb0cb08c194574b Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Aug 2013 18:21:21 +0000 Subject: [PATCH 03/19] Update the configure script to use the latest version number (3.8.0). FossilOrigin-Name: 52e8ec5e24730efa6d89cbaf1e03bc1d5c59cc05 --- configure | 18 +++++++++--------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/configure b/configure index 90452c95a2..a7281f089c 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.62 for sqlite 3.7.17. +# Generated by GNU Autoconf 2.62 for sqlite 3.8.0. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. @@ -743,8 +743,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='sqlite' PACKAGE_TARNAME='sqlite' -PACKAGE_VERSION='3.7.17' -PACKAGE_STRING='sqlite 3.7.17' +PACKAGE_VERSION='3.8.0' +PACKAGE_STRING='sqlite 3.8.0' PACKAGE_BUGREPORT='' # Factoring default headers for most tests. @@ -1484,7 +1484,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sqlite 3.7.17 to adapt to many kinds of systems. +\`configure' configures sqlite 3.8.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1549,7 +1549,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sqlite 3.7.17:";; + short | recursive ) echo "Configuration of sqlite 3.8.0:";; esac cat <<\_ACEOF @@ -1665,7 +1665,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sqlite configure 3.7.17 +sqlite configure 3.8.0 generated by GNU Autoconf 2.62 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1679,7 +1679,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sqlite $as_me 3.7.17, which was +It was created by sqlite $as_me 3.8.0, which was generated by GNU Autoconf 2.62. Invocation command line was $ $0 $@ @@ -14032,7 +14032,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sqlite $as_me 3.7.17, which was +This file was extended by sqlite $as_me 3.8.0, which was generated by GNU Autoconf 2.62. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -14085,7 +14085,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -sqlite config.status 3.7.17 +sqlite config.status 3.8.0 configured by $0, generated by GNU Autoconf 2.62, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/manifest b/manifest index 8d38e2ab31..b54d1a1dae 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stestcase()\smacro\sto\sverify\sOOM\scoverage. -D 2013-08-06T17:24:23.114 +C Update\sthe\sconfigure\sscript\sto\suse\sthe\slatest\sversion\snumber\s(3.8.0). +D 2013-08-06T18:21:21.097 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -38,7 +38,7 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977 F config.h.in 0921066a13130082764ab4ab6456f7b5bebe56de F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55 -F configure 8bb8bd13d3c918c4c1c73480930e81f955ac298a x +F configure 27e9279a219b652bd1c53439353a5e5be70214b2 x F configure.ac 81c43d151d0b0e406be056394cc9ff4cb3fd0444 F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html 334dbf6621b8fb8790297ec1abf3cfa4621709d1 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 9103c27ceb3f4023ea3a41b679a10717d3f80210 -R 66ae81cd15b8b8eab1989c80a506936c +P d43dcbc488120aeb7104ab9e6a27f62bb348bf6a +R 3b3e55282f1c280f4b646ca0138070fb U drh -Z 5187416864919678052fb71ae4c5e22d +Z 4115d1bc46bf087fcf132b66c03b606d diff --git a/manifest.uuid b/manifest.uuid index 453fe9f728..e01b873041 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d43dcbc488120aeb7104ab9e6a27f62bb348bf6a \ No newline at end of file +52e8ec5e24730efa6d89cbaf1e03bc1d5c59cc05 \ No newline at end of file From d3f4964168418a8e0a5b4e5e6ef905d5e56957ca Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Aug 2013 18:35:31 +0000 Subject: [PATCH 04/19] Adjust #ifdefs in test_autoext.c so that it compiles with SQLITE_OMIT_LOAD_EXTENSION. Fix compiler warnings in two other test modules. No changes to the core. FossilOrigin-Name: 89930ea3c3b3bd078f641b2c5203d851083bbf1a --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/test_autoext.c | 2 +- src/test_demovfs.c | 2 +- src/test_fs.c | 4 +++- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index b54d1a1dae..a87c76f6f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sconfigure\sscript\sto\suse\sthe\slatest\sversion\snumber\s(3.8.0). -D 2013-08-06T18:21:21.097 +C Adjust\s#ifdefs\sin\stest_autoext.c\sso\sthat\sit\scompiles\swith\s\nSQLITE_OMIT_LOAD_EXTENSION.\s\sFix\scompiler\swarnings\sin\stwo\sother\ntest\smodules.\s\sNo\schanges\sto\sthe\score. +D 2013-08-06T18:35:31.726 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -236,13 +236,13 @@ F src/test7.c 126b886b53f0358b92aba9b81d3fcbfbe9a93cd6 F src/test8.c 7ee77ea522ae34aa691dfe407139dec80d4fc039 F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60 F src/test_async.c 21e11293a2f72080eda70e1124e9102044531cd8 -F src/test_autoext.c 32cff3d01cdd3202486e623c3f8103ed04cb57fa +F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 F src/test_backup.c 3875e899222b651e18b662f86e0e50daa946344e F src/test_btree.c 5b89601dcb42a33ba8b820a6b763cc9cb48bac16 F src/test_config.c 95bb33e9dcaa340a296c0bf0e0ba3d1a1c8004c0 -F src/test_demovfs.c 20a4975127993f4959890016ae9ce5535a880094 +F src/test_demovfs.c 69b2085076654ebc18014cbc6386f04409c959a9 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc -F src/test_fs.c 8f786bfd0ad48030cf2a06fb1f050e9c60a150d7 +F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f F src/test_func.c 3a8dd37c08ab43b76d38eea2836e34a3897bf170 F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd F src/test_init.c 3cbad7ce525aec925f8fda2192d576d47f0d478a @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P d43dcbc488120aeb7104ab9e6a27f62bb348bf6a -R 3b3e55282f1c280f4b646ca0138070fb +P 52e8ec5e24730efa6d89cbaf1e03bc1d5c59cc05 +R a1467a2c305e4e64db55068e564d786d U drh -Z 4115d1bc46bf087fcf132b66c03b606d +Z 082cd0bd0486defd1efdbdfa0db86156 diff --git a/manifest.uuid b/manifest.uuid index e01b873041..70a2c163ab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -52e8ec5e24730efa6d89cbaf1e03bc1d5c59cc05 \ No newline at end of file +89930ea3c3b3bd078f641b2c5203d851083bbf1a \ No newline at end of file diff --git a/src/test_autoext.c b/src/test_autoext.c index 4a5a5caa08..a5236d2390 100644 --- a/src/test_autoext.c +++ b/src/test_autoext.c @@ -208,13 +208,13 @@ int Sqlitetest_autoext_Init(Tcl_Interp *interp){ autoExtCubeObjCmd, 0, 0); Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken", autoExtBrokenObjCmd, 0, 0); -#endif Tcl_CreateObjCommand(interp, "sqlite3_cancel_auto_extension_sqr", cancelAutoExtSqrObjCmd, 0, 0); Tcl_CreateObjCommand(interp, "sqlite3_cancel_auto_extension_cube", cancelAutoExtCubeObjCmd, 0, 0); Tcl_CreateObjCommand(interp, "sqlite3_cancel_auto_extension_broken", cancelAutoExtBrokenObjCmd, 0, 0); +#endif Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension", resetAutoExtObjCmd, 0, 0); return TCL_OK; diff --git a/src/test_demovfs.c b/src/test_demovfs.c index 637627071d..c63b0a8b7a 100644 --- a/src/test_demovfs.c +++ b/src/test_demovfs.c @@ -536,7 +536,7 @@ static int demoFullPathname( if( zPath[0]=='/' ){ zDir[0] = '\0'; }else{ - getcwd(zDir, sizeof(zDir)); + if( getcwd(zDir, sizeof(zDir))==0 ) return SQLITE_IOERR; } zDir[MAXPATHNAME] = '\0'; diff --git a/src/test_fs.c b/src/test_fs.c index 478cad80b1..417c81b49f 100644 --- a/src/test_fs.c +++ b/src/test_fs.c @@ -195,6 +195,7 @@ static int fsColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){ const char *zFile = (const char *)sqlite3_column_text(pCur->pStmt, 1); struct stat sbuf; int fd; + int n; fd = open(zFile, O_RDONLY); if( fd<0 ) return SQLITE_IOERR; @@ -214,8 +215,9 @@ static int fsColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){ pCur->nAlloc = nNew; } - read(fd, pCur->zBuf, sbuf.st_size); + n = (int)read(fd, pCur->zBuf, sbuf.st_size); close(fd); + if( n!=sbuf.st_size ) return SQLITE_ERROR; pCur->nBuf = sbuf.st_size; pCur->zBuf[pCur->nBuf] = '\0'; From 9fe809c5619d04d042ae46d5ca7cb7d7ee86df81 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Aug 2013 19:18:17 +0000 Subject: [PATCH 05/19] Fix a test case related to partial indices so that it works even if STAT3 is disabled. FossilOrigin-Name: 153c645025637bbff14dfce793e4b92210ded7e8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/index6.test | 21 +++++++++++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index a87c76f6f4..6e6e80a710 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Adjust\s#ifdefs\sin\stest_autoext.c\sso\sthat\sit\scompiles\swith\s\nSQLITE_OMIT_LOAD_EXTENSION.\s\sFix\scompiler\swarnings\sin\stwo\sother\ntest\smodules.\s\sNo\schanges\sto\sthe\score. -D 2013-08-06T18:35:31.726 +C Fix\sa\stest\scase\srelated\sto\spartial\sindices\sso\sthat\sit\sworks\seven\sif\nSTAT3\sis\sdisabled. +D 2013-08-06T19:18:17.913 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -590,7 +590,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6 F test/index3.test 423a25c789fc8cc51aaf2a4370bbdde2d9e9eed7 F test/index4.test 2983216eb8c86ee62d9ed7cb206b5cc3331c0026 F test/index5.test fc07c14193c0430814e7a08b5da46888ee795c33 -F test/index6.test 0005b3093012c6d0f20cc54d9057210221216143 +F test/index6.test f53a788b813eb6937346867bae9e587c434dd9a1 F test/indexedby.test 0e959308707c808515c3a51363f7a9835027108c F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 52e8ec5e24730efa6d89cbaf1e03bc1d5c59cc05 -R a1467a2c305e4e64db55068e564d786d +P 89930ea3c3b3bd078f641b2c5203d851083bbf1a +R 22d053337a8290c9ac6b0d4c1264f844 U drh -Z 082cd0bd0486defd1efdbdfa0db86156 +Z 21ef7545513488fc6735d995a8f856cc diff --git a/manifest.uuid b/manifest.uuid index 70a2c163ab..2ed121756d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -89930ea3c3b3bd078f641b2c5203d851083bbf1a \ No newline at end of file +153c645025637bbff14dfce793e4b92210ded7e8 \ No newline at end of file diff --git a/test/index6.test b/test/index6.test index e9ea570b83..d70e86aefe 100644 --- a/test/index6.test +++ b/test/index6.test @@ -144,12 +144,21 @@ do_test index6-2.2 { SELECT * FROM t2 WHERE a=5; } } {/.* TABLE t2 USING INDEX t2a1 .*/} -do_test index6-2.3 { - execsql { - EXPLAIN QUERY PLAN - SELECT * FROM t2 WHERE a IS NOT NULL; - } -} {/.* TABLE t2 USING INDEX t2a1 .*/} +ifcapable stat3 { + do_test index6-2.3stat3 { + execsql { + EXPLAIN QUERY PLAN + SELECT * FROM t2 WHERE a IS NOT NULL; + } + } {/.* TABLE t2 USING INDEX t2a1 .*/} +} else { + do_test index6-2.3stat3 { + execsql { + EXPLAIN QUERY PLAN + SELECT * FROM t2 WHERE a IS NOT NULL AND a>0; + } + } {/.* TABLE t2 USING INDEX t2a1 .*/} +} do_test index6-2.4 { execsql { EXPLAIN QUERY PLAN From 4a6fc3596b1d2995403bf7193b51cd276274b553 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 7 Aug 2013 01:18:38 +0000 Subject: [PATCH 06/19] Fix typos and add clarification to comments in where.c. No code changes. FossilOrigin-Name: f8d8790ede0fcaf6c5b60ac22919c1d97c74e838 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 33 +++++++++++++++++---------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 6e6e80a710..fda1a12844 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stest\scase\srelated\sto\spartial\sindices\sso\sthat\sit\sworks\seven\sif\nSTAT3\sis\sdisabled. -D 2013-08-06T19:18:17.913 +C Fix\stypos\sand\sadd\sclarification\sto\scomments\sin\swhere.c.\s\sNo\scode\schanges. +D 2013-08-07T01:18:38.449 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 2e8b489db47e20ae36cd247932dc671c9ded0624 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 67245bb73fd9cc04ee7796a0f358d4910c45cfe9 +F src/where.c ea01a52eb31e54dda97b8e39c2e5b38faa13dce5 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 89930ea3c3b3bd078f641b2c5203d851083bbf1a -R 22d053337a8290c9ac6b0d4c1264f844 +P 153c645025637bbff14dfce793e4b92210ded7e8 +R bd41820faa238dc5341c3c2a4f14484a U drh -Z 21ef7545513488fc6735d995a8f856cc +Z dce4447dee7fcad2bdba25f503c8b865 diff --git a/manifest.uuid b/manifest.uuid index 2ed121756d..7511d7cd14 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -153c645025637bbff14dfce793e4b92210ded7e8 \ No newline at end of file +f8d8790ede0fcaf6c5b60ac22919c1d97c74e838 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 2bf3aaecb7..9be48a427f 100644 --- a/src/where.c +++ b/src/where.c @@ -33,7 +33,7 @@ # define WHERETRACE(K,X) #endif -/* Forward reference +/* Forward references */ typedef struct WhereClause WhereClause; typedef struct WhereMaskSet WhereMaskSet; @@ -55,14 +55,15 @@ typedef struct WhereOrSet WhereOrSet; ** So all costs can be stored in a 16-bit unsigned integer without risk ** of overflow. ** -** Costs are estimates, so don't go to the computational trouble to compute -** 10*log2(X) exactly. Instead, a close estimate is used. Any value of -** X<=1 is stored as 0. X=2 is 10. X=3 is 16. X=1000 is 99. etc. +** Costs are estimates, so no effort is made to compute 10*log2(X) exactly. +** Instead, a close estimate is used. Any value of X<=1 is stored as 0. +** X=2 is 10. X=3 is 16. X=1000 is 99. etc. ** ** The tool/wherecosttest.c source file implements a command-line program -** that will convert between WhereCost to integers and do addition and -** multiplication on WhereCost values. That command-line program is a -** useful utility to have around when working with this module. +** that will convert WhereCosts to integers, convert integers to WhereCosts +** and do addition and multiplication on WhereCost values. The wherecosttest +** command-line program is a useful utility to have around when working with +** this module. */ typedef unsigned short int WhereCost; @@ -165,8 +166,8 @@ struct WhereOrCost { }; /* The WhereOrSet object holds a set of possible WhereOrCosts that -** correspond to the subquery(s) of OR-clause processing. At most -** favorable N_OR_COST elements are retained. +** correspond to the subquery(s) of OR-clause processing. Only the +** best N_OR_COST elements are retained. */ #define N_OR_COST 3 struct WhereOrSet { @@ -232,9 +233,9 @@ struct WherePath { ** ** (t1.X ) OR (t1.Y ) OR .... ** -** In this second case, wtFlag as the TERM_ORINFO set and eOperator==WO_OR +** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR ** and the WhereTerm.u.pOrInfo field points to auxiliary information that -** is collected about the +** is collected about the OR clause. ** ** If a term in the WHERE clause does not match either of the two previous ** categories, then eOperator==0. The WhereTerm.pExpr field is still set @@ -746,7 +747,7 @@ static void createMask(WhereMaskSet *pMaskSet, int iCursor){ } /* -** These routine walk (recursively) an expression tree and generates +** These routines walk (recursively) an expression tree and generate ** a bitmask indicating which tables are used in that expression ** tree. */ @@ -1263,10 +1264,10 @@ static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ ** From another point of view, "indexable" means that the subterm could ** potentially be used with an index if an appropriate index exists. ** This analysis does not consider whether or not the index exists; that -** is something the bestIndex() routine will determine. This analysis -** only looks at whether subterms appropriate for indexing exist. +** is decided elsewhere. This analysis only looks at whether subterms +** appropriate for indexing exist. ** -** All examples A through E above all satisfy case 2. But if a term +** All examples A through E above satisfy case 2. But if a term ** also statisfies case 1 (such as B) we know that the optimizer will ** always prefer case 1, so in that case we pretend that case 2 is not ** satisfied. @@ -1933,7 +1934,7 @@ static int isDistinctRedundant( } /* -** The (an approximate) sum of two WhereCosts. This computation is +** Find (an approximate) sum of two WhereCosts. This computation is ** not a simple "+" operator because WhereCost is stored as a logarithmic ** value. ** From 3b449ee48144fe306f758dfe9669c5fd3bf983c0 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 7 Aug 2013 14:18:45 +0000 Subject: [PATCH 07/19] Add a guard #ifndef to test_intarray.h to prevent harm if it is #included more than once. Add a comment on the closing #endif of the guards on sqlite3.h and test_multiplex.h. FossilOrigin-Name: 0ad83ceb79767738bd06a28840cf84da0464ab4f --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/sqlite.h.in | 2 +- src/test_intarray.h | 3 +++ src/test_multiplex.h | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index fda1a12844..190659f0f2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypos\sand\sadd\sclarification\sto\scomments\sin\swhere.c.\s\sNo\scode\schanges. -D 2013-08-07T01:18:38.449 +C Add\sa\sguard\s#ifndef\sto\stest_intarray.h\sto\sprevent\sharm\sif\sit\sis\s#included\nmore\sthan\sonce.\s\sAdd\sa\scomment\son\sthe\sclosing\s#endif\sof\sthe\sguards\son\nsqlite3.h\sand\stest_multiplex.h. +D 2013-08-07T14:18:45.279 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -218,7 +218,7 @@ F src/resolve.c 17e670996729ac41aadf6a31f57b4e6f29b3d819 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 -F src/sqlite.h.in 442c109e0c3447c34b1794971ecdb673ce08a843 +F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqliteInt.h def0e436c0d4ca5084305ca6ae898020fbafaae4 @@ -247,12 +247,12 @@ F src/test_func.c 3a8dd37c08ab43b76d38eea2836e34a3897bf170 F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd F src/test_init.c 3cbad7ce525aec925f8fda2192d576d47f0d478a F src/test_intarray.c 87847c71c3c36889c0bcc9c4baf9d31881665d61 -F src/test_intarray.h b999bb18d090b8d9d9c49d36ec37ef8f341fe169 +F src/test_intarray.h 2ece66438cfd177b78d1bfda7a4180cd3a10844d F src/test_journal.c f5c0a05b7b3d5930db769b5ee6c3766dc2221a64 F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e F src/test_malloc.c a105801222c0514f8befa2a1712a95505cce099a F src/test_multiplex.c 5d691eeb6cb6aa7888da28eba5e62a9a857d3c0f -F src/test_multiplex.h 9b63b95f07acedee425fdfe49a47197c9bf5f9d8 +F src/test_multiplex.h 110a8c4d356e0aa464ca8730375608a9a0b61ae1 F src/test_mutex.c 293042d623ebba969160f471a82aa1551626454f F src/test_onefile.c 0396f220561f3b4eedc450cef26d40c593c69a25 F src/test_osinst.c 90a845c8183013d80eccb1f29e8805608516edba @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 153c645025637bbff14dfce793e4b92210ded7e8 -R bd41820faa238dc5341c3c2a4f14484a +P f8d8790ede0fcaf6c5b60ac22919c1d97c74e838 +R 2f7b5cf183df4b523d2c445c6f8fcaa5 U drh -Z dce4447dee7fcad2bdba25f503c8b865 +Z cdc793001b4bb9536e6929a443adf8d1 diff --git a/manifest.uuid b/manifest.uuid index 7511d7cd14..bcffddd0ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8d8790ede0fcaf6c5b60ac22919c1d97c74e838 \ No newline at end of file +0ad83ceb79767738bd06a28840cf84da0464ab4f \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 90e78d9acc..fc76029bcb 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -7228,4 +7228,4 @@ int sqlite3_vtab_on_conflict(sqlite3 *); #ifdef __cplusplus } /* End of the 'extern "C"' block */ #endif -#endif +#endif /* _SQLITE3_H_ */ diff --git a/src/test_intarray.h b/src/test_intarray.h index 691337d1ae..6d26235a87 100644 --- a/src/test_intarray.h +++ b/src/test_intarray.h @@ -75,6 +75,8 @@ ** action to free the intarray objects. */ #include "sqlite3.h" +#ifndef _INTARRAY_H_ +#define _INTARRAY_H_ /* ** Make sure we can call this stuff from C++. @@ -123,3 +125,4 @@ int sqlite3_intarray_bind( #ifdef __cplusplus } /* End of the 'extern "C"' block */ #endif +#endif /* _INTARRAY_H_ */ diff --git a/src/test_multiplex.h b/src/test_multiplex.h index b7e1afea5f..9fe2f0f2b2 100644 --- a/src/test_multiplex.h +++ b/src/test_multiplex.h @@ -96,4 +96,4 @@ extern int sqlite3_multiplex_shutdown(void); } /* End of the 'extern "C"' block */ #endif -#endif +#endif /* _TEST_MULTIPLEX_H */ From 869c0409e3a7a54341cb408533b3c668b9df916d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 7 Aug 2013 23:15:52 +0000 Subject: [PATCH 08/19] If the SQLITE_ALLOW_URI_AUTHORITY compile-time option is set, then allow non-localhost authorities on URI filenames and pass them through as a UNC to the underlying VFS. FossilOrigin-Name: 3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 190659f0f2..c9e8d0b682 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sguard\s#ifndef\sto\stest_intarray.h\sto\sprevent\sharm\sif\sit\sis\s#included\nmore\sthan\sonce.\s\sAdd\sa\scomment\son\sthe\sclosing\s#endif\sof\sthe\sguards\son\nsqlite3.h\sand\stest_multiplex.h. -D 2013-08-07T14:18:45.279 +C If\sthe\sSQLITE_ALLOW_URI_AUTHORITY\scompile-time\soption\sis\sset,\sthen\sallow\nnon-localhost\sauthorities\son\sURI\sfilenames\sand\spass\sthem\sthrough\sas\sa\sUNC\nto\sthe\sunderlying\sVFS. +D 2013-08-07T23:15:52.266 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 b2592b4119f9b34d20861d1a73a44f07d061508c +F src/main.c 482135b0bf855d621ef10c5bb56c63df23b2ddec F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f8d8790ede0fcaf6c5b60ac22919c1d97c74e838 -R 2f7b5cf183df4b523d2c445c6f8fcaa5 +P 0ad83ceb79767738bd06a28840cf84da0464ab4f +R a230045986289598d392f4ac16d8f85f U drh -Z cdc793001b4bb9536e6929a443adf8d1 +Z 3dff46ea9ed1198b77cd17bced6ea4de diff --git a/manifest.uuid b/manifest.uuid index bcffddd0ea..bb59190386 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ad83ceb79767738bd06a28840cf84da0464ab4f \ No newline at end of file +3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 \ No newline at end of file diff --git a/src/main.c b/src/main.c index d848dc7f59..9e8a6ed063 100644 --- a/src/main.c +++ b/src/main.c @@ -2178,20 +2178,20 @@ int sqlite3ParseUri( zFile = sqlite3_malloc(nByte); if( !zFile ) return SQLITE_NOMEM; + iIn = 5; +#ifndef SQLITE_ALLOW_URI_AUTHORITY /* Discard the scheme and authority segments of the URI. */ if( zUri[5]=='/' && zUri[6]=='/' ){ iIn = 7; while( zUri[iIn] && zUri[iIn]!='/' ) iIn++; - if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){ *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", iIn-7, &zUri[7]); rc = SQLITE_ERROR; goto parse_uri_out; } - }else{ - iIn = 5; } +#endif /* Copy the filename and any query parameters into the zFile buffer. ** Decode %HH escape codes along the way. From ab80be99e3c96e03982056e33853ec52a34222eb Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 8 Aug 2013 14:38:45 +0000 Subject: [PATCH 09/19] If the SQLITE_EXTRA_INIT function is defined, make sure it is called only once by the effective sqlite3_initialize() call. FossilOrigin-Name: e2b597cafe7c8a8313b051d6a302fed54f235727 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c9e8d0b682..6cc104b469 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\sSQLITE_ALLOW_URI_AUTHORITY\scompile-time\soption\sis\sset,\sthen\sallow\nnon-localhost\sauthorities\son\sURI\sfilenames\sand\spass\sthem\sthrough\sas\sa\sUNC\nto\sthe\sunderlying\sVFS. -D 2013-08-07T23:15:52.266 +C If\sthe\sSQLITE_EXTRA_INIT\sfunction\sis\sdefined,\smake\ssure\sit\sis\scalled\sonly\nonce\sby\sthe\seffective\ssqlite3_initialize()\scall. +D 2013-08-08T14:38:45.404 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 482135b0bf855d621ef10c5bb56c63df23b2ddec +F src/main.c f6eb795f17eb88205b55e5116fb37e6593707d82 F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 0ad83ceb79767738bd06a28840cf84da0464ab4f -R a230045986289598d392f4ac16d8f85f +P 3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 +R f58cae922c11c825e7cdfcd2f4c52823 U drh -Z 3dff46ea9ed1198b77cd17bced6ea4de +Z 6adac74ecb750c6ba6eb610c8156f9d8 diff --git a/manifest.uuid b/manifest.uuid index bb59190386..cb24e03baa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 \ No newline at end of file +e2b597cafe7c8a8313b051d6a302fed54f235727 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 9e8a6ed063..217221d238 100644 --- a/src/main.c +++ b/src/main.c @@ -117,6 +117,9 @@ char *sqlite3_data_directory = 0; int sqlite3_initialize(void){ MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ int rc; /* Result code */ +#ifdef SQLITE_EXTRA_INIT + int bRunExtraInit = 0; /* Extra initialization needed */ +#endif #ifdef SQLITE_OMIT_WSD rc = sqlite3_wsd_init(4096, 24); @@ -214,6 +217,9 @@ int sqlite3_initialize(void){ sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); sqlite3GlobalConfig.isInit = 1; +#ifdef SQLITE_EXTRA_INIT + bRunExtraInit = 1; +#endif } sqlite3GlobalConfig.inProgress = 0; } @@ -254,7 +260,7 @@ int sqlite3_initialize(void){ ** compile-time option. */ #ifdef SQLITE_EXTRA_INIT - if( rc==SQLITE_OK && sqlite3GlobalConfig.isInit ){ + if( bRunExtraInit ){ int SQLITE_EXTRA_INIT(const char*); rc = SQLITE_EXTRA_INIT(0); } From 037933b8a75f01013fc7fb2899dc06c57eef30dc Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 13 Aug 2013 22:33:41 +0000 Subject: [PATCH 10/19] Fix an outdated comment and a comment typo. No changes to code. FossilOrigin-Name: ac336959490083ffeaaf25aaec97ecb59a2f4536 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/main.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 6cc104b469..c1132e63b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\sSQLITE_EXTRA_INIT\sfunction\sis\sdefined,\smake\ssure\sit\sis\scalled\sonly\nonce\sby\sthe\seffective\ssqlite3_initialize()\scall. -D 2013-08-08T14:38:45.404 +C Fix\san\soutdated\scomment\sand\sa\scomment\stypo.\s\sNo\schanges\sto\scode. +D 2013-08-13T22:33:41.968 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 f6eb795f17eb88205b55e5116fb37e6593707d82 +F src/main.c 4e4cd5c2ee09db496c0dde79b507bba6b8bcbdcb F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 -R f58cae922c11c825e7cdfcd2f4c52823 -U drh -Z 6adac74ecb750c6ba6eb610c8156f9d8 +P e2b597cafe7c8a8313b051d6a302fed54f235727 +R 725a28de0f0d05555ad0060ad37d65c5 +U mistachkin +Z 538f6198c3d2d5189ca428ea230684f3 diff --git a/manifest.uuid b/manifest.uuid index cb24e03baa..57d601b84e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e2b597cafe7c8a8313b051d6a302fed54f235727 \ No newline at end of file +ac336959490083ffeaaf25aaec97ecb59a2f4536 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 217221d238..6932bf7b9d 100644 --- a/src/main.c +++ b/src/main.c @@ -448,8 +448,8 @@ int sqlite3_config(int op, ...){ memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); }else{ /* The heap pointer is not NULL, then install one of the - ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor - ** ENABLE_MEMSYS5 is defined, return an error. + ** mem5.c/mem3.c methods. The enclosing #if guarantees at + ** least one of these methods is currently enabled. */ #ifdef SQLITE_ENABLE_MEMSYS3 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); @@ -468,7 +468,7 @@ int sqlite3_config(int op, ...){ break; } - /* Record a pointer to the logger funcction and its first argument. + /* Record a pointer to the logger function and its first argument. ** The default is NULL. Logging is disabled if the function pointer is ** NULL. */ From 3dfaf6766c93993a897c3ee38d59a4b3a42c3a30 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 14 Aug 2013 00:20:23 +0000 Subject: [PATCH 11/19] Fix a few more minor comment typos. No changes to code. FossilOrigin-Name: 9e999081a59b161a0a1f968fbc01a1db9ea43b93 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/mem5.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index c1132e63b5..5e2d3872f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\soutdated\scomment\sand\sa\scomment\stypo.\s\sNo\schanges\sto\scode. -D 2013-08-13T22:33:41.968 +C Fix\sa\sfew\smore\sminor\scomment\stypos.\s\sNo\schanges\sto\scode. +D 2013-08-14T00:20:23.461 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -191,7 +191,7 @@ F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa F src/mem2.c e307323e86b5da1853d7111b68fd6b84ad6f09cf F src/mem3.c 61c9d47b792908c532ca3a62b999cf21795c6534 -F src/mem5.c c2c63b7067570b00bf33d751c39af24182316f7f +F src/mem5.c 0025308a93838022bd5696cf9627ff4e40b19918 F src/memjournal.c 0683aac6cab6ec2b5374c0db37c0deb2436a3785 F src/mutex.c d3b66a569368015e0fcb1ac15f81c119f504d3bc F src/mutex.h 5bc526e19dccc412b7ff04642f6fdad3fdfdabea @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P e2b597cafe7c8a8313b051d6a302fed54f235727 -R 725a28de0f0d05555ad0060ad37d65c5 +P ac336959490083ffeaaf25aaec97ecb59a2f4536 +R b65660836257e0b7350de3a479496a6b U mistachkin -Z 538f6198c3d2d5189ca428ea230684f3 +Z 2adbd114c976ac90cd58966c1c244f68 diff --git a/manifest.uuid b/manifest.uuid index 57d601b84e..c5b110f948 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac336959490083ffeaaf25aaec97ecb59a2f4536 \ No newline at end of file +9e999081a59b161a0a1f968fbc01a1db9ea43b93 \ No newline at end of file diff --git a/src/mem5.c b/src/mem5.c index 783cef6176..5f99ebf43d 100644 --- a/src/mem5.c +++ b/src/mem5.c @@ -130,13 +130,13 @@ static SQLITE_WSD struct Mem5Global { } mem5; /* -** Access the static variable through a macro for SQLITE_OMIT_WSD +** Access the static variable through a macro for SQLITE_OMIT_WSD. */ #define mem5 GLOBAL(struct Mem5Global, mem5) /* ** Assuming mem5.zPool is divided up into an array of Mem5Link -** structures, return a pointer to the idx-th such lik. +** structures, return a pointer to the idx-th such link. */ #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom])) @@ -232,7 +232,7 @@ static int memsys5UnlinkFirst(int iLogsize){ ** Return a block of memory of at least nBytes in size. ** Return NULL if unable. Return NULL if nBytes==0. ** -** The caller guarantees that nByte positive. +** The caller guarantees that nByte is positive. ** ** The caller has obtained a mutex prior to invoking this ** routine so there is never any chance that two or more @@ -354,7 +354,7 @@ static void memsys5FreeUnsafe(void *pOld){ } /* -** Allocate nBytes of memory +** Allocate nBytes of memory. */ static void *memsys5Malloc(int nBytes){ sqlite3_int64 *p = 0; From 1f28e0703fb33668db136898d03874832babf74f Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 15 Aug 2013 08:06:15 +0000 Subject: [PATCH 12/19] Make it easy to attach a debugger the test fixture process prior to any tests being run. FossilOrigin-Name: c23acba11bfefc019b5945cfb345f9afcf4b6242 --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/tclsqlite.c | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 5e2d3872f1..c257781adc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfew\smore\sminor\scomment\stypos.\s\sNo\schanges\sto\scode. -D 2013-08-14T00:20:23.461 +C Make\sit\seasy\sto\sattach\sa\sdebugger\sthe\stest\sfixture\sprocess\sprior\sto\sany\stests\sbeing\srun. +D 2013-08-15T08:06:15.562 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -225,7 +225,7 @@ F src/sqliteInt.h def0e436c0d4ca5084305ca6ae898020fbafaae4 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e -F src/tclsqlite.c b8835978e853a89bf58de88acc943a5ca94d752e +F src/tclsqlite.c 659dad8ef30b54831306a244b43e37af4725a444 F src/test1.c 870fc648a48cb6d6808393174f7ebe82b8c840fa F src/test2.c 7355101c085304b90024f2261e056cdff13c6c35 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c @@ -1105,7 +1105,10 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ac336959490083ffeaaf25aaec97ecb59a2f4536 -R b65660836257e0b7350de3a479496a6b +P 9e999081a59b161a0a1f968fbc01a1db9ea43b93 +R c32412a10fe0450296a67115895879b1 +T *branch * dbgTestFixture +T *sym-dbgTestFixture * +T -sym-trunk * U mistachkin -Z 2adbd114c976ac90cd58966c1c244f68 +Z 7b47b87c7211179488e7ecca78b01825 diff --git a/manifest.uuid b/manifest.uuid index c5b110f948..32c235aa4c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e999081a59b161a0a1f968fbc01a1db9ea43b93 \ No newline at end of file +c23acba11bfefc019b5945cfb345f9afcf4b6242 \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 6d2a51e5ab..42f7bcdc3a 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -41,6 +41,18 @@ #endif #include +/* Used to get the current process ID */ +#if !defined(_WIN32) +# include +# define GETPID getpid +#elif !defined(_WIN32_WCE) +# ifndef SQLITE_AMALGAMATION +# define WIN32_LEAN_AND_MEAN +# include +# endif +# define GETPID (int)GetCurrentProcessId +#endif + /* * Windows needs to know which symbols to export. Unix does not. * BUILD_sqlite should be undefined for Unix. @@ -3746,7 +3758,16 @@ static void init_all(Tcl_Interp *interp){ #define TCLSH_MAIN main /* Needed to fake out mktclapp */ int TCLSH_MAIN(int argc, char **argv){ Tcl_Interp *interp; - + +#if !defined(_WIN32_WCE) + if( getenv("BREAK") ){ + fprintf(stderr, + "attach debugger to process %d and press any key to continue.\n", + GETPID()); + fgetc(stdin); + } +#endif + /* Call sqlite3_shutdown() once before doing anything else. This is to ** test that sqlite3_shutdown() can be safely called by a process before ** sqlite3_initialize() is. */ From 26080d924120b24cdc93cd7ab84b98129a68f475 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Aug 2013 14:27:42 +0000 Subject: [PATCH 13/19] Clarification and typo fixes in comments related to name resolution. No changes to code. FossilOrigin-Name: f30abdf9d814d6c75bf1c803054737c737ad636f --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/resolve.c | 4 ++-- src/sqliteInt.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 5e2d3872f1..33f9db7681 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfew\smore\sminor\scomment\stypos.\s\sNo\schanges\sto\scode. -D 2013-08-14T00:20:23.461 +C Clarification\sand\stypo\sfixes\sin\scomments\srelated\sto\sname\sresolution.\nNo\schanges\sto\scode. +D 2013-08-15T14:27:42.072 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,14 +214,14 @@ F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c 17e670996729ac41aadf6a31f57b4e6f29b3d819 +F src/resolve.c 94a08f37c04352bbdd4a91b335e1a4feb256a3c7 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h def0e436c0d4ca5084305ca6ae898020fbafaae4 +F src/sqliteInt.h ac5de15640d7a5d6ea46724fe3e0ffd39af0ed12 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ac336959490083ffeaaf25aaec97ecb59a2f4536 -R b65660836257e0b7350de3a479496a6b -U mistachkin -Z 2adbd114c976ac90cd58966c1c244f68 +P 9e999081a59b161a0a1f968fbc01a1db9ea43b93 +R 24134e38ea075ceae9b6222f6f5f7529 +U drh +Z 9cfa8ebfbef3728e717dd86578dea4f4 diff --git a/manifest.uuid b/manifest.uuid index c5b110f948..948eae37cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e999081a59b161a0a1f968fbc01a1db9ea43b93 \ No newline at end of file +f30abdf9d814d6c75bf1c803054737c737ad636f \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index a194a26553..d5517003b6 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1009,7 +1009,7 @@ int sqlite3ResolveOrderGroupBy( ** If the order-by term is an integer I between 1 and N (where N is the ** number of columns in the result set of the SELECT) then the expression ** in the resolution is a copy of the I-th result-set expression. If -** the order-by term is an identify that corresponds to the AS-name of +** the order-by term is an identifier that corresponds to the AS-name of ** a result-set expression, then the term resolves to a copy of the ** result-set expression. Otherwise, the expression is resolved in ** the usual way - using sqlite3ResolveExprNames(). @@ -1187,7 +1187,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ return WRC_Abort; } - /* Add the expression list to the name-context before parsing the + /* Add the output column list to the name-context before parsing the ** other expressions in the SELECT statement. This is so that ** expressions in the WHERE clause (etc.) can refer to expressions by ** aliases in the result set. diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 67f7df2474..a0ba82ab8c 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2006,7 +2006,7 @@ struct SrcList { struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ - ExprList *pEList; /* Optional list of named expressions */ + ExprList *pEList; /* Optional list of result-set columns */ AggInfo *pAggInfo; /* Information about aggregates at this level */ NameContext *pNext; /* Next outer name context. NULL for outermost */ int nRef; /* Number of names resolved by this context */ From e35463b312a5ec35ae5546d155a75380e0d03e64 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Aug 2013 20:24:27 +0000 Subject: [PATCH 14/19] Bare identifiers in ORDER BY clauses bind more tightly to output column name, but identifiers in expressions bind more tightly to input column names. This is a compromise between SQL92 and SQL99 behavior and is what PostgreSQL and MS-SQL do. Ticket [f617ea3125e9c]. FossilOrigin-Name: c78b357c00a35ed48ce2ffbc041de8d22570d1e2 --- manifest | 20 ++++---- manifest.uuid | 2 +- src/resolve.c | 24 +++++---- src/sqliteInt.h | 4 +- test/resolver01.test | 117 ++++++++++++++++++++++++++++++++++++++++++- test/tkt2822.test | 5 +- 6 files changed, 143 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 1a10d6e3a3..f200c5dbea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sit\seasy\sto\sattach\sa\sdebugger\sthe\stest\sfixture\sprocess\sprior\sto\sany\stests\sbeing\srun. -D 2013-08-15T20:05:03.202 +C Bare\sidentifiers\sin\sORDER\sBY\sclauses\sbind\smore\stightly\sto\soutput\scolumn\sname,\nbut\sidentifiers\sin\sexpressions\sbind\smore\stightly\sto\sinput\scolumn\snames.\nThis\sis\sa\scompromise\sbetween\sSQL92\sand\sSQL99\sbehavior\sand\sis\swhat\nPostgreSQL\sand\sMS-SQL\sdo.\s\sTicket\s[f617ea3125e9c]. +D 2013-08-15T20:24:27.463 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,14 +214,14 @@ F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c 94a08f37c04352bbdd4a91b335e1a4feb256a3c7 +F src/resolve.c 2a760f369ddbcd951f176556c8ec05be04cdd0da F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h ac5de15640d7a5d6ea46724fe3e0ffd39af0ed12 +F src/sqliteInt.h b2a4e9a85e4bb49c1537fe7fc6532cd7ebe82aa0 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -733,7 +733,7 @@ F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce -F test/resolver01.test d1b487fc567bdb70b5dd09ccaaa877ddc61a233e +F test/resolver01.test a98ed8a2e9f78600155d783389ad4e6537010285 F test/rollback.test a1b4784b864331eae8b2a98c189efa2a8b11ff07 F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 F test/rowid.test f777404492adb0e00868fd706a3721328fd3af48 @@ -906,7 +906,7 @@ F test/tkt2686.test 6ee01c9b9e9c48f6d3a1fdd553b1cc4258f903d6 F test/tkt2767.test 569000d842678f9cf2db7e0d1b27cbc9011381b0 F test/tkt2817.test f31839e01f4243cff7399ef654d3af3558cb8d8d F test/tkt2820.test 39940276b3436d125deb7d8ebeee053e4cf13213 -F test/tkt2822.test c3589494fba643e039bcf0bfde7554ff6028406d +F test/tkt2822.test f391776423a7c0d0949edfce375708bfb0f3141e F test/tkt2832.test a9b0b74a02dca166a04d9e37739c414b10929caa F test/tkt2854.test e432965db29e27e16f539b2ba7f502eb2ccc49af F test/tkt2920.test a8737380e4ae6424e00c0273dc12775704efbebf @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f30abdf9d814d6c75bf1c803054737c737ad636f c23acba11bfefc019b5945cfb345f9afcf4b6242 -R fb4db235176e52d42891fba292ddbfa5 -U mistachkin -Z 4d072d8f2cb243e6b9c13cb11a27b554 +P 53cd9ebfaf401c7932bf591e134a527c9962b88e +R b873391074dfe27843eed5ca71b0596f +U drh +Z 52475f320db5f901cc1dc06cbb7fef10 diff --git a/manifest.uuid b/manifest.uuid index 836758fb58..1f70b21510 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -53cd9ebfaf401c7932bf591e134a527c9962b88e \ No newline at end of file +c78b357c00a35ed48ce2ffbc041de8d22570d1e2 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index d5517003b6..b41a7adda4 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -55,7 +55,7 @@ static void incrAggFunctionDepth(Expr *pExpr, int N){ ** column reference is so that the column reference will be recognized as ** usable by indices within the WHERE clause processing logic. ** -** Hack: The TK_AS operator is inhibited if zType[0]=='G'. This means +** The TK_AS operator is inhibited if zType[0]=='G'. This means ** that in a GROUP BY clause, the expression is evaluated twice. Hence: ** ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x @@ -65,8 +65,9 @@ static void incrAggFunctionDepth(Expr *pExpr, int N){ ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 ** ** The result of random()%5 in the GROUP BY clause is probably different -** from the result in the result-set. We might fix this someday. Or -** then again, we might not... +** from the result in the result-set. On the other hand Standard SQL does +** not allow the GROUP BY clause to contain references to result-set columns. +** So this should never come up in well-formed queries. ** ** If the reference is followed by a COLLATE operator, then make sure ** the COLLATE operator is preserved. For example: @@ -396,10 +397,16 @@ static int lookupName( ** forms the result set entry ("a+b" in the example) and return immediately. ** Note that the expression in the result set should have already been ** resolved by the time the WHERE clause is resolved. + ** + ** The ability to use an output result-set column in the WHERE, GROUP BY, + ** or HAVING clauses, or as part of a larger expression in the ORDRE BY + ** clause is not standard SQL. This is a (goofy) SQLite extension, that + ** is supported for backwards compatibility only. TO DO: Issue a warning + ** on sqlite3_log() whenever the capability is used. */ if( (pEList = pNC->pEList)!=0 && zTab==0 - && ((pNC->ncFlags & NC_AsMaybe)==0 || cnt==0) + && cnt==0 ){ for(j=0; jnExpr; j++){ char *zAs = pEList->a[j].zName; @@ -961,7 +968,7 @@ static int resolveCompoundOrderBy( /* ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of ** the SELECT statement pSelect. If any term is reference to a -** result set expression (as determined by the ExprList.a.iCol field) +** result set expression (as determined by the ExprList.a.iOrderByCol field) ** then convert that term into a copy of the corresponding result set ** column. ** @@ -1035,7 +1042,8 @@ static int resolveOrderGroupBy( pParse = pNC->pParse; for(i=0, pItem=pOrderBy->a; inExpr; i++, pItem++){ Expr *pE = pItem->pExpr; - iCol = resolveAsName(pParse, pSelect->pEList, pE); + Expr *pE2 = sqlite3ExprSkipCollate(pE); + iCol = resolveAsName(pParse, pSelect->pEList, pE2); if( iCol>0 ){ /* If an AS-name match is found, mark this ORDER BY column as being ** a copy of the iCol-th result-set column. The subsequent call to @@ -1044,7 +1052,7 @@ static int resolveOrderGroupBy( pItem->iOrderByCol = (u16)iCol; continue; } - if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){ + if( sqlite3ExprIsInteger(pE2, &iCol) ){ /* The ORDER BY term is an integer constant. Again, set the column ** number so that sqlite3ResolveOrderGroupBy() will convert the ** order-by term to a copy of the result-set expression */ @@ -1196,10 +1204,8 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** re-evaluated for each reference to it. */ sNC.pEList = p->pEList; - sNC.ncFlags |= NC_AsMaybe; if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort; - sNC.ncFlags &= ~NC_AsMaybe; /* The ORDER BY and GROUP BY clauses may not refer to terms in ** outer queries diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a0ba82ab8c..78aa0f8fca 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2021,9 +2021,7 @@ struct NameContext { #define NC_HasAgg 0x02 /* One or more aggregate functions seen */ #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */ #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */ -#define NC_AsMaybe 0x10 /* Resolve to AS terms of the result set only - ** if no other resolution is available */ -#define NC_PartIdx 0x20 /* True if resolving a partial index WHERE */ +#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */ /* ** An instance of the following structure contains all information diff --git a/test/resolver01.test b/test/resolver01.test index 3ca6acec47..3bad269151 100644 --- a/test/resolver01.test +++ b/test/resolver01.test @@ -13,10 +13,18 @@ # figures out what identifiers in the SQL statement refer to) that # were fixed by ticket [2500cdb9be] # +# See also tickets [1c69be2daf] and [f617ea3125] from 2013-08-14. +# set testdir [file dirname $argv0] source $testdir/tester.tcl +# "ORDER BY y" binds to the output result-set column named "y" +# if available. If no output column is named "y", then try to +# bind against an input column named "y". +# +# This is classical SQL92 behavior. +# do_test resolver01-1.1 { catchsql { CREATE TABLE t1(x, y); INSERT INTO t1 VALUES(11,22); @@ -25,15 +33,120 @@ do_test resolver01-1.1 { } } {0 1} do_test resolver01-1.2 { + catchsql { + SELECT 1 AS yy FROM t1, t2 ORDER BY y; + } +} {1 {ambiguous column name: y}} +do_test resolver01-1.3 { + catchsql { + CREATE TABLE t3(x,y); INSERT INTO t3 VALUES(11,44),(33,22); + SELECT x AS y FROM t3 ORDER BY y; + } +} {0 {11 33}} +do_test resolver01-1.4 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY y; + } +} {0 {33 11}} + +# SQLite allows the WHERE clause to reference output columns if there is +# no other way to resolve the name. +# +do_test resolver01-1.5 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY yy; + } +} {0 {11 33}} +do_test resolver01-1.6 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY 1; + } +} {0 {11 33}} + +# The "ORDER BY y COLLATE nocase" form works the same as "ORDER BY y". +# The "y" binds more tightly to output columns than to input columns. +# +# This is for compatibility with SQL92 and with historical SQLite behavior. +# Note that PostgreSQL considers "y COLLATE nocase" to be an expression +# and thus PostgreSQL treats this case as if it where the 3.x case below. +# +do_test resolver01-2.1 { catchsql { SELECT 2 AS y FROM t1, t2 ORDER BY y COLLATE nocase; } } {0 2} -do_test resolver01-1.3 { +do_test resolver01-2.2 { + catchsql { + SELECT 2 AS yy FROM t1, t2 ORDER BY y COLLATE nocase; + } +} {1 {ambiguous column name: y}} +do_test resolver01-2.3 { + catchsql { + SELECT x AS y FROM t3 ORDER BY y COLLATE nocase; + } +} {0 {11 33}} +do_test resolver01-2.4 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY y COLLATE nocase; + } +} {0 {33 11}} +do_test resolver01-2.5 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY yy COLLATE nocase; + } +} {0 {11 33}} +do_test resolver01-2.6 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY 1 COLLATE nocase; + } +} {0 {11 33}} + +# But if the form is "ORDER BY expr" then bind more tightly to the +# the input column names and only use the output column names if no +# input column name matches. +# +# This is SQL99 behavior, as implemented by PostgreSQL and MS-SQL. +# Note that Oracle works differently. +# +do_test resolver01-3.1 { catchsql { SELECT 3 AS y FROM t1, t2 ORDER BY +y; } -} {0 3} +} {1 {ambiguous column name: y}} +do_test resolver01-3.2 { + catchsql { + SELECT 2 AS yy FROM t1, t2 ORDER BY +y; + } +} {1 {ambiguous column name: y}} +do_test resolver01-3.3 { + catchsql { + SELECT x AS y FROM t3 ORDER BY +y; + } +} {0 {33 11}} +do_test resolver01-3.4 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY +y; + } +} {0 {33 11}} +do_test resolver01-3.5 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY +yy + } +} {0 {11 33}} +# This is the test case given in ticket [f617ea3125e9] (with table name +# changed from "t1" to "t4". The behavior of (1) and (3) match with +# PostgreSQL, but we intentionally break with PostgreSQL to provide +# SQL92 behavior for case (2). +# +do_execsql_test resolver01-4.1 { + CREATE TABLE t4(m CHAR(2)); + INSERT INTO t4 VALUES('az'); + INSERT INTO t4 VALUES('by'); + INSERT INTO t4 VALUES('cx'); + SELECT '1', substr(m,2) AS m FROM t4 ORDER BY m; + SELECT '2', substr(m,2) AS m FROM t4 ORDER BY m COLLATE binary; + SELECT '3', substr(m,2) AS m FROM t4 ORDER BY lower(m); +} {1 x 1 y 1 z 2 x 2 y 2 z 3 z 3 y 3 x} finish_test diff --git a/test/tkt2822.test b/test/tkt2822.test index d3512d3038..d0b16338c6 100644 --- a/test/tkt2822.test +++ b/test/tkt2822.test @@ -208,15 +208,12 @@ do_test tkt2822-5.4 { # In "ORDER BY +b" the term is now an expression rather than # a label. It therefore matches by rule (3) instead of rule (2). -# -# 2013-04-13: This is busted. Changed to conform to PostgreSQL and -# MySQL and Oracle behavior. # do_test tkt2822-5.5 { execsql { SELECT a AS b FROM t3 ORDER BY +b; } -} {1 9} +} {9 1} # Tests for rule 2 in compound queries # From 0af16ab2c2d5eec0eb01f512af96ef01909a095c Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Aug 2013 22:40:21 +0000 Subject: [PATCH 15/19] Make sure that GROUP BY terms select input column names in preference to output column names, in compliance with the SQL standard. Ticket [1c69be2dafc28]. FossilOrigin-Name: f2d175f975cd0be63425424ec322a98fb650019e --- manifest | 14 +++++------ manifest.uuid | 2 +- src/resolve.c | 18 +++++++------- test/resolver01.test | 56 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index f200c5dbea..87a62738cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bare\sidentifiers\sin\sORDER\sBY\sclauses\sbind\smore\stightly\sto\soutput\scolumn\sname,\nbut\sidentifiers\sin\sexpressions\sbind\smore\stightly\sto\sinput\scolumn\snames.\nThis\sis\sa\scompromise\sbetween\sSQL92\sand\sSQL99\sbehavior\sand\sis\swhat\nPostgreSQL\sand\sMS-SQL\sdo.\s\sTicket\s[f617ea3125e9c]. -D 2013-08-15T20:24:27.463 +C Make\ssure\sthat\sGROUP\sBY\sterms\sselect\sinput\scolumn\snames\sin\spreference\sto\noutput\scolumn\snames,\sin\scompliance\swith\sthe\sSQL\sstandard.\nTicket\s[1c69be2dafc28]. +D 2013-08-15T22:40:21.803 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c 2a760f369ddbcd951f176556c8ec05be04cdd0da +F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 @@ -733,7 +733,7 @@ F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce -F test/resolver01.test a98ed8a2e9f78600155d783389ad4e6537010285 +F test/resolver01.test 33abf37ff8335e6bf98f2b45a0af3e06996ccd9a F test/rollback.test a1b4784b864331eae8b2a98c189efa2a8b11ff07 F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 F test/rowid.test f777404492adb0e00868fd706a3721328fd3af48 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 53cd9ebfaf401c7932bf591e134a527c9962b88e -R b873391074dfe27843eed5ca71b0596f +P c78b357c00a35ed48ce2ffbc041de8d22570d1e2 +R 0cad26d57aaadc86e4d0689961c53035 U drh -Z 52475f320db5f901cc1dc06cbb7fef10 +Z 9ac8068bb659c66e2e7c0f0532626e1f diff --git a/manifest.uuid b/manifest.uuid index 1f70b21510..cb7ffe8748 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c78b357c00a35ed48ce2ffbc041de8d22570d1e2 \ No newline at end of file +f2d175f975cd0be63425424ec322a98fb650019e \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index b41a7adda4..43a3870e23 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1043,14 +1043,16 @@ static int resolveOrderGroupBy( for(i=0, pItem=pOrderBy->a; inExpr; i++, pItem++){ Expr *pE = pItem->pExpr; Expr *pE2 = sqlite3ExprSkipCollate(pE); - iCol = resolveAsName(pParse, pSelect->pEList, pE2); - if( iCol>0 ){ - /* If an AS-name match is found, mark this ORDER BY column as being - ** a copy of the iCol-th result-set column. The subsequent call to - ** sqlite3ResolveOrderGroupBy() will convert the expression to a - ** copy of the iCol-th result-set expression. */ - pItem->iOrderByCol = (u16)iCol; - continue; + if( zType[0]!='G' ){ + iCol = resolveAsName(pParse, pSelect->pEList, pE2); + if( iCol>0 ){ + /* If an AS-name match is found, mark this ORDER BY column as being + ** a copy of the iCol-th result-set column. The subsequent call to + ** sqlite3ResolveOrderGroupBy() will convert the expression to a + ** copy of the iCol-th result-set expression. */ + pItem->iOrderByCol = (u16)iCol; + continue; + } } if( sqlite3ExprIsInteger(pE2, &iCol) ){ /* The ORDER BY term is an integer constant. Again, set the column diff --git a/test/resolver01.test b/test/resolver01.test index 3bad269151..7d95a2132a 100644 --- a/test/resolver01.test +++ b/test/resolver01.test @@ -149,4 +149,60 @@ do_execsql_test resolver01-4.1 { SELECT '3', substr(m,2) AS m FROM t4 ORDER BY lower(m); } {1 x 1 y 1 z 2 x 2 y 2 z 3 z 3 y 3 x} +########################################################################## +# Test cases for ticket [1c69be2dafc28]: Make sure the GROUP BY binds +# more tightly to the input tables in all cases. +# +# This first case case has been wrong in SQLite for time out of mind. +# For SQLite version 3.7.17 the answer was two rows, which is wrong. +# +do_execsql_test resolver01-5.1 { + CREATE TABLE t5(m CHAR(2)); + INSERT INTO t5 VALUES('ax'); + INSERT INTO t5 VALUES('bx'); + INSERT INTO t5 VALUES('cy'); + SELECT count(*), substr(m,2,1) AS m FROM t5 GROUP BY m ORDER BY 1, 2; +} {1 x 1 x 1 y} + +# This case is unambiguous and has always been correct. +# +do_execsql_test resolver01-5.2 { + SELECT count(*), substr(m,2,1) AS mx FROM t5 GROUP BY m ORDER BY 1, 2; +} {1 x 1 x 1 y} + +# This case is not allowed in standard SQL, but SQLite allows and does +# the sensible thing. +# +do_execsql_test resolver01-5.3 { + SELECT count(*), substr(m,2,1) AS mx FROM t5 GROUP BY mx ORDER BY 1, 2; +} {1 y 2 x} +do_execsql_test resolver01-5.4 { + SELECT count(*), substr(m,2,1) AS mx FROM t5 + GROUP BY substr(m,2,1) ORDER BY 1, 2; +} {1 y 2 x} + +# These test case weere provided in the 2013-08-14 email from Rob Golsteijn +# that originally reported the problem of ticket [1c69be2dafc28]. +# +do_execsql_test resolver01-6.1 { + CREATE TABLE t61(name); + SELECT min(name) FROM t61 GROUP BY lower(name); +} {} +do_execsql_test resolver01-6.2 { + SELECT min(name) AS name FROM t61 GROUP BY lower(name); +} {} +do_execsql_test resolver01-6.3 { + CREATE TABLE t63(name); + INSERT INTO t63 VALUES (NULL); + INSERT INTO t63 VALUES ('abc'); + SELECT count(), + NULLIF(name,'abc') AS name + FROM t63 + GROUP BY lower(name); +} {1 {} 1 {}} + + + + + finish_test From 40c3941cfa6af853a6ea9b3bf859607f11273d15 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 16 Aug 2013 20:42:20 +0000 Subject: [PATCH 16/19] Add the cache_spill pragma. FossilOrigin-Name: cdb181c04fa99c6c29f23eb68ccb5475e7f6bf9c --- manifest | 27 +++++++++------- manifest.uuid | 2 +- src/btree.c | 9 ++---- src/btree.h | 2 +- src/main.c | 2 +- src/pager.c | 85 ++++++++++++++++++++++++++++++------------------- src/pager.h | 14 +++++++- src/pragma.c | 12 +++++-- src/sqliteInt.h | 47 ++++++++++++++------------- 9 files changed, 120 insertions(+), 80 deletions(-) diff --git a/manifest b/manifest index 87a62738cb..fcb9b9388e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthat\sGROUP\sBY\sterms\sselect\sinput\scolumn\snames\sin\spreference\sto\noutput\scolumn\snames,\sin\scompliance\swith\sthe\sSQL\sstandard.\nTicket\s[1c69be2dafc28]. -D 2013-08-15T22:40:21.803 +C Add\sthe\scache_spill\spragma. +D 2013-08-16T20:42:20.550 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,8 +163,8 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 3f7bbfd72efb1cbf6a49515c376a031767ec930a -F src/btree.h 6fa8a3ff2483d0bb64a9f0105a8cedeac9e00cca +F src/btree.c 9b985e4f334a1b3df5733e2ac2de1de9bdd41be7 +F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2 F src/build.c cee4724668ebc09bb482c1be30f96e0ae2474f9b F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc @@ -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 4e4cd5c2ee09db496c0dde79b507bba6b8bcbdcb +F src/main.c dc02c7c118d58049e0cccc6c9c47c0a4d3e2bcda F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -204,13 +204,13 @@ F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 9eafa5458cf2ff684ddccff82c9bb113c7cad847 F src/os_win.c 1d84f2079d9b91f91a4b5dbfa5e08f1b1a0ed0ff -F src/pager.c 5d2f7475260a8588f9c441bb309d2b7eaa7ded3b -F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1 +F src/pager.c 7c999137cb940133f7fc7609ccfa66f17eec4ab4 +F src/pager.h 66e42d6942a445d4c25651733ab2079dbebc7ca9 F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c d23d07716de96c7c0c2503ec5051a4384c3fb938 -F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b +F src/pragma.c 3fd0f90f7106fdfe9daf59cb1dc5ad6f2bcec878 F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -221,7 +221,7 @@ F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h b2a4e9a85e4bb49c1537fe7fc6532cd7ebe82aa0 +F src/sqliteInt.h eae58298bc7c9a491ad2fc6c600f534b74be8a11 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1105,7 +1105,10 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P c78b357c00a35ed48ce2ffbc041de8d22570d1e2 -R 0cad26d57aaadc86e4d0689961c53035 +P f2d175f975cd0be63425424ec322a98fb650019e +R 51784bade3c91fc13297b6a9e11bfbe0 +T *branch * cache_spill +T *sym-cache_spill * +T -sym-trunk * U drh -Z 9ac8068bb659c66e2e7c0f0532626e1f +Z 6759e9990b6aac3480039cd24c99d255 diff --git a/manifest.uuid b/manifest.uuid index cb7ffe8748..b6f4ea3fd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f2d175f975cd0be63425424ec322a98fb650019e \ No newline at end of file +cdb181c04fa99c6c29f23eb68ccb5475e7f6bf9c \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 9b78378791..ac0a8cf2c0 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2165,17 +2165,14 @@ int sqlite3BtreeSetMmapLimit(Btree *p, sqlite3_int64 szMmap){ ** probability of damage to near zero but with a write performance reduction. */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS -int sqlite3BtreeSetSafetyLevel( +int sqlite3BtreeSetPagerFlags( Btree *p, /* The btree to set the safety level on */ - int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */ - int fullSync, /* PRAGMA fullfsync. */ - int ckptFullSync /* PRAGMA checkpoint_fullfync */ + unsigned pgFlags /* Various PAGER_* flags */ ){ BtShared *pBt = p->pBt; assert( sqlite3_mutex_held(p->db->mutex) ); - assert( level>=1 && level<=3 ); sqlite3BtreeEnter(p); - sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync, ckptFullSync); + sqlite3PagerSetFlags(pBt->pPager, pgFlags); sqlite3BtreeLeave(p); return SQLITE_OK; } diff --git a/src/btree.h b/src/btree.h index ace0f8cd21..33b3ed1f08 100644 --- a/src/btree.h +++ b/src/btree.h @@ -64,7 +64,7 @@ int sqlite3BtreeOpen( int sqlite3BtreeClose(Btree*); int sqlite3BtreeSetCacheSize(Btree*,int); int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); -int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int); +int sqlite3BtreeSetPagerFlags(Btree*,unsigned); int sqlite3BtreeSyncDisabled(Btree*); int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix); int sqlite3BtreeGetPageSize(Btree*); diff --git a/src/main.c b/src/main.c index 6932bf7b9d..7e817e5953 100644 --- a/src/main.c +++ b/src/main.c @@ -2461,7 +2461,7 @@ static int openDatabase( db->nextAutovac = -1; db->szMmap = sqlite3GlobalConfig.szMmap; db->nextPagesize = 0; - db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger + db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX | SQLITE_AutoIndex #endif diff --git a/src/pager.c b/src/pager.c index b208228968..77a7d86a0d 100644 --- a/src/pager.c +++ b/src/pager.c @@ -453,6 +453,13 @@ struct PagerSavepoint { #endif }; +/* +** Bits of the Pager.doNotSpill flag. See further description below. +*/ +#define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */ +#define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */ +#define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */ + /* ** A open page cache is an instance of struct Pager. A description of ** some of the more important member variables follows: @@ -519,19 +526,21 @@ struct PagerSavepoint { ** journal file from being successfully finalized, the setMaster flag ** is cleared anyway (and the pager will move to ERROR state). ** -** doNotSpill, doNotSyncSpill +** doNotSpill ** -** These two boolean variables control the behavior of cache-spills -** (calls made by the pcache module to the pagerStress() routine to -** write cached data to the file-system in order to free up memory). +** This variables control the behavior of cache-spills (calls made by +** the pcache module to the pagerStress() routine to write cached data +** to the file-system in order to free up memory). ** -** When doNotSpill is non-zero, writing to the database from pagerStress() -** is disabled altogether. This is done in a very obscure case that +** When bits SPILLFLAG_OFF or SPILLFLAG_ROLLBACK of doNotSpill are set, +** writing to the database from pagerStress() is disabled altogether. +** The SPILLFLAG_ROLLBACK case is done in a very obscure case that ** comes up during savepoint rollback that requires the pcache module ** to allocate a new page to prevent the journal file from being written -** while it is being traversed by code in pager_playback(). +** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF +** case is a user preference. ** -** If doNotSyncSpill is non-zero, writing to the database from pagerStress() +** If the SPILLFLAG_NOSYNC bit is set, writing to the database from pagerStress() ** is permitted, but syncing the journal file is not. This flag is set ** by sqlite3PagerWrite() when the file-system sector-size is larger than ** the database page-size in order to prevent a journal sync from happening @@ -635,7 +644,6 @@ struct Pager { u8 changeCountDone; /* Set after incrementing the change-counter */ u8 setMaster; /* True if a m-j name has been written to jrnl */ u8 doNotSpill; /* Do not spill the cache when non-zero */ - u8 doNotSyncSpill; /* Do not do a spill that requires jrnl sync */ u8 subjInMemory; /* True to use in-memory sub-journals */ Pgno dbSize; /* Number of pages in the database */ Pgno dbOrigSize; /* dbSize before the current transaction */ @@ -2295,11 +2303,11 @@ static int pager_playback_one_page( ** requiring a journal-sync before it is written. */ assert( isSavepnt ); - assert( pPager->doNotSpill==0 ); - pPager->doNotSpill++; + assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 ); + pPager->doNotSpill |= SPILLFLAG_ROLLBACK; rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1); - assert( pPager->doNotSpill==1 ); - pPager->doNotSpill--; + assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 ); + pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK; if( rc!=SQLITE_OK ) return rc; pPg->flags &= ~PGHDR_NEED_READ; sqlite3PcacheMakeDirty(pPg); @@ -3404,9 +3412,12 @@ void sqlite3PagerShrink(Pager *pPager){ } /* -** Adjust the robustness of the database to damage due to OS crashes -** or power failures by changing the number of syncs()s when writing -** the rollback journal. There are three levels: +** Adjust settings of the pager to those specified in the pgFlags parameter. +** +** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness +** of the database to damage due to OS crashes or power failures by +** changing the number of syncs()s when writing the journals. +** There are three levels: ** ** OFF sqlite3OsSync() is never called. This is the default ** for temporary and transient files. @@ -3447,22 +3458,21 @@ void sqlite3PagerShrink(Pager *pPager){ ** and FULL=3. */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS -void sqlite3PagerSetSafetyLevel( +void sqlite3PagerSetFlags( Pager *pPager, /* The pager to set safety level for */ - int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */ - int bFullFsync, /* PRAGMA fullfsync */ - int bCkptFullFsync /* PRAGMA checkpoint_fullfsync */ + unsigned pgFlags /* Various flags */ ){ + unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK; assert( level>=1 && level<=3 ); pPager->noSync = (level==1 || pPager->tempFile) ?1:0; pPager->fullSync = (level==3 && !pPager->tempFile) ?1:0; if( pPager->noSync ){ pPager->syncFlags = 0; pPager->ckptSyncFlags = 0; - }else if( bFullFsync ){ + }else if( pgFlags & PAGER_FULLFSYNC ){ pPager->syncFlags = SQLITE_SYNC_FULL; pPager->ckptSyncFlags = SQLITE_SYNC_FULL; - }else if( bCkptFullFsync ){ + }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){ pPager->syncFlags = SQLITE_SYNC_NORMAL; pPager->ckptSyncFlags = SQLITE_SYNC_FULL; }else{ @@ -3473,6 +3483,11 @@ void sqlite3PagerSetSafetyLevel( if( pPager->fullSync ){ pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS; } + if( pgFlags & PAGER_CACHESPILL ){ + pPager->doNotSpill &= ~SPILLFLAG_OFF; + }else{ + pPager->doNotSpill |= SPILLFLAG_OFF; + } } #endif @@ -4373,13 +4388,14 @@ static int pagerStress(void *p, PgHdr *pPg){ assert( pPg->pPager==pPager ); assert( pPg->flags&PGHDR_DIRTY ); - /* The doNotSyncSpill flag is set during times when doing a sync of + /* The doNotSpill NOSYNC bit is set during times when doing a sync of ** journal (and adding a new header) is not allowed. This occurs ** during calls to sqlite3PagerWrite() while trying to journal multiple ** pages belonging to the same sector. ** - ** The doNotSpill flag inhibits all cache spilling regardless of whether - ** or not a sync is required. This is set during a rollback. + ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling + ** regardless of whether or not a sync is required. This is set during + ** a rollback or by user request, respectively. ** ** Spilling is also prohibited when in an error state since that could ** lead to database corruption. In the current implementaton it @@ -4389,8 +4405,13 @@ static int pagerStress(void *p, PgHdr *pPg){ ** test for the error state as a safeguard against future changes. */ if( NEVER(pPager->errCode) ) return SQLITE_OK; - if( pPager->doNotSpill ) return SQLITE_OK; - if( pPager->doNotSyncSpill && (pPg->flags & PGHDR_NEED_SYNC)!=0 ){ + testcase( pPager->doNotSpill & SPILLFLAG_ROLLBACK ); + testcase( pPager->doNotSpill & SPILLFLAG_OFF ); + testcase( pPager->doNotSpill & SPILLFLAG_NOSYNC ); + if( pPager->doNotSpill + && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0 + || (pPg->flags & PGHDR_NEED_SYNC)!=0) + ){ return SQLITE_OK; } @@ -5744,13 +5765,13 @@ int sqlite3PagerWrite(DbPage *pDbPage){ int ii; /* Loop counter */ int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ - /* Set the doNotSyncSpill flag to 1. This is because we cannot allow + /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow ** a journal header to be written between the pages journaled by ** this function. */ assert( !MEMDB ); - assert( pPager->doNotSyncSpill==0 ); - pPager->doNotSyncSpill++; + assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 ); + pPager->doNotSpill |= SPILLFLAG_NOSYNC; /* This trick assumes that both the page-size and sector-size are ** an integer power of 2. It sets variable pg1 to the identifier @@ -5809,8 +5830,8 @@ int sqlite3PagerWrite(DbPage *pDbPage){ } } - assert( pPager->doNotSyncSpill==1 ); - pPager->doNotSyncSpill--; + assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 ); + pPager->doNotSpill &= ~SPILLFLAG_NOSYNC; }else{ rc = pager_write(pDbPage); } diff --git a/src/pager.h b/src/pager.h index 6f659136e2..5528be14e7 100644 --- a/src/pager.h +++ b/src/pager.h @@ -84,6 +84,18 @@ typedef struct PgHdr DbPage; #define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */ #define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */ +/* +** Flags for sqlite3PagerSetFlags() +*/ +#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */ +#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */ +#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */ +#define PAGER_SYNCHRONOUS_MASK 0x03 /* Mask for three values above */ +#define PAGER_FULLFSYNC 0x04 /* PRAGMA fullfsync=ON */ +#define PAGER_CKPT_FULLFSYNC 0x08 /* PRAGMA checkpoint_fullfsync=ON */ +#define PAGER_CACHESPILL 0x10 /* PRAGMA cache_spill=ON */ +#define PAGER_FLAGS_MASK 0x1c /* All above except SYNCHRONOUS */ + /* ** The remainder of this file contains the declarations of the functions ** that make up the Pager sub-system API. See source code comments for @@ -110,7 +122,7 @@ int sqlite3PagerMaxPageCount(Pager*, int); void sqlite3PagerSetCachesize(Pager*, int); void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); void sqlite3PagerShrink(Pager*); -void sqlite3PagerSetSafetyLevel(Pager*,int,int,int); +void sqlite3PagerSetFlags(Pager*,unsigned); int sqlite3PagerLockingMode(Pager *, int); int sqlite3PagerSetJournalMode(Pager *, int); int sqlite3PagerGetJournalMode(Pager*); diff --git a/src/pragma.c b/src/pragma.c index f152220d40..4a0c2b0184 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -176,6 +176,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ { "legacy_file_format", SQLITE_LegacyFileFmt }, { "fullfsync", SQLITE_FullFSync }, { "checkpoint_fullfsync", SQLITE_CkptFullFSync }, + { "cache_spill", SQLITE_CacheSpill }, { "reverse_unordered_selects", SQLITE_ReverseOrder }, { "query_only", SQLITE_QueryOnly }, #ifndef SQLITE_OMIT_AUTOMATIC_INDEX @@ -1811,9 +1812,14 @@ void sqlite3Pragma( */ #ifndef SQLITE_OMIT_PAGER_PRAGMAS if( db->autoCommit ){ - sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, - (db->flags&SQLITE_FullFSync)!=0, - (db->flags&SQLITE_CkptFullFSync)!=0); + assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level ); + assert( SQLITE_FullFSync==PAGER_FULLFSYNC ); + assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC ); + assert( SQLITE_CacheSpill==PAGER_CACHESPILL ); + assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL) + == PAGER_FLAGS_MASK ); + sqlite3BtreeSetPagerFlags(pDb->pBt, + pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) ); } #endif pragma_out: diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 78aa0f8fca..643040a7a2 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -972,32 +972,33 @@ struct sqlite3 { */ #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */ -#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ -#define SQLITE_ShortColNames 0x00000008 /* Show short columns names */ -#define SQLITE_CountRows 0x00000010 /* Count rows changed by INSERT, */ +#define SQLITE_FullFSync 0x00000004 /* Use full fsync on the backend */ +#define SQLITE_CkptFullFSync 0x00000008 /* Use full fsync for checkpoint */ +#define SQLITE_CacheSpill 0x00000010 /* OK to spill pager cache */ +#define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */ +#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ +#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ /* DELETE, or UPDATE and return */ /* the count using a callback. */ -#define SQLITE_NullCallback 0x00000020 /* Invoke the callback once if the */ +#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ /* result set is empty */ -#define SQLITE_SqlTrace 0x00000040 /* Debug print SQL as it executes */ -#define SQLITE_VdbeListing 0x00000080 /* Debug listings of VDBE programs */ -#define SQLITE_WriteSchema 0x00000100 /* OK to update SQLITE_MASTER */ -#define SQLITE_VdbeAddopTrace 0x00000200 /* Trace sqlite3VdbeAddOp() calls */ -#define SQLITE_IgnoreChecks 0x00000400 /* Do not enforce check constraints */ -#define SQLITE_ReadUncommitted 0x0000800 /* For shared-cache mode */ -#define SQLITE_LegacyFileFmt 0x00001000 /* Create new databases in format 1 */ -#define SQLITE_FullFSync 0x00002000 /* Use full fsync on the backend */ -#define SQLITE_CkptFullFSync 0x00004000 /* Use full fsync for checkpoint */ -#define SQLITE_RecoveryMode 0x00008000 /* Ignore schema errors */ -#define SQLITE_ReverseOrder 0x00010000 /* Reverse unordered SELECTs */ -#define SQLITE_RecTriggers 0x00020000 /* Enable recursive triggers */ -#define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */ -#define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */ -#define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */ -#define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */ -#define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */ -#define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */ -#define SQLITE_QueryOnly 0x01000000 /* Disable database changes */ +#define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */ +#define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */ +#define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */ +#define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */ +#define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */ +#define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */ +#define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */ +#define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */ +#define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */ +#define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */ +#define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */ +#define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */ +#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */ +#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ +#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ +#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ +#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ /* From d4b5c60eca0969b900ff4855904d396f32a4e8bb Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 17 Aug 2013 00:25:07 +0000 Subject: [PATCH 17/19] Test cases for the cache_spill pragma. FossilOrigin-Name: b85c9ec5e02c1b92faa8eeb9e56e02a576a43a96 --- manifest | 15 ++++++-------- manifest.uuid | 2 +- test/pragma2.test | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index fcb9b9388e..eb42de9940 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\scache_spill\spragma. -D 2013-08-16T20:42:20.550 +C Test\scases\sfor\sthe\scache_spill\spragma. +D 2013-08-17T00:25:07.417 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -716,7 +716,7 @@ F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test b98fc868d71eb5619d42a1702e9ab91718cbed54 F test/permutations.test 461ef4ea10db02cd421dfe5f988eac3e99b5cd9a F test/pragma.test 5e7de6c32a5d764f09437d2025f07e4917b9e178 -F test/pragma2.test 3a55f82b954242c642f8342b17dffc8b47472947 +F test/pragma2.test 5bc62f356ad2ea64ec2b931fd4189485c9518d58 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 F test/progress.test 552dc1edc37333a8d3098b8c26a2b7f06f5799d7 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1105,10 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f2d175f975cd0be63425424ec322a98fb650019e -R 51784bade3c91fc13297b6a9e11bfbe0 -T *branch * cache_spill -T *sym-cache_spill * -T -sym-trunk * +P cdb181c04fa99c6c29f23eb68ccb5475e7f6bf9c +R 4fb024de498b67ffd161eb735de52cba U drh -Z 6759e9990b6aac3480039cd24c99d255 +Z e0fbe7fca060e30f944a0c3b1b2c8e44 diff --git a/manifest.uuid b/manifest.uuid index b6f4ea3fd6..574163dd3d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cdb181c04fa99c6c29f23eb68ccb5475e7f6bf9c \ No newline at end of file +b85c9ec5e02c1b92faa8eeb9e56e02a576a43a96 \ No newline at end of file diff --git a/test/pragma2.test b/test/pragma2.test index 1111a984b4..ddda08108f 100644 --- a/test/pragma2.test +++ b/test/pragma2.test @@ -22,6 +22,7 @@ source $testdir/tester.tcl # pragma2-1.*: Test freelist_count pragma on the main database. # pragma2-2.*: Test freelist_count pragma on an attached database. # pragma2-3.*: Test trying to write to the freelist_count is a no-op. +# pragma2-4.*: Tests for PRAGMA cache_spill # ifcapable !pragma||!schema_pragmas { @@ -116,4 +117,53 @@ ifcapable attach { } {9 9} } +# Default setting of PRAGMA cache_spill is always ON +# +db close +delete_file test.db test.db-journal +sqlite3 db test.db +do_execsql_test pragma2-4.1 { + PRAGMA cache_spill; + PRAGMA main.cache_spill; + PRAGMA temp.cache_spill; +} {1 1 1} +do_execsql_test pragma2-4.2 { + PRAGMA cache_spill=OFF; + PRAGMA cache_spill; + PRAGMA main.cache_spill; + PRAGMA temp.cache_spill; +} {0 0 0} +do_execsql_test pragma2-4.3 { + PRAGMA page_size=1024; + PRAGMA cache_size=50; + BEGIN; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); + INSERT INTO t1 VALUES(1, randomblob(400), 1, randomblob(400)); + INSERT INTO t1 SELECT a+1, randomblob(400), a+1, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+2, randomblob(400), a+2, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+4, randomblob(400), a+4, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+8, randomblob(400), a+8, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+16, randomblob(400), a+16, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1; + COMMIT; + PRAGMA cache_spill=ON; +} {} +do_test pragma2-4.4 { + db eval { + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } +} {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill +do_test pragma2-4.5 { + db eval { + COMMIT; + PRAGMA cache_spill=OFF; + BEGIN; + UPDATE t1 SET c=c-1; + PRAGMA lock_status; + } +} {main reserved temp unknown} ;# No cache spill, so no exclusive lock + finish_test From d3605a4f205da7d50bccdec50ee6f8af3be56a42 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 17 Aug 2013 15:42:29 +0000 Subject: [PATCH 18/19] The fullfsync, checkpoint_fullfsync, and cache_spill pragmas apply to all files of a database connection, including those opened by future ATTACH statements. FossilOrigin-Name: d07c4331a28d44deca1ece8a34118f5b121b3ee2 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/attach.c | 1 + src/pragma.c | 48 +++++++++++++++++++++++++++++------------------ test/pragma2.test | 25 ++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index eb42de9940..2969bca66b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\scases\sfor\sthe\scache_spill\spragma. -D 2013-08-17T00:25:07.417 +C The\sfullfsync,\scheckpoint_fullfsync,\sand\scache_spill\spragmas\sapply\sto\sall\nfiles\sof\sa\sdatabase\sconnection,\sincluding\sthose\sopened\sby\sfuture\sATTACH\nstatements. +D 2013-08-17T15:42:29.969 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -158,7 +158,7 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad F src/alter.c f8db986c03eb0bfb221523fc9bbb9d0b70de3168 F src/analyze.c a33fcb0b3a399d966951feb9f32115106b3ecc2e -F src/attach.c 1816f5a9eea8d2010fc2b22b44f0f63eb3a62704 +F src/attach.c 5df737912f668fd160ec1d560755f85fdccbe5b7 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb @@ -210,7 +210,7 @@ F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c d23d07716de96c7c0c2503ec5051a4384c3fb938 -F src/pragma.c 3fd0f90f7106fdfe9daf59cb1dc5ad6f2bcec878 +F src/pragma.c 1d96ba749253b49bc229c6294f9c2e5ef3dca85c F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -716,7 +716,7 @@ F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/percentile.test b98fc868d71eb5619d42a1702e9ab91718cbed54 F test/permutations.test 461ef4ea10db02cd421dfe5f988eac3e99b5cd9a F test/pragma.test 5e7de6c32a5d764f09437d2025f07e4917b9e178 -F test/pragma2.test 5bc62f356ad2ea64ec2b931fd4189485c9518d58 +F test/pragma2.test 76e4a54cd4677966e4e75f8a7fe86ccbc250de2a F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 F test/progress.test 552dc1edc37333a8d3098b8c26a2b7f06f5799d7 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P cdb181c04fa99c6c29f23eb68ccb5475e7f6bf9c -R 4fb024de498b67ffd161eb735de52cba +P b85c9ec5e02c1b92faa8eeb9e56e02a576a43a96 +R 54aea7d44f4215ed05dbd991004edc4d U drh -Z e0fbe7fca060e30f944a0c3b1b2c8e44 +Z fd6003e382c3b0a90752bac67d35c865 diff --git a/manifest.uuid b/manifest.uuid index 574163dd3d..c6e71feff6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b85c9ec5e02c1b92faa8eeb9e56e02a576a43a96 \ No newline at end of file +d07c4331a28d44deca1ece8a34118f5b121b3ee2 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index b8e12199b5..87c15ae3d3 100644 --- a/src/attach.c +++ b/src/attach.c @@ -158,6 +158,7 @@ static void attachFunc( sqlite3PagerLockingMode(pPager, db->dfltLockMode); sqlite3BtreeSecureDelete(aNew->pBt, sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); + sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK)); } aNew->safety_level = 3; aNew->zName = sqlite3DbStrDup(db, zName); diff --git a/src/pragma.c b/src/pragma.c index 4a0c2b0184..f0f7b5b66b 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -158,6 +158,34 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); } + +/* +** Set the safety_level and pager flags for pager iDb. Or if iDb<0 +** set these values for all pagers. +*/ +#ifndef SQLITE_OMIT_PAGER_PRAGMAS +static void setAllPagerFlags(sqlite3 *db){ + if( db->autoCommit ){ + Db *pDb = db->aDb; + int n = db->nDb; + assert( SQLITE_FullFSync==PAGER_FULLFSYNC ); + assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC ); + assert( SQLITE_CacheSpill==PAGER_CACHESPILL ); + assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL) + == PAGER_FLAGS_MASK ); + assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level ); + while( (n--) > 0 ){ + if( pDb->pBt ){ + sqlite3BtreeSetPagerFlags(pDb->pBt, + pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) ); + } + pDb++; + } + } +} +#endif + + #ifndef SQLITE_OMIT_FLAG_PRAGMAS /* ** Check to see if zRight and zLeft refer to a pragma that queries @@ -967,6 +995,7 @@ void sqlite3Pragma( "Safety level may not be changed inside a transaction"); }else{ pDb->safety_level = getSafetyLevel(zRight,0,1)+1; + setAllPagerFlags(db); } } }else @@ -974,8 +1003,7 @@ void sqlite3Pragma( #ifndef SQLITE_OMIT_FLAG_PRAGMAS if( flagPragma(pParse, zLeft, zRight) ){ - /* The flagPragma() subroutine also generates any necessary code - ** there is nothing more to do here */ + setAllPagerFlags(db); }else #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ @@ -1806,22 +1834,6 @@ void sqlite3Pragma( {/* Empty ELSE clause */} - /* - ** Reset the safety level, in case the fullfsync flag or synchronous - ** setting changed. - */ -#ifndef SQLITE_OMIT_PAGER_PRAGMAS - if( db->autoCommit ){ - assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level ); - assert( SQLITE_FullFSync==PAGER_FULLFSYNC ); - assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC ); - assert( SQLITE_CacheSpill==PAGER_CACHESPILL ); - assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL) - == PAGER_FLAGS_MASK ); - sqlite3BtreeSetPagerFlags(pDb->pBt, - pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) ); - } -#endif pragma_out: sqlite3DbFree(db, zLeft); sqlite3DbFree(db, zRight); diff --git a/test/pragma2.test b/test/pragma2.test index ddda08108f..4a9fe8d944 100644 --- a/test/pragma2.test +++ b/test/pragma2.test @@ -121,6 +121,7 @@ ifcapable attach { # db close delete_file test.db test.db-journal +delete_file test2.db test2.db-journal sqlite3 db test.db do_execsql_test pragma2-4.1 { PRAGMA cache_spill; @@ -147,6 +148,10 @@ do_execsql_test pragma2-4.3 { INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1; INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1; COMMIT; + ATTACH 'test2.db' AS aux1; + CREATE TABLE aux1.t2(a INTEGER PRIMARY KEY, b, c, d); + INSERT INTO t2 SELECT * FROM t1; + DETACH aux1; PRAGMA cache_spill=ON; } {} do_test pragma2-4.4 { @@ -166,4 +171,24 @@ do_test pragma2-4.5 { } } {main reserved temp unknown} ;# No cache spill, so no exclusive lock +# Verify that newly attached databases inherit the cache_spill=OFF +# setting. +# +do_execsql_test pragma2-4.6 { + COMMIT; + ATTACH 'test2.db' AS aux1; + PRAGMA aux1.cache_size=50; + BEGIN; + UPDATE t2 SET c=c+1; + PRAGMA lock_status; +} {main unlocked temp unknown aux1 reserved} +do_execsql_test pragma2-4.7 { + COMMIT; + PRAGMA cache_spill=ON; -- Applies to all databases + BEGIN; + UPDATE t2 SET c=c-1; + PRAGMA lock_status; +} {main unlocked temp unknown aux1 exclusive} + + finish_test From 77dfd5bb447381a23791abb35569d39046281f59 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Aug 2013 11:15:48 +0000 Subject: [PATCH 19/19] Fixes for harmless compiler warnings. FossilOrigin-Name: a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/build.c | 2 +- src/shell.c | 1 + src/vdbe.c | 1 + src/where.c | 1 + 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 4473ce4ae6..9af4bbc0dc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\scache_spill\spragma.\s\sChange\sthe\sfullfsync\sand\scheckpoint_fullfsync\npragmas\sto\sapply\sto\sall\sattached\sdatabases. -D 2013-08-17T16:37:04.194 +C Fixes\sfor\sharmless\scompiler\swarnings. +D 2013-08-19T11:15:48.054 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,7 +166,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 F src/btree.c 9b985e4f334a1b3df5733e2ac2de1de9bdd41be7 F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2 -F src/build.c cee4724668ebc09bb482c1be30f96e0ae2474f9b +F src/build.c f99a715ff9290996b579d5e1ec8e94239dc9ae5e F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 4262c227bc91cecc61ae37ed3a40f08069cfa267 @@ -217,7 +217,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca -F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 +F src/shell.c 909f6c4a52c8e0265ce0048e2b3cbadda1bd6051 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -277,7 +277,7 @@ F src/update.c 7f3fe64d8f3b44c44a1eac293f0f85f87c355b7a F src/utf.c 8d819e2e5104a430fc2005f018db14347c95a38f F src/util.c f566b5138099a2df8533b190d0dcc74b7dfbe0c9 F src/vacuum.c d9c5759f4c5a438bb43c2086f72c5d2edabc36c8 -F src/vdbe.c 4914ae1d00045a5310aea9e0f7c9a8edd3d9f856 +F src/vdbe.c 0fbe7a904a1187dc6c8a2dbe2f594f0ce8d01401 F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4 F src/vdbeInt.h e9b7c6b165a31a4715c5aa97223d20d265515231 F src/vdbeapi.c 4d13580bd058b39623e8fcfc233b7df4b8191e8b @@ -290,7 +290,7 @@ F src/vtab.c 2e8b489db47e20ae36cd247932dc671c9ded0624 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c ea01a52eb31e54dda97b8e39c2e5b38faa13dce5 +F src/where.c 67a823e7816464bc1de998841e87a2a3e4c20a94 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f2d175f975cd0be63425424ec322a98fb650019e d07c4331a28d44deca1ece8a34118f5b121b3ee2 -R 54aea7d44f4215ed05dbd991004edc4d +P 65a85a156f3c827890e9f1fd22484a2f875c3b6f +R d8f5ca6c104ad88cbb780c1e3e66f865 U drh -Z c8787901468f9008ef7d70e55d347b83 +Z a9ff7ee6c83dbd598cfc582a60fae5a4 diff --git a/manifest.uuid b/manifest.uuid index d90ab3709b..f6e394cf03 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -65a85a156f3c827890e9f1fd22484a2f875c3b6f \ No newline at end of file +a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a \ No newline at end of file diff --git a/src/build.c b/src/build.c index f5ea5be4b6..0239017389 100644 --- a/src/build.c +++ b/src/build.c @@ -2866,7 +2866,7 @@ Index *sqlite3CreateIndex( ** the zStmt variable */ if( pStart ){ - int n = (pParse->sLastToken.z - pName->z) + pParse->sLastToken.n; + int n = (int)(pParse->sLastToken.z - pName->z) + pParse->sLastToken.n; if( pName->z[n-1]==';' ) n--; /* A named index with an explicit CREATE INDEX statement */ zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s", diff --git a/src/shell.c b/src/shell.c index 4a59c667a6..c811057ae3 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2902,6 +2902,7 @@ static int process_input(struct callback_data *p, FILE *in){ if( nSql==0 ){ int i; for(i=0; zLine[i] && IsSpace(zLine[i]); i++){} + assert( nAlloc>0 && zSql!=0 ); memcpy(zSql, zLine+i, nLine+1-i); startline = lineno; nSql = nLine-i; diff --git a/src/vdbe.c b/src/vdbe.c index 1f575c779d..4bd26b377c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6242,6 +6242,7 @@ vdbe_error_halt: ** top. */ vdbe_return: db->lastRowid = lastRowid; + testcase( nVmStep>0 ); p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep; sqlite3VdbeLeave(p); return rc; diff --git a/src/where.c b/src/where.c index 9be48a427f..92a9d3eb80 100644 --- a/src/where.c +++ b/src/where.c @@ -4855,6 +4855,7 @@ static int whereLoopAddOr(WhereLoopBuilder *pBuilder, Bitmask mExtra){ if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK; pWCEnd = pWC->a + pWC->nTerm; pNew = pBuilder->pNew; + memset(&sSum, 0, sizeof(sSum)); for(pTerm=pWC->a; pTermeOperator & WO_OR)!=0