From 2476a6f2cb071b4ea17a99b1ddc05111cd1422f4 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 7 Nov 2015 15:19:59 +0000 Subject: [PATCH 01/55] Enhance TreeView to show WITH clauses. Add an assert to detect the infinite loop behavior when certain kinds of errors occur on a nested WITH clause. FossilOrigin-Name: 2040d88e877bdb69de125a047cefb4a1558e89e8 --- manifest | 19 +++++++++++-------- manifest.uuid | 2 +- src/select.c | 3 ++- src/sqliteInt.h | 1 + src/treeview.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 782863019b..f844244b93 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sOPFLAG_SEEKEQ\soptimization\sis\sonly\sapplicable\sto\sequality\scomparisons\nagainst\san\sindex,\snot\sagainst\sa\srowid\stable. -D 2015-11-07T01:19:00.997 +C Enhance\sTreeView\sto\sshow\sWITH\sclauses.\s\sAdd\san\sassert\sto\sdetect\sthe\ninfinite\sloop\sbehavior\swhen\scertain\skinds\sof\serrors\soccur\son\sa\snested\nWITH\sclause. +D 2015-11-07T15:19:59.796 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -340,12 +340,12 @@ F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 167b4e9058bc8e997d18d6b6b20ecbb0c9c457af +F src/select.c f5b0518eeb623ab4e6883a04b19602e5f914cfd7 F src/shell.c d25df04168d6ba5a4fa05bdbf859df667f9eb621 F src/sqlite.h.in 3cfc86c55e57c63d86b9e1e92869e2bfb162ca8e F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h 12ff325b433c4ded39995b74b01b78aacc19805a +F src/sqliteInt.h a6cddd46ae93372eb3b1acd4f2f23c4de02a94d6 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -397,7 +397,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 F src/tokenize.c 338bc8f7c9dd103188952cda7964696bacac6d22 -F src/treeview.c 154f0acc622fa3514de8777dcedf4c8a8802b4ce +F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f F src/update.c 40e51cd0883cb5bfd6abb7d8a7cd8aa47fab2945 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c @@ -1400,7 +1400,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P dd9a26ecdeaef7b0b9cbf4ff70448ab13a276b4e -R 37fd8f25666e5cc61c467cdb94b7bb71 +P 0f5b147d1fe83c34d0fbeacc7422be94d8441bc1 +R 62a6359affd853c29ced84c847c76120 +T *branch * infinite-with-loop-bug +T *sym-infinite-with-loop-bug * +T -sym-trunk * U drh -Z b3bf4f06c783a2156de71d3cb1963976 +Z 3b853d83f7a6a14368bd6ec3d809b3a9 diff --git a/manifest.uuid b/manifest.uuid index f7a057f393..70e1510060 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f5b147d1fe83c34d0fbeacc7422be94d8441bc1 \ No newline at end of file +2040d88e877bdb69de125a047cefb4a1558e89e8 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 8db983891f..456271365f 100644 --- a/src/select.c +++ b/src/select.c @@ -3972,7 +3972,7 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){ ** object that the returned CTE belongs to. */ static struct Cte *searchWith( - With *pWith, /* Current outermost WITH clause */ + With *pWith, /* Current innermost WITH clause */ struct SrcList_item *pItem, /* FROM clause element to resolve */ With **ppContext /* OUT: WITH clause return value belongs to */ ){ @@ -4005,6 +4005,7 @@ static struct Cte *searchWith( void sqlite3WithPush(Parse *pParse, With *pWith, u8 bFree){ assert( bFree==0 || pParse->pWith==0 ); if( pWith ){ + assert( pParse->pWith!=pWith ); pWith->pOuter = pParse->pWith; pParse->pWith = pWith; pParse->bFreeWith = bFree; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 2b9ece78e2..8956c43b06 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3271,6 +3271,7 @@ char *sqlite3VMPrintf(sqlite3*,const char*, va_list); void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); void sqlite3TreeViewSelect(TreeView*, const Select*, u8); + void sqlite3TreeViewWith(TreeView*, const With*, u8); #endif diff --git a/src/treeview.c b/src/treeview.c index 971de4e8bc..a26e9e2b9f 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -79,6 +79,45 @@ static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ sqlite3TreeViewLine(p, "%s", zLabel); } +/* +** Generate a human-readable description of a WITH clause. +*/ +void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ + int i; + if( pWith==0 ) return; + if( pWith->nCte==0 ) return; + if( pWith->pOuter ){ + sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); + }else{ + sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); + } + if( pWith->nCte>0 ){ + pView = sqlite3TreeViewPush(pView, 1); + for(i=0; inCte; i++){ + StrAccum x; + char zLine[1000]; + const struct Cte *pCte = &pWith->a[i]; + sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); + sqlite3XPrintf(&x, 0, "%s", pCte->zName); + if( pCte->pCols && pCte->pCols->nExpr>0 ){ + char cSep = '('; + int j; + for(j=0; jpCols->nExpr; j++){ + sqlite3XPrintf(&x, 0, "%c%s", cSep, pCte->pCols->a[j].zName); + cSep = ','; + } + sqlite3XPrintf(&x, 0, ")"); + } + sqlite3XPrintf(&x, 0, " AS"); + sqlite3StrAccumFinish(&x); + sqlite3TreeViewItem(pView, zLine, inCte-1); + sqlite3TreeViewSelect(pView, pCte->pSelect, 0); + sqlite3TreeViewPop(pView); + } + sqlite3TreeViewPop(pView); + } +} + /* ** Generate a human-readable description of a the Select object. @@ -87,6 +126,11 @@ void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ int n = 0; int cnt = 0; pView = sqlite3TreeViewPush(pView, moreToFollow); + if( p->pWith ){ + sqlite3TreeViewWith(pView, p->pWith, 1); + cnt = 1; + sqlite3TreeViewPush(pView, 1); + } do{ sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x", ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), From 6e7722669ec0080c1fec7d315460b77aecbd9e4f Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 7 Nov 2015 17:48:21 +0000 Subject: [PATCH 02/55] Proposed fix for an infinite loop bug in the WITH clause semantic analysis logic. FossilOrigin-Name: 028475cb17a4b50baf0e9aba9bd3403d0a5d03b0 --- manifest | 20 +++++++--------- manifest.uuid | 2 +- src/select.c | 5 ++-- src/sqliteInt.h | 2 +- src/tokenize.c | 2 +- test/with3.test | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 test/with3.test diff --git a/manifest b/manifest index f844244b93..c81ed9bc69 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sTreeView\sto\sshow\sWITH\sclauses.\s\sAdd\san\sassert\sto\sdetect\sthe\ninfinite\sloop\sbehavior\swhen\scertain\skinds\sof\serrors\soccur\son\sa\snested\nWITH\sclause. -D 2015-11-07T15:19:59.796 +C Proposed\sfix\sfor\san\sinfinite\sloop\sbug\sin\sthe\sWITH\sclause\ssemantic\sanalysis\nlogic. +D 2015-11-07T17:48:21.602 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -340,12 +340,12 @@ F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c f5b0518eeb623ab4e6883a04b19602e5f914cfd7 +F src/select.c 00a2a10d4298a685d0eeb05b09ef018a2bd81bf8 F src/shell.c d25df04168d6ba5a4fa05bdbf859df667f9eb621 F src/sqlite.h.in 3cfc86c55e57c63d86b9e1e92869e2bfb162ca8e F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h a6cddd46ae93372eb3b1acd4f2f23c4de02a94d6 +F src/sqliteInt.h bc6d24460fe544323517630b1e20539146379077 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -396,7 +396,7 @@ F src/test_vfs.c 3b65d42e18b262805716bd96178c81da8f2d9283 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 -F src/tokenize.c 338bc8f7c9dd103188952cda7964696bacac6d22 +F src/tokenize.c b05b63e224a12531813efda3bcc73e9438958745 F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f F src/update.c 40e51cd0883cb5bfd6abb7d8a7cd8aa47fab2945 @@ -1331,6 +1331,7 @@ F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d F test/with1.test a1e8660be88e2eb4648f8860f831d1e38b5b5443 F test/with2.test 2b40da883658eb74ad8ad06afabe11a408e7fb87 +F test/with3.test 511bacdbe41c49cf34f9fd1bd3245fe1575bca98 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991 F test/without_rowid1.test 1a7b9bd51b899928d327052df9741d2fe8dbe701 F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 @@ -1400,10 +1401,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0f5b147d1fe83c34d0fbeacc7422be94d8441bc1 -R 62a6359affd853c29ced84c847c76120 -T *branch * infinite-with-loop-bug -T *sym-infinite-with-loop-bug * -T -sym-trunk * +P 2040d88e877bdb69de125a047cefb4a1558e89e8 +R 6cacd3ab17c16b2093b599a59893b257 U drh -Z 3b853d83f7a6a14368bd6ec3d809b3a9 +Z 3613be9f7ebbfaa0b17b40694bdae79f diff --git a/manifest.uuid b/manifest.uuid index 70e1510060..31d437d0c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2040d88e877bdb69de125a047cefb4a1558e89e8 \ No newline at end of file +028475cb17a4b50baf0e9aba9bd3403d0a5d03b0 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 456271365f..bd732e5bc8 100644 --- a/src/select.c +++ b/src/select.c @@ -4003,12 +4003,12 @@ static struct Cte *searchWith( ** statement with which it is associated. */ void sqlite3WithPush(Parse *pParse, With *pWith, u8 bFree){ - assert( bFree==0 || pParse->pWith==0 ); + assert( bFree==0 || (pParse->pWith==0 && pParse->pWithToFree==0) ); if( pWith ){ assert( pParse->pWith!=pWith ); pWith->pOuter = pParse->pWith; pParse->pWith = pWith; - pParse->bFreeWith = bFree; + if( bFree ) pParse->pWithToFree = pWith; } } @@ -4101,6 +4101,7 @@ static int withExpand( pSavedWith = pParse->pWith; pParse->pWith = pWith; sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel); + pParse->pWith = pWith; for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); pEList = pLeft->pEList; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8956c43b06..c65e0f2051 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2754,7 +2754,6 @@ struct Parse { int nVar; /* Number of '?' variables seen in the SQL so far */ int nzVar; /* Number of available slots in azVar[] */ u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */ - u8 bFreeWith; /* True if pWith should be freed with parser */ u8 explain; /* True if the EXPLAIN flag is found on the query */ #ifndef SQLITE_OMIT_VIRTUALTABLE u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ @@ -2781,6 +2780,7 @@ struct Parse { Table *pZombieTab; /* List of Table objects to delete after code gen */ TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ With *pWith; /* Current WITH clause, or NULL */ + With *pWithToFree; /* Free this WITH object at the end of the parse */ }; /* diff --git a/src/tokenize.c b/src/tokenize.c index 9c1403bb29..f2b63b5cf1 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -510,7 +510,7 @@ abort_parse: sqlite3DeleteTable(db, pParse->pNewTable); } - if( pParse->bFreeWith ) sqlite3WithDelete(db, pParse->pWith); + sqlite3WithDelete(db, pParse->pWithToFree); sqlite3DeleteTrigger(db, pParse->pNewTrigger); for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]); sqlite3DbFree(db, pParse->azVar); diff --git a/test/with3.test b/test/with3.test new file mode 100644 index 0000000000..62e88441ab --- /dev/null +++ b/test/with3.test @@ -0,0 +1,64 @@ +# 2015-11-07 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the WITH clause. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix with3 + +ifcapable {!cte} { + finish_test + return +} + +# Test problems found by Kostya Serebryany using +# LibFuzzer. (http://llvm.org/docs/LibFuzzer.html) +# +do_catchsql_test 1.0 { + WITH i(x) AS ( + WITH j AS (SELECT 10) + SELECT 5 FROM t0 UNION SELECT 8 FROM m + ) + SELECT * FROM i; +} {1 {no such table: m}} + +# Additional test cases that came out of the work to +# fix for Kostya's problem. +# +do_execsql_test 2.0 { + WITH + x1 AS (SELECT 10), + x2 AS (SELECT 11), + x3 AS ( + SELECT * FROM x1 UNION ALL SELECT * FROM x2 + ), + x4 AS ( + WITH + x1 AS (SELECT 12), + x2 AS (SELECT 13) + SELECT * FROM x3 + ) + SELECT * FROM x4; + +} {10 11} + +do_execsql_test 2.1 { + CREATE TABLE t1(x); + WITH + x1(a) AS (values(100)) + INSERT INTO t1(x) + SELECT * FROM (WITH x2(y) AS (SELECT * FROM x1) SELECT y+a FROM x1, x2); + SELECT * FROM t1; +} {200} + +finish_test From fe88fbfc828594d00999649ab6a8dcff5db64821 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 7 Nov 2015 17:51:39 +0000 Subject: [PATCH 03/55] Add test cases for WITH clauses. FossilOrigin-Name: e7e65c7559ed43e7065adc2ec1bd242bf187b7c3 --- manifest | 14 +++--- manifest.uuid | 2 +- test/with1.test | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c81ed9bc69..b8a59cb2c6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Proposed\sfix\sfor\san\sinfinite\sloop\sbug\sin\sthe\sWITH\sclause\ssemantic\sanalysis\nlogic. -D 2015-11-07T17:48:21.602 +C Add\stest\scases\sfor\sWITH\sclauses. +D 2015-11-07T17:51:39.619 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -1329,7 +1329,7 @@ F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d -F test/with1.test a1e8660be88e2eb4648f8860f831d1e38b5b5443 +F test/with1.test 05c8fc7f809f178a8a0519f02c21fe430948c895 F test/with2.test 2b40da883658eb74ad8ad06afabe11a408e7fb87 F test/with3.test 511bacdbe41c49cf34f9fd1bd3245fe1575bca98 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991 @@ -1401,7 +1401,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2040d88e877bdb69de125a047cefb4a1558e89e8 -R 6cacd3ab17c16b2093b599a59893b257 -U drh -Z 3613be9f7ebbfaa0b17b40694bdae79f +P 028475cb17a4b50baf0e9aba9bd3403d0a5d03b0 +R 0a66e1cb90e0f88ea5b94da656f84e5f +U dan +Z 560670311488774642220bf984dfc3d3 diff --git a/manifest.uuid b/manifest.uuid index 31d437d0c6..c4a678277c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -028475cb17a4b50baf0e9aba9bd3403d0a5d03b0 \ No newline at end of file +e7e65c7559ed43e7065adc2ec1bd242bf187b7c3 \ No newline at end of file diff --git a/test/with1.test b/test/with1.test index 71eec61e7d..d98f33dfb0 100644 --- a/test/with1.test +++ b/test/with1.test @@ -865,4 +865,114 @@ do_catchsql_test 16.1 { SELECT * FROM i; } {1 {recursive aggregate queries not supported}} +#------------------------------------------------------------------------- +do_execsql_test 17.1 { + WITH x(a) AS ( + WITH y(b) AS (SELECT 10) + SELECT 9 UNION ALL SELECT * FROM y + ) + SELECT * FROM x +} {9 10} + +do_execsql_test 17.2 { + WITH x AS ( + WITH y(b) AS (SELECT 10) + SELECT * FROM y UNION ALL SELECT * FROM y + ) + SELECT * FROM x +} {10 10} + +do_test 17.2 { + db eval { + WITH x AS ( + WITH y(b) AS (SELECT 10) + SELECT * FROM y UNION ALL SELECT * FROM y + ) + SELECT * FROM x + } A { + # no op + } + set A(*) +} {b} + +do_catchsql_test 17.3 { + WITH i AS ( + WITH j AS (SELECT 5) + SELECT 5 FROM i UNION SELECT 8 FROM i + ) + SELECT * FROM i; +} {1 {circular reference: i}} + +do_catchsql_test 17.4 { + WITH i AS ( + WITH j AS (SELECT 5) + SELECT 5 FROM t1 UNION SELECT 8 FROM t11 + ) + SELECT * FROM i; +} {1 {no such table: t11}} + +do_execsql_test 17.5 { + WITH + x1 AS (SELECT 10), + x2 AS (SELECT * FROM x1), + x3 AS ( + WITH x1 AS (SELECT 11) + SELECT * FROM x2 UNION ALL SELECT * FROM x2 + ) + SELECT * FROM x3; +} {10 10} + +do_execsql_test 17.6 { + WITH + x1 AS (SELECT 10), + x2 AS (SELECT * FROM x1), + x3 AS ( + WITH x1 AS (SELECT 11) + SELECT * FROM x2 UNION ALL SELECT * FROM x1 + ) + SELECT * FROM x3; +} {10 11} + +do_execsql_test 17.7 { + WITH + x1 AS (SELECT 10), + x2 AS (SELECT * FROM x1), + x3 AS ( + WITH + x1 AS ( SELECT 11 ), + x4 AS ( SELECT * FROM x2 ) + SELECT * FROM x4 UNION ALL SELECT * FROM x1 + ) + SELECT * FROM x3; +} {10 11} + +do_execsql_test 17.8 { + WITH + x1 AS (SELECT 10), + x2 AS (SELECT * FROM x1), + x3 AS ( + WITH + x1 AS ( SELECT 11 ), + x4 AS ( SELECT * FROM x2 ) + SELECT * FROM x4 UNION ALL SELECT * FROM x1 + ) + SELECT * FROM x3; +} {10 11} + +do_execsql_test 17.9 { + WITH + x1 AS (SELECT 10), + x2 AS (SELECT 11), + x3 AS ( + SELECT * FROM x1 UNION ALL SELECT * FROM x2 + ), + x4 AS ( + WITH + x1 AS (SELECT 12), + x2 AS (SELECT 13) + SELECT * FROM x3 + ) + SELECT * FROM x4; +} {10 11} + finish_test From edd2260b40ce9182031f35f24aa7652bc1748d7c Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 7 Nov 2015 18:32:17 +0000 Subject: [PATCH 04/55] Enhance the sqldiff utility to deal gracefully with ALTER TABLE ADD COLUMN. FossilOrigin-Name: 7ea036ac37397ed8f6a0fa9f5bfc0994364b53dc --- manifest | 15 +++++++-------- manifest.uuid | 2 +- tool/sqldiff.c | 27 ++++++++++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index b2a16a7394..1c72713975 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\sCTE\shandling\sdiscovered\sby\sLibFuzzer\sthat\scan\scause\san\sinfinite\sloop\sin\sthe\squery\splanner. -D 2015-11-07T18:07:15.260 +C Enhance\sthe\ssqldiff\sutility\sto\sdeal\sgracefully\swith\sALTER\sTABLE\sADD\sCOLUMN. +D 2015-11-07T18:32:17.087 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -1390,7 +1390,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c b318efc2eaf7a7fac4d281a0ce736193cb2506df +F tool/sqldiff.c 37ab2cd4f0c8b4f0bbdc2f41f63f0f262e25805d F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1401,8 +1401,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0f5b147d1fe83c34d0fbeacc7422be94d8441bc1 e7e65c7559ed43e7065adc2ec1bd242bf187b7c3 -R 0a66e1cb90e0f88ea5b94da656f84e5f -T +closed e7e65c7559ed43e7065adc2ec1bd242bf187b7c3 -U dan -Z 97f5561994d709cf0287df4980640bc9 +P 088009efdd56160bb4eee0fbd829a529b141274e +R 6849733f18d4f768e8de91b6fdec79e9 +U drh +Z e7f3d6622d7fdf445d9b0889f3775adc diff --git a/manifest.uuid b/manifest.uuid index 576eda30af..4bc50f23f2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -088009efdd56160bb4eee0fbd829a529b141274e \ No newline at end of file +7ea036ac37397ed8f6a0fa9f5bfc0994364b53dc \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 9f0b705c40..944968fe05 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -558,7 +558,7 @@ static void diff_one_table(const char *zTab, FILE *out){ az = columnNames("main", zTab, &nPk, 0); az2 = columnNames("aux", zTab, &nPk2, 0); if( az && az2 ){ - for(n=0; az[n]; n++){ + for(n=0; az[n] && az2[n]; n++){ if( sqlite3_stricmp(az[n],az2[n])!=0 ) break; } } @@ -568,13 +568,15 @@ static void diff_one_table(const char *zTab, FILE *out){ || az[n] ){ /* Schema mismatch */ - fprintf(out, "DROP TABLE %s;\n", zId); + fprintf(out, "DROP TABLE %s; -- due to schema mismatch\n", zId); dump_table(zTab, out); goto end_diff_one_table; } /* Build the comparison query */ - for(n2=n; az[n2]; n2++){} + for(n2=n; az2[n2]; n2++){ + fprintf(out, "ALTER TABLE %s ADD COLUMN %s;\n", zId, safeId(az2[n2])); + } nQ = nPk2+1+2*(n2-nPk2); if( n2>nPk2 ){ zSep = "SELECT "; @@ -585,7 +587,12 @@ static void diff_one_table(const char *zTab, FILE *out){ strPrintf(&sql, ", 1%s -- changed row\n", nPk==n ? "" : ","); while( az[i] ){ strPrintf(&sql, " A.%s IS NOT B.%s, B.%s%s\n", - az[i], az[i], az[i], i==n2-1 ? "" : ","); + az[i], az2[i], az2[i], az2[i+1]==0 ? "" : ","); + i++; + } + while( az2[i] ){ + strPrintf(&sql, " B.%s IS NOT NULL, B.%s%s\n", + az2[i], az2[i], az2[i+1]==0 ? "" : ","); i++; } strPrintf(&sql, " FROM main.%s A, aux.%s B\n", zId, zId); @@ -597,7 +604,13 @@ static void diff_one_table(const char *zTab, FILE *out){ zSep = "\n AND ("; while( az[i] ){ strPrintf(&sql, "%sA.%s IS NOT B.%s%s\n", - zSep, az[i], az[i], i==n2-1 ? ")" : ""); + zSep, az[i], az2[i], az2[i+1]==0 ? ")" : ""); + zSep = " OR "; + i++; + } + while( az2[i] ){ + strPrintf(&sql, "%sB.%s IS NOT NULL%s\n", + zSep, az2[i], az2[i+1]==0 ? ")" : ""); zSep = " OR "; i++; } @@ -609,7 +622,7 @@ static void diff_one_table(const char *zTab, FILE *out){ zSep = ", "; } strPrintf(&sql, ", 2%s -- deleted row\n", nPk==n ? "" : ","); - while( az[i] ){ + while( az2[i] ){ strPrintf(&sql, " NULL, NULL%s\n", i==n2-1 ? "" : ","); i++; } @@ -628,7 +641,7 @@ static void diff_one_table(const char *zTab, FILE *out){ } strPrintf(&sql, ", 3%s -- inserted row\n", nPk==n ? "" : ","); while( az2[i] ){ - strPrintf(&sql, " 1, B.%s%s\n", az[i], i==n2-1 ? "" : ","); + strPrintf(&sql, " 1, B.%s%s\n", az2[i], az2[i+1]==0 ? "" : ","); i++; } strPrintf(&sql, " FROM aux.%s B\n", zId); From 0739e45bcd8c66cbb7dcde7f5b2b04b167069e26 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 02:08:09 +0000 Subject: [PATCH 05/55] Small size reduction and performance increase in the parser. FossilOrigin-Name: d62cd757a69cc49c2d309e27c948610b5868632f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/tokenize.c | 34 ++++++++++++---------------------- tool/addopcodes.tcl | 11 ++++++++--- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index 1c72713975..f46bfb5259 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\ssqldiff\sutility\sto\sdeal\sgracefully\swith\sALTER\sTABLE\sADD\sCOLUMN. -D 2015-11-07T18:32:17.087 +C Small\ssize\sreduction\sand\sperformance\sincrease\sin\sthe\sparser. +D 2015-11-09T02:08:09.483 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -396,7 +396,7 @@ F src/test_vfs.c 3b65d42e18b262805716bd96178c81da8f2d9283 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 -F src/tokenize.c b05b63e224a12531813efda3bcc73e9438958745 +F src/tokenize.c c1006aa773da5725ef55e8d48f69c11d7141d011 F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f F src/update.c 40e51cd0883cb5bfd6abb7d8a7cd8aa47fab2945 @@ -1344,7 +1344,7 @@ F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 8606413d3035c05373a0d7fae82ebf59ae9e16c3 -F tool/addopcodes.tcl 26892c394964c194fe96b9a79b8b9f87347c7151 +F tool/addopcodes.tcl f1fd17b639910226749d1ae006beef8f60378274 F tool/build-all-msvc.bat e42141ca3c3812315432f9813ef9eb78aa8d99c9 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 @@ -1401,7 +1401,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 088009efdd56160bb4eee0fbd829a529b141274e -R 6849733f18d4f768e8de91b6fdec79e9 +P 7ea036ac37397ed8f6a0fa9f5bfc0994364b53dc +R 3231bc9f57ce7558e058f50c744abb1e U drh -Z e7f3d6622d7fdf445d9b0889f3775adc +Z db3ec02e9e575bd3c4a05b8f4b24bc15 diff --git a/manifest.uuid b/manifest.uuid index 4bc50f23f2..cf6442cb11 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7ea036ac37397ed8f6a0fa9f5bfc0994364b53dc \ No newline at end of file +d62cd757a69cc49c2d309e27c948610b5868632f \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index f2b63b5cf1..81b98d593a 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -416,7 +416,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ assert( pParse->azVar==0 ); enableLookaside = db->lookaside.bEnabled; if( db->lookaside.pStart ) db->lookaside.bEnabled = 1; - while( !db->mallocFailed && zSql[i]!=0 ){ + while( zSql[i]!=0 ){ assert( i>=0 ); pParse->sLastToken.z = &zSql[i]; pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType); @@ -425,35 +425,25 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ pParse->rc = SQLITE_TOOBIG; break; } - switch( tokenType ){ - case TK_SPACE: { - if( db->u1.isInterrupted ){ - sqlite3ErrorMsg(pParse, "interrupt"); - pParse->rc = SQLITE_INTERRUPT; - goto abort_parse; - } + if( tokenType>=TK_SPACE ){ + assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); + if( db->u1.isInterrupted ){ + sqlite3ErrorMsg(pParse, "interrupt"); + pParse->rc = SQLITE_INTERRUPT; break; } - case TK_ILLEGAL: { + if( tokenType==TK_ILLEGAL ){ sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &pParse->sLastToken); - goto abort_parse; - } - case TK_SEMI: { - pParse->zTail = &zSql[i]; - /* Fall thru into the default case */ - } - default: { - sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse); - lastTokenParsed = tokenType; - if( pParse->rc!=SQLITE_OK ){ - goto abort_parse; - } break; } + }else{ + if( tokenType==TK_SEMI ) pParse->zTail = &zSql[i]; + sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse); + lastTokenParsed = tokenType; + if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break; } } -abort_parse: assert( nErr==0 ); if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){ assert( zSql[i]==0 ); diff --git a/tool/addopcodes.tcl b/tool/addopcodes.tcl index c5c3525ad4..bd0b73a35f 100644 --- a/tool/addopcodes.tcl +++ b/tool/addopcodes.tcl @@ -18,7 +18,8 @@ while {![eof $in]} { } close $in -# The following are the extra token codes to be added +# The following are the extra token codes to be added. SPACE and +# ILLEGAL *must* be the last two token codes and they must be in that order. # set extras { TO_TEXT @@ -28,8 +29,6 @@ set extras { TO_REAL ISNOT END_OF_FILE - ILLEGAL - SPACE UNCLOSED_STRING FUNCTION COLUMN @@ -38,6 +37,12 @@ set extras { UMINUS UPLUS REGISTER + SPACE + ILLEGAL +} +if {[lrange $extras end-1 end]!="SPACE ILLEGAL"} { + error "SPACE and ILLEGAL must be the last two token codes and they\ + must be in that order" } foreach x $extras { incr max From d797035ac78a0854e6a4c13e03849318d92459af Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 12:33:39 +0000 Subject: [PATCH 06/55] Avoid unnecessary function prologues in the sqlite3VdbeAddOp3() routine. FossilOrigin-Name: 7c6a19ba9b0bdb1cc0b9a9796b7c1c114944d927 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 10 +++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f46bfb5259..cd829a2bee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Small\ssize\sreduction\sand\sperformance\sincrease\sin\sthe\sparser. -D 2015-11-09T02:08:09.483 +C Avoid\sunnecessary\sfunction\sprologues\sin\sthe\ssqlite3VdbeAddOp3()\sroutine. +D 2015-11-09T12:33:39.340 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -407,7 +407,7 @@ F src/vdbe.c 7a9b18027414368d800716e6319e2acd699c70db F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637 F src/vdbeInt.h 33403622c6a8feaaac5f0f3f17f5d1bf6df42286 F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca -F src/vdbeaux.c 6d55530b05b69bc663c87d2d258318dcdf042644 +F src/vdbeaux.c da9eddc62e025148e30267600a6fe3882d5e912f F src/vdbeblob.c 565fabd302f5fca3bdf3d56cac330483616a39b6 F src/vdbemem.c fdd1578e47bea61390d472de53c565781d81e045 F src/vdbesort.c 8b23930a1289526f6d2a3a9f2e965bcc963e4a68 @@ -1401,7 +1401,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7ea036ac37397ed8f6a0fa9f5bfc0994364b53dc -R 3231bc9f57ce7558e058f50c744abb1e +P d62cd757a69cc49c2d309e27c948610b5868632f +R a904c99753c26b60df840fbeb9147fea U drh -Z db3ec02e9e575bd3c4a05b8f4b24bc15 +Z 04359d40d10a11f87d61acdb694f52aa diff --git a/manifest.uuid b/manifest.uuid index cf6442cb11..d3a3f51b6e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d62cd757a69cc49c2d309e27c948610b5868632f \ No newline at end of file +7c6a19ba9b0bdb1cc0b9a9796b7c1c114944d927 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 83a9047dc7..a5bc0b71a2 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -157,6 +157,12 @@ static void test_addop_breakpoint(void){ ** the sqlite3VdbeChangeP4() function to change the value of the P4 ** operand. */ +static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3){ + assert( p->pParse->nOpAlloc<=p->nOp ); + if( growOpArray(p, 1) ) return 1; + assert( p->pParse->nOpAlloc>p->nOp ); + return sqlite3VdbeAddOp3(p, op, p1, p2, p3); +} int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ int i; VdbeOp *pOp; @@ -165,9 +171,7 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ assert( p->magic==VDBE_MAGIC_INIT ); assert( op>0 && op<0xff ); if( p->pParse->nOpAlloc<=i ){ - if( growOpArray(p, 1) ){ - return 1; - } + return growOp3(p, op, p1, p2, p3); } p->nOp++; pOp = &p->aOp[i]; From f10b1f78ee6a3bc5aa9b10c2c090516ef49187b7 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 12:44:19 +0000 Subject: [PATCH 07/55] Check in the cg_anno.tcl and run-speed-test.sh scripts, as an historical record. FossilOrigin-Name: 836418d3b7cfcd5ec375c4e08c09bd6b78646307 --- manifest | 12 ++++---- manifest.uuid | 2 +- tool/cg_anno.tcl | 24 +++++++++++++++ tool/run-speed-test.sh | 68 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100755 tool/cg_anno.tcl create mode 100644 tool/run-speed-test.sh diff --git a/manifest b/manifest index cd829a2bee..3e38a0f6ef 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sunnecessary\sfunction\sprologues\sin\sthe\ssqlite3VdbeAddOp3()\sroutine. -D 2015-11-09T12:33:39.340 +C Check\sin\sthe\scg_anno.tcl\sand\srun-speed-test.sh\sscripts,\sas\san\shistorical\nrecord. +D 2015-11-09T12:44:19.680 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -1347,6 +1347,7 @@ F tool/GetTclKit.bat 8606413d3035c05373a0d7fae82ebf59ae9e16c3 F tool/addopcodes.tcl f1fd17b639910226749d1ae006beef8f60378274 F tool/build-all-msvc.bat e42141ca3c3812315432f9813ef9eb78aa8d99c9 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 +F tool/cg_anno.tcl 692ce4b8693d59e3a3de77ca97f4139ecfa641b0 x F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 @@ -1377,6 +1378,7 @@ F tool/pagesig.c ff0ca355fd3c2398e933da5e22439bbff89b803b F tool/replace.tcl 7727c60a04299b65a92f5e1590896fea0f25b9e0 F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 +F tool/run-speed-test.sh 0ae485af4fe9f826e2b494be8c81f8ca9e222a4a F tool/showdb.c d4476e000a64eca9f5e2c2f68741e747b9778e8d F tool/showjournal.c 5bad7ae8784a43d2b270d953060423b8bd480818 F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 @@ -1401,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d62cd757a69cc49c2d309e27c948610b5868632f -R a904c99753c26b60df840fbeb9147fea +P 7c6a19ba9b0bdb1cc0b9a9796b7c1c114944d927 +R 9d7a4cba8878c4f3f14011449d7a4d87 U drh -Z 04359d40d10a11f87d61acdb694f52aa +Z cd8c6de9d269073054c5419c6ba867b6 diff --git a/manifest.uuid b/manifest.uuid index d3a3f51b6e..2649680579 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c6a19ba9b0bdb1cc0b9a9796b7c1c114944d927 \ No newline at end of file +836418d3b7cfcd5ec375c4e08c09bd6b78646307 \ No newline at end of file diff --git a/tool/cg_anno.tcl b/tool/cg_anno.tcl new file mode 100755 index 0000000000..f806c5a5af --- /dev/null +++ b/tool/cg_anno.tcl @@ -0,0 +1,24 @@ +#!/usr/bin/tclsh +# +# A wrapper around cg_annotate that sets appropriate command-line options +# and rearranges the output so that annotated files occur in a consistent +# sorted order. Used by the run-speed-test.tcl script. +# + +set in [open "|cg_annotate --show=Ir --auto=yes --context=40 $argv" r] +set dest ! +set out(!) {} +while {![eof $in]} { + set line [string map {\t { }} [gets $in]] + if {[regexp {^-- Auto-annotated source: (.*)} $line all name]} { + set dest $name + } elseif {[regexp {^-- line \d+ ------} $line]} { + set line [lreplace $line 2 2 {#}] + } elseif {[regexp {^The following files chosen for } $line]} { + set dest ! + } + append out($dest) $line\n +} +foreach x [lsort [array names out]] { + puts $out($x) +} diff --git a/tool/run-speed-test.sh b/tool/run-speed-test.sh new file mode 100644 index 0000000000..ee2ceac660 --- /dev/null +++ b/tool/run-speed-test.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# +# This is a template for a script used for day-to-day size and +# performance monitoring of SQLite. Typical usage: +# +# sh run-speed-test.sh trunk # Baseline measurement of trunk +# sh run-speed-test.sh x1 # Measure some experimental change +# fossil test-diff --tk cout-trunk.txt cout-x1.txt # View chanages +# +# There are multiple output files, all with a base name given by +# the first argument: +# +# summary-$BASE.txt # Copy of standard output +# cout-$BASE.txt # cachegrind output +# explain-$BASE.txt # EXPLAIN listings +# +if test "$1" = "" +then + echo "Usage: $0 OUTPUTFILE [OPTIONS]" + exit +fi +NAME=$1 +shift +CC_OPTS="-DSQLITE_ENABLE_RTREE" +SPEEDTEST_OPTS="--shrink-memory --reprepare" +SIZE=5 +while test "$1" != ""; do + case $1 in + --reprepare) + SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1" + ;; + --autovacuum) + SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1" + ;; + --utf16be) + SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1" + ;; + --without-rowid) + SPEEDTEST_OPTS="$SPEEDTEST_OPTS $1" + ;; + --size) + shift; SIZE=$1 + ;; + *) + CC_OPTS="$CC_OPTS $1" + ;; + esac + shift +done +SPEEDTEST_OPTS="$SPEEDTEST_OPTS --size $SIZE" +echo "NAME = $NAME" | tee summary-$NAME.txt +echo "SPEEDTEST_OPTS = $SPEEDTEST_OPTS" | tee -a summary-$NAME.txt +echo "CC_OPTS = $CC_OPTS" | tee -a summary-$NAME.txt +rm -f cachegrind.out.* speedtest1 speedtest1.db sqlite3.o +gcc -g -Os -Wall -I. $CC_OPTS -c sqlite3.c +size sqlite3.o | tee -a summary-$NAME.txt +gcc -g -Os -Wall -I. $CC_OPTS \ + -DSQLITE_ENABLE_EXPLAIN_COMMENTS \ + ./shell.c ./sqlite3.c -o sqlite3 -ldl -lpthread +SRC=./speedtest1.c +gcc -g -Os -Wall -I. $CC_OPTS $SRC ./sqlite3.o -o speedtest1 -ldl -lpthread +ls -l speedtest1 | tee -a summary-$NAME.txt +valgrind --tool=cachegrind ./speedtest1 speedtest1.db \ + $SPEEDTEST_OPTS 2>&1 | tee -a summary-$NAME.txt +size sqlite3.o | tee -a summary-$NAME.txt +wc sqlite3.c +cg_anno.tcl cachegrind.out.* >cout-$NAME.txt +./speedtest1 --explain $SPEEDTEST_OPTS | ./sqlite3 >explain-$NAME.txt From 7450494c502469e1814db2328fda725c2ed1ec8b Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 12:47:04 +0000 Subject: [PATCH 08/55] Fix incorrect WHERE clause in sqldiff, as reported on the mailing list by Youcef Hilem. FossilOrigin-Name: e0ed4c3e376248dfbf903e4b5845f910824fa6c6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/sqldiff.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 3e38a0f6ef..00baa3e5e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Check\sin\sthe\scg_anno.tcl\sand\srun-speed-test.sh\sscripts,\sas\san\shistorical\nrecord. -D 2015-11-09T12:44:19.680 +C Fix\sincorrect\sWHERE\sclause\sin\ssqldiff,\sas\sreported\son\sthe\smailing\slist\nby\sYoucef\sHilem. +D 2015-11-09T12:47:04.583 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -1392,7 +1392,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 37ab2cd4f0c8b4f0bbdc2f41f63f0f262e25805d +F tool/sqldiff.c 40e3458f0015290be8ecb6e03f9dbf1bb1e264c0 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 7c6a19ba9b0bdb1cc0b9a9796b7c1c114944d927 -R 9d7a4cba8878c4f3f14011449d7a4d87 +P 836418d3b7cfcd5ec375c4e08c09bd6b78646307 +R d937c57aac217cda0397e7f6695d66bb U drh -Z cd8c6de9d269073054c5419c6ba867b6 +Z 203526c61164c46fffc3cfcb2374dd46 diff --git a/manifest.uuid b/manifest.uuid index 2649680579..cfaa513cbc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -836418d3b7cfcd5ec375c4e08c09bd6b78646307 \ No newline at end of file +e0ed4c3e376248dfbf903e4b5845f910824fa6c6 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 944968fe05..90a53fe16a 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -702,7 +702,7 @@ static void diff_one_table(const char *zTab, FILE *out){ for(i=0; i Date: Mon, 9 Nov 2015 14:11:37 +0000 Subject: [PATCH 09/55] Size reduction and performance improvement in the stack-popping logic of the Lemon-generated parser. FossilOrigin-Name: 9748c48a4fbd5c06208bbf80e7bfcb159ec026d9 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/lempar.c | 18 +++++------------- tool/lempar.c | 18 ++++++------------ 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index 00baa3e5e2..6d273a47e7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sincorrect\sWHERE\sclause\sin\ssqldiff,\sas\sreported\son\sthe\smailing\slist\nby\sYoucef\sHilem. -D 2015-11-09T12:47:04.583 +C Size\sreduction\sand\sperformance\simprovement\sin\sthe\sstack-popping\slogic\sof\nthe\sLemon-generated\sparser. +D 2015-11-09T14:11:37.997 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -303,7 +303,7 @@ F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/insert.c 419a947f27ce2da18eebf440a5aa80cc825defae F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e -F src/lempar.c d344a95d60c24e2f490ee59db9784b1b17439012 +F src/lempar.c 68f7e1e9d7a19e97e81e921f35f28063cc57cc91 F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 F src/main.c f393acc6e5d604cbe0054376d62f668a5560b3f1 F src/malloc.c 337bbe9c7d436ef9b7d06b5dd10bbfc8f3025972 @@ -1357,7 +1357,7 @@ F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d -F tool/lempar.c 3617143ddb9b176c3605defe6a9c798793280120 +F tool/lempar.c 5ea7cad700dd4df4486e825b9149f40137efcfbb F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 836418d3b7cfcd5ec375c4e08c09bd6b78646307 -R d937c57aac217cda0397e7f6695d66bb +P e0ed4c3e376248dfbf903e4b5845f910824fa6c6 +R 08c66b00ee44c1ce6bc53eab9d896126 U drh -Z 203526c61164c46fffc3cfcb2374dd46 +Z 114def794faa9ab9a746aed1255c1eea diff --git a/manifest.uuid b/manifest.uuid index cfaa513cbc..06f04d2a29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e0ed4c3e376248dfbf903e4b5845f910824fa6c6 \ No newline at end of file +9748c48a4fbd5c06208bbf80e7bfcb159ec026d9 \ No newline at end of file diff --git a/src/lempar.c b/src/lempar.c index 5e5a11aeaa..47be43477e 100644 --- a/src/lempar.c +++ b/src/lempar.c @@ -332,27 +332,19 @@ static void yy_destructor( ** ** If there is a destructor routine associated with the token which ** is popped from the stack, then call it. -** -** Return the major token number for the symbol popped. */ -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - - /* There is no mechanism by which the parser stack can be popped below - ** empty in SQLite. */ +static void yy_pop_parser_stack(yyParser *pParser){ + yyStackEntry *yytos; assert( pParser->yyidx>=0 ); + yytos = &pParser->yystack[pParser->yyidx--]; #ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ + if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif - yymajor = yytos->major; - yy_destructor(pParser, yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; + yy_destructor(pParser, yytos->major, &yytos->minor); } /* diff --git a/tool/lempar.c b/tool/lempar.c index cdf4ca5a1a..1b2b1798b4 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -326,25 +326,19 @@ static void yy_destructor( ** ** If there is a destructor routine associated with the token which ** is popped from the stack, then call it. -** -** Return the major token number for the symbol popped. */ -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - - if( pParser->yyidx<0 ) return 0; +static void yy_pop_parser_stack(yyParser *pParser){ + yyStackEntry *yytos; + assert( pParser->yyidx>=0 ); + yytos = &pParser->yystack[pParser->yyidx--]; #ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ + if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif - yymajor = yytos->major; - yy_destructor(pParser, yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; + yy_destructor(pParser, yytos->major, &yytos->minor); } /* From a441404f9215f9a8e7544a4b52899ee3e19b1dff Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 15:06:26 +0000 Subject: [PATCH 10/55] Avoid recursion in the yy_find_shift_action() routine of the Lemon-generated parser, so that routine can be inlined, for a size reduction and performance increase. FossilOrigin-Name: 0557a179f932296cc1fd5217f9a0d2f74e34ce1d --- manifest | 14 ++++---- manifest.uuid | 2 +- src/lempar.c | 83 ++++++++++++++++++++++++---------------------- tool/lempar.c | 92 ++++++++++++++++++++++++++++----------------------- 4 files changed, 103 insertions(+), 88 deletions(-) diff --git a/manifest b/manifest index 6d273a47e7..de4332e89f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Size\sreduction\sand\sperformance\simprovement\sin\sthe\sstack-popping\slogic\sof\nthe\sLemon-generated\sparser. -D 2015-11-09T14:11:37.997 +C Avoid\srecursion\sin\sthe\syy_find_shift_action()\sroutine\sof\sthe\sLemon-generated\nparser,\sso\sthat\sroutine\scan\sbe\sinlined,\sfor\sa\ssize\sreduction\sand\sperformance\nincrease. +D 2015-11-09T15:06:26.258 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -303,7 +303,7 @@ F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/insert.c 419a947f27ce2da18eebf440a5aa80cc825defae F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e -F src/lempar.c 68f7e1e9d7a19e97e81e921f35f28063cc57cc91 +F src/lempar.c 62dbf933df3bd95815a4207925f7e1cf31063443 F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 F src/main.c f393acc6e5d604cbe0054376d62f668a5560b3f1 F src/malloc.c 337bbe9c7d436ef9b7d06b5dd10bbfc8f3025972 @@ -1357,7 +1357,7 @@ F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d -F tool/lempar.c 5ea7cad700dd4df4486e825b9149f40137efcfbb +F tool/lempar.c 4ff2afb0449e9367f6cb4c8513339e3333852099 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e0ed4c3e376248dfbf903e4b5845f910824fa6c6 -R 08c66b00ee44c1ce6bc53eab9d896126 +P 9748c48a4fbd5c06208bbf80e7bfcb159ec026d9 +R c9026e58b8922b5b815b58f78da1a9b7 U drh -Z 114def794faa9ab9a746aed1255c1eea +Z 94abf9709b7d536396fc03122fef0eed diff --git a/manifest.uuid b/manifest.uuid index 06f04d2a29..12c76b678c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9748c48a4fbd5c06208bbf80e7bfcb159ec026d9 \ No newline at end of file +0557a179f932296cc1fd5217f9a0d2f74e34ce1d \ No newline at end of file diff --git a/src/lempar.c b/src/lempar.c index 47be43477e..beef6cfe49 100644 --- a/src/lempar.c +++ b/src/lempar.c @@ -401,52 +401,57 @@ static int yy_find_shift_action( if( stateno>=YY_MIN_REDUCE ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); - i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ + do{ + i = yy_shift_ofst[stateno]; + if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; + assert( iLookAhead!=YYNOCODE ); + i += iLookAhead; + if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ + if( iLookAhead>0 ){ #ifdef YYFALLBACK - YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - return yy_find_shift_action(pParser, iFallback); - } -#endif -#ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( -#if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && -#endif -#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); + fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } +#endif + assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ + iLookAhead = iFallback; + continue; + } +#endif +#ifdef YYWILDCARD + { + int j = i - iLookAhead + YYWILDCARD; + if( +#if YY_SHIFT_MIN+YYWILDCARD<0 + j>=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j %s\n", + yyTracePrompt, yyTokenName[iLookAhead], + yyTokenName[YYWILDCARD]); + } +#endif /* NDEBUG */ + return yy_action[j]; } -#endif /* NDEBUG */ - return yy_action[j]; } - } #endif /* YYWILDCARD */ + } + return yy_default[stateno]; + }else{ + return yy_action[i]; } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } + }while(1); } /* diff --git a/tool/lempar.c b/tool/lempar.c index 1b2b1798b4..b7408f60a2 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -390,55 +390,60 @@ static int yy_find_shift_action( ){ int i; int stateno = pParser->yystack[pParser->yyidx].stateno; - - if( stateno>=YY_MIN_REDUCE ) return stateno; + + if( stateno>=YY_MIN_REDUCE ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); - i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ + do{ + i = yy_shift_ofst[stateno]; + if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; + assert( iLookAhead!=YYNOCODE ); + i += iLookAhead; + if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ + if( iLookAhead>0 ){ #ifdef YYFALLBACK - YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - return yy_find_shift_action(pParser, iFallback); - } -#endif -#ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( -#if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && -#endif -#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); + fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } +#endif + assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ + iLookAhead = iFallback; + continue; + } +#endif +#ifdef YYWILDCARD + { + int j = i - iLookAhead + YYWILDCARD; + if( +#if YY_SHIFT_MIN+YYWILDCARD<0 + j>=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j %s\n", + yyTracePrompt, yyTokenName[iLookAhead], + yyTokenName[YYWILDCARD]); + } +#endif /* NDEBUG */ + return yy_action[j]; } -#endif /* NDEBUG */ - return yy_action[j]; } - } #endif /* YYWILDCARD */ + } + return yy_default[stateno]; + }else{ + return yy_action[i]; } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } + }while(1); } /* @@ -618,6 +623,7 @@ static void yy_reduce( */ %% }; + assert( yyruleno>=0 && yyrulenoyyidx -= yysize; @@ -725,7 +731,9 @@ void Parse( ){ YYMINORTYPE yyminorunion; int yyact; /* The parser action. */ +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ +#endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif @@ -748,7 +756,9 @@ void Parse( yypParser->yystack[0].major = 0; } yyminorunion.yy0 = yyminor; +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); +#endif ParseARG_STORE; #ifndef NDEBUG From 82415f2d8d2ecfe22ad56762ff0f5723ed8da791 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 19:33:42 +0000 Subject: [PATCH 11/55] Change the parser to use the standard "lempar.c" template over in the tool/ folder rather than the customized "lempar.c" found in src/. FossilOrigin-Name: 0a72991f4e54548f6c3268c5a9cac1c8d6437d26 --- Makefile.in | 4 +- Makefile.msc | 4 +- main.mk | 4 +- manifest | 21 +- manifest.uuid | 2 +- src/lempar.c | 892 -------------------------------------------------- src/parse.y | 12 + tool/lempar.c | 190 ++++++----- 8 files changed, 136 insertions(+), 993 deletions(-) delete mode 100644 src/lempar.c diff --git a/Makefile.in b/Makefile.in index 1ad64aa617..eaf021b412 100644 --- a/Makefile.in +++ b/Makefile.in @@ -645,9 +645,9 @@ sqlite3.lo: sqlite3.c # Rules to build the LEMON compiler generator # -lemon$(BEXE): $(TOP)/tool/lemon.c $(TOP)/src/lempar.c +lemon$(BEXE): $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c $(BCC) -o $@ $(TOP)/tool/lemon.c - cp $(TOP)/src/lempar.c . + cp $(TOP)/tool/lempar.c . # Rules to build individual *.o files from generated *.c files. This # applies to: diff --git a/Makefile.msc b/Makefile.msc index 408073c651..57fba11c53 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1310,8 +1310,8 @@ sqlite3.lo: $(SQLITE3C) # Rules to build the LEMON compiler generator # -lempar.c: $(TOP)\src\lempar.c - copy $(TOP)\src\lempar.c . +lempar.c: $(TOP)\tool\lempar.c + copy $(TOP)\tool\lempar.c . lemon.exe: $(TOP)\tool\lemon.c lempar.c $(BCC) $(NO_WARN) -Daccess=_access \ diff --git a/main.mk b/main.mk index 41bcb1c7e4..838e0753d9 100644 --- a/main.mk +++ b/main.mk @@ -554,9 +554,9 @@ fts3amal.c: target_source $(TOP)/ext/fts3/mkfts3amal.tcl # Rules to build the LEMON compiler generator # -lemon: $(TOP)/tool/lemon.c $(TOP)/src/lempar.c +lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c $(BCC) -o lemon $(TOP)/tool/lemon.c - cp $(TOP)/src/lempar.c . + cp $(TOP)/tool/lempar.c . # Rules to build individual *.o files from generated *.c files. This # applies to: diff --git a/manifest b/manifest index de4332e89f..09c98aaddf 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Avoid\srecursion\sin\sthe\syy_find_shift_action()\sroutine\sof\sthe\sLemon-generated\nparser,\sso\sthat\sroutine\scan\sbe\sinlined,\sfor\sa\ssize\sreduction\sand\sperformance\nincrease. -D 2015-11-09T15:06:26.258 -F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb +C Change\sthe\sparser\sto\suse\sthe\sstandard\s"lempar.c"\stemplate\sover\sin\sthe\stool/\nfolder\srather\sthan\sthe\scustomized\s"lempar.c"\sfound\sin\ssrc/. +D 2015-11-09T19:33:42.333 +F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 +F Makefile.msc e928e68168df69b353300ac87c10105206653a03 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 8b9d3ac6f1962f94e06ba05462422a544f9c4e36 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -263,7 +263,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk ac9746f24334056c85775dbe6b7279b84a6941d7 +F main.mk ae99be5eb22933b1ecf80f94d41d25a3ea80aaf3 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -303,7 +303,6 @@ F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/insert.c 419a947f27ce2da18eebf440a5aa80cc825defae F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e -F src/lempar.c 62dbf933df3bd95815a4207925f7e1cf31063443 F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 F src/main.c f393acc6e5d604cbe0054376d62f668a5560b3f1 F src/malloc.c 337bbe9c7d436ef9b7d06b5dd10bbfc8f3025972 @@ -329,7 +328,7 @@ F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c ed5cff11793b6a4146582aabb29ed8613a6cf89e F src/pager.h 7fc069c07f3120ee466ff3d48a9d376974ebffa7 -F src/parse.y 11078cd8e3af00f030505b6a86a06a4536cfdeaa +F src/parse.y 89784cfb2a421e4c2257b3dac86bb79096eaa9b9 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 @@ -1357,7 +1356,7 @@ F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d -F tool/lempar.c 4ff2afb0449e9367f6cb4c8513339e3333852099 +F tool/lempar.c 586bd85c5840a69f7f5f5e1ea23c16a2c6f6d724 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa @@ -1403,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9748c48a4fbd5c06208bbf80e7bfcb159ec026d9 -R c9026e58b8922b5b815b58f78da1a9b7 +P 0557a179f932296cc1fd5217f9a0d2f74e34ce1d +R 35d70dd8e88f4fe91342592b77f63958 U drh -Z 94abf9709b7d536396fc03122fef0eed +Z 3f3cd24eab0db5510bf6fee027109bd0 diff --git a/manifest.uuid b/manifest.uuid index 12c76b678c..78e17aab36 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0557a179f932296cc1fd5217f9a0d2f74e34ce1d \ No newline at end of file +0a72991f4e54548f6c3268c5a9cac1c8d6437d26 \ No newline at end of file diff --git a/src/lempar.c b/src/lempar.c deleted file mode 100644 index beef6cfe49..0000000000 --- a/src/lempar.c +++ /dev/null @@ -1,892 +0,0 @@ -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -** -** This version of "lempar.c" is modified, slightly, for use by SQLite. -** The only modifications are the addition of a couple of NEVER() -** macros to disable tests that are needed in the case of a general -** LALR(1) grammar but which are always false in the -** specific grammar used by SQLite. -*/ -/* First off, code is included that follows the "include" declaration -** in the input grammar file. */ -#include -%% -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* -** These constants (all generated automatically by the parser generator) -** specify the various kinds of tokens (terminals) that the parser -** understands. -** -** Each symbol here is a terminal symbol in the grammar. -*/ -%% -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control -** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. -** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** ParseTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. -** This is typically a union of many types, one of -** which is ParseTOKENTYPE. The entry in the union -** for base tokens is called "yy0". -** YYSTACKDEPTH is the maximum depth of the parser's stack. If -** zero the stack is dynamically sized using realloc() -** ParseARG_SDECL A static variable declaration for the %extra_argument -** ParseARG_PDECL A parameter declaration for the %extra_argument -** ParseARG_STORE Code to store %extra_argument into yypParser -** ParseARG_FETCH Code to extract %extra_argument from yypParser -** YYERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar -** YY_MAX_SHIFT Maximum value for shift actions -** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions -** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions -** YY_MIN_REDUCE Maximum value for reduce actions -** YY_ERROR_ACTION The yy_action[] code for syntax error -** YY_ACCEPT_ACTION The yy_action[] code for accept -** YY_NO_ACTION The yy_action[] code for no-op -*/ -%% - -/* The yyzerominor constant is used to initialize instances of -** YYMINORTYPE objects to zero. */ -static const YYMINORTYPE yyzerominor = { 0 }; - -/* Define the yytestcase() macro to be a no-op if is not already defined -** otherwise. -** -** Applications can choose to define yytestcase() in the %include section -** to a macro that can assist in verifying code coverage. For production -** code the yytestcase() macro should be turned off. But it is useful -** for testing. -*/ -#ifndef yytestcase -# define yytestcase(X) -#endif - - -/* Next are the tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then -** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. -** -** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE -** and YY_MAX_REDUCE - -** N == YY_ERROR_ACTION A syntax error has occurred. -** -** N == YY_ACCEPT_ACTION The parser accepts its input. -** -** N == YY_NO_ACTION No such action. Denotes unused -** slots in the yy_action[] table. -** -** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as -** -** yy_action[ yy_shift_ofst[S] + X ] -** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. -** -** The formula above is for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. -** -** The following are the tables generated in this section: -** -** yy_action[] A single table containing all actions. -** yy_lookahead[] A table containing the lookahead for each entry in -** yy_action. Used to detect hash collisions. -** yy_shift_ofst[] For each state, the offset into yy_action for -** shifting terminals. -** yy_reduce_ofst[] For each state, the offset into yy_action for -** shifting non-terminals after a reduce. -** yy_default[] Default action for each state. -*/ -%% - -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammar, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -*/ -#ifdef YYFALLBACK -static const YYCODETYPE yyFallback[] = { -%% -}; -#endif /* YYFALLBACK */ - -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -** -** After the "shift" half of a SHIFTREDUCE action, the stateno field -** actually contains the reduce action for the second half of the -** SHIFTREDUCE. -*/ -struct yyStackEntry { - YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */ - YYCODETYPE major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct yyStackEntry yyStackEntry; - -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct yyParser { - int yyidx; /* Index of top element in stack */ -#ifdef YYTRACKMAXSTACKDEPTH - int yyidxMax; /* Maximum value of yyidx */ -#endif - int yyerrcnt; /* Shifts left before out of the error */ - ParseARG_SDECL /* A place to hold %extra_argument */ -#if YYSTACKDEPTH<=0 - int yystksz; /* Current side of the stack */ - yyStackEntry *yystack; /* The parser's stack */ -#else - yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ -#endif -}; -typedef struct yyParser yyParser; - -#ifndef NDEBUG -#include -static FILE *yyTraceFILE = 0; -static char *yyTracePrompt = 0; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* -** Turn parser tracing on by giving a stream to which to write the trace -** and a prompt to preface each trace message. Tracing is turned off -** by making either argument NULL -** -** Inputs: -**
    -**
  • A FILE* to which trace output should be written. -** If NULL, then tracing is turned off. -**
  • A prefix string written at the beginning of every -** line of trace output. If NULL, then tracing is -** turned off. -**
-** -** Outputs: -** None. -*/ -void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ - yyTraceFILE = TraceFILE; - yyTracePrompt = zTracePrompt; - if( yyTraceFILE==0 ) yyTracePrompt = 0; - else if( yyTracePrompt==0 ) yyTraceFILE = 0; -} -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *const yyTokenName[] = { -%% -}; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *const yyRuleName[] = { -%% -}; -#endif /* NDEBUG */ - - -#if YYSTACKDEPTH<=0 -/* -** Try to increase the size of the parser stack. -*/ -static void yyGrowStack(yyParser *p){ - int newSize; - yyStackEntry *pNew; - - newSize = p->yystksz*2 + 100; - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); - if( pNew ){ - p->yystack = pNew; - p->yystksz = newSize; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", - yyTracePrompt, p->yystksz); - } -#endif - } -} -#endif - -/* -** This function allocates a new parser. -** The only argument is a pointer to a function which works like -** malloc. -** -** Inputs: -** A pointer to the function used to allocate memory. -** -** Outputs: -** A pointer to a parser. This pointer is used in subsequent calls -** to Parse and ParseFree. -*/ -void *ParseAlloc(void *(*mallocProc)(u64)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (u64)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; -#ifdef YYTRACKMAXSTACKDEPTH - pParser->yyidxMax = 0; -#endif -#if YYSTACKDEPTH<=0 - pParser->yystack = NULL; - pParser->yystksz = 0; - yyGrowStack(pParser); -#endif - } - return pParser; -} - -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. -*/ -static void yy_destructor( - yyParser *yypParser, /* The parser */ - YYCODETYPE yymajor, /* Type code for object to destroy */ - YYMINORTYPE *yypminor /* The object to be destroyed */ -){ - ParseARG_FETCH; - switch( yymajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used - ** inside the C code. - */ -%% - default: break; /* If no destructor action specified: do nothing */ - } -} - -/* -** Pop the parser's stack once. -** -** If there is a destructor routine associated with the token which -** is popped from the stack, then call it. -*/ -static void yy_pop_parser_stack(yyParser *pParser){ - yyStackEntry *yytos; - assert( pParser->yyidx>=0 ); - yytos = &pParser->yystack[pParser->yyidx--]; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sPopping %s\n", - yyTracePrompt, - yyTokenName[yytos->major]); - } -#endif - yy_destructor(pParser, yytos->major, &yytos->minor); -} - -/* -** Deallocate and destroy a parser. Destructors are all called for -** all stack elements before shutting the parser down. -** -** Inputs: -**
    -**
  • A pointer to the parser. This should be a pointer -** obtained from ParseAlloc. -**
  • A pointer to a function used to reclaim memory obtained -** from malloc. -**
-*/ -void ParseFree( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ - yyParser *pParser = (yyParser*)p; - /* In SQLite, we never try to destroy a parser that was not successfully - ** created in the first place. */ - if( NEVER(pParser==0) ) return; - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); -#if YYSTACKDEPTH<=0 - free(pParser->yystack); -#endif - (*freeProc)((void*)pParser); -} - -/* -** Return the peak depth of the stack for a parser. -*/ -#ifdef YYTRACKMAXSTACKDEPTH -int ParseStackPeak(void *p){ - yyParser *pParser = (yyParser*)p; - return pParser->yyidxMax; -} -#endif - -/* -** Find the appropriate action for a parser given the terminal -** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. -*/ -static int yy_find_shift_action( - yyParser *pParser, /* The parser */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->yystack[pParser->yyidx].stateno; - - if( stateno>=YY_MIN_REDUCE ) return stateno; - assert( stateno <= YY_SHIFT_COUNT ); - do{ - i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ -#ifdef YYFALLBACK - YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ - iLookAhead = iFallback; - continue; - } -#endif -#ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( -#if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && -#endif -#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j %s\n", - yyTracePrompt, yyTokenName[iLookAhead], - yyTokenName[YYWILDCARD]); - } -#endif /* NDEBUG */ - return yy_action[j]; - } - } -#endif /* YYWILDCARD */ - } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } - }while(1); -} - -/* -** Find the appropriate action for a parser given the non-terminal -** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. -*/ -static int yy_find_reduce_action( - int stateno, /* Current state number */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; -#ifdef YYERRORSYMBOL - if( stateno>YY_REDUCE_COUNT ){ - return yy_default[stateno]; - } -#else - assert( stateno<=YY_REDUCE_COUNT ); -#endif - i = yy_reduce_ofst[stateno]; - assert( i!=YY_REDUCE_USE_DFLT ); - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; -#ifdef YYERRORSYMBOL - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - return yy_default[stateno]; - } -#else - assert( i>=0 && iyyidx--; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will execute if the parser - ** stack every overflows */ -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ -} - -/* -** Print tracing information for a SHIFT action -*/ -#ifndef NDEBUG -static void yyTraceShift(yyParser *yypParser, int yyNewState){ - if( yyTraceFILE ){ - int i; - if( yyNewStateyyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); - }else{ - fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt); - } - } -} -#else -# define yyTraceShift(X,Y) -#endif - -/* -** Perform a shift action. Return the number of errors. -*/ -static void yy_shift( - yyParser *yypParser, /* The parser to be shifted */ - int yyNewState, /* The new state to shift in */ - int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ -){ - yyStackEntry *yytos; - yypParser->yyidx++; -#ifdef YYTRACKMAXSTACKDEPTH - if( yypParser->yyidx>yypParser->yyidxMax ){ - yypParser->yyidxMax = yypParser->yyidx; - } -#endif -#if YYSTACKDEPTH>0 - if( yypParser->yyidx>=YYSTACKDEPTH ){ - yyStackOverflow(yypParser, yypMinor); - return; - } -#else - if( yypParser->yyidx>=yypParser->yystksz ){ - yyGrowStack(yypParser); - if( yypParser->yyidx>=yypParser->yystksz ){ - yyStackOverflow(yypParser, yypMinor); - return; - } - } -#endif - yytos = &yypParser->yystack[yypParser->yyidx]; - yytos->stateno = (YYACTIONTYPE)yyNewState; - yytos->major = (YYCODETYPE)yyMajor; - yytos->minor = *yypMinor; - yyTraceShift(yypParser, yyNewState); -} - -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ -} yyRuleInfo[] = { -%% -}; - -static void yy_accept(yyParser*); /* Forward Declaration */ - -/* -** Perform a reduce action and the shift that must immediately -** follow the reduce. -*/ -static void yy_reduce( - yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ -){ - int yygoto; /* The next state */ - int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ - yyStackEntry *yymsp; /* The top of the parser's stack */ - int yysize; /* Amount to pop the stack */ - ParseARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; -#ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfo[yyruleno].nrhs; - fprintf(yyTraceFILE, "%sReduce [%s] -> state %d.\n", yyTracePrompt, - yyRuleName[yyruleno], yymsp[-yysize].stateno); - } -#endif /* NDEBUG */ - - /* Silence complaints from purify about yygotominor being uninitialized - ** in some cases when it is copied into the stack after the following - ** switch. yygotominor is uninitialized when a rule reduces that does - ** not set the value of its left-hand side nonterminal. Leaving the - ** value of the nonterminal uninitialized is utterly harmless as long - ** as the value is never used. So really the only thing this code - ** accomplishes is to quieten purify. - ** - ** 2007-01-16: The wireshark project (www.wireshark.org) reports that - ** without this code, their parser segfaults. I'm not sure what there - ** parser is doing to make this happen. This is the second bug report - ** from wireshark this week. Clearly they are stressing Lemon in ways - ** that it has not been previously stressed... (SQLite ticket #2172) - */ - /*memset(&yygotominor, 0, sizeof(yygotominor));*/ - yygotominor = yyzerominor; - - - switch( yyruleno ){ - /* Beginning here are the reduction cases. A typical example - ** follows: - ** case 0: - ** #line - ** { ... } // User supplied code - ** #line - ** break; - */ -%% - }; - assert( yyruleno>=0 && yyrulenoyyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); - if( yyact <= YY_MAX_SHIFTREDUCE ){ - if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - /* If the reduce action popped at least - ** one element off the stack, then we can push the new element back - ** onto the stack here, and skip the stack overflow test in yy_shift(). - ** That gives a significant speed improvement. */ - if( yysize ){ - yypParser->yyidx++; - yymsp -= yysize-1; - yymsp->stateno = (YYACTIONTYPE)yyact; - yymsp->major = (YYCODETYPE)yygoto; - yymsp->minor = yygotominor; - yyTraceShift(yypParser, yyact); - }else{ - yy_shift(yypParser,yyact,yygoto,&yygotominor); - } - }else{ - assert( yyact == YY_ACCEPT_ACTION ); - yy_accept(yypParser); - } -} - -/* -** The following code executes when the parse fails -*/ -#ifndef YYNOERRORRECOVERY -static void yy_parse_failed( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} -#endif /* YYNOERRORRECOVERY */ - -/* -** The following code executes when a syntax error first occurs. -*/ -static void yy_syntax_error( - yyParser *yypParser, /* The parser */ - int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ -){ - ParseARG_FETCH; -#define TOKEN (yyminor.yy0) -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* -** The following is executed when the parser accepts -*/ -static void yy_accept( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ -%% - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "ParseAlloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -void Parse( - void *yyp, /* The parser */ - int yymajor, /* The major token code number */ - ParseTOKENTYPE yyminor /* The value for the token */ - ParseARG_PDECL /* Optional %extra_argument parameter */ -){ - YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ -#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) - int yyendofinput; /* True if we are at the end of input */ -#endif -#ifdef YYERRORSYMBOL - int yyerrorhit = 0; /* True if yymajor has invoked an error */ -#endif - yyParser *yypParser; /* The parser */ - - /* (re)initialize the parser, if necessary */ - yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ -#if YYSTACKDEPTH<=0 - if( yypParser->yystksz <=0 ){ - /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ - yyminorunion = yyzerominor; - yyStackOverflow(yypParser, &yyminorunion); - return; - } -#endif - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; - } - yyminorunion.yy0 = yyminor; -#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) - yyendofinput = (yymajor==0); -#endif - ParseARG_STORE; - -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); - } -#endif - - do{ - yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); - if( yyact <= YY_MAX_SHIFTREDUCE ){ - if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - yy_shift(yypParser,yyact,yymajor,&yyminorunion); - yypParser->yyerrcnt--; - yymajor = YYNOCODE; - }else if( yyact <= YY_MAX_REDUCE ){ - yy_reduce(yypParser,yyact-YY_MIN_REDUCE); - }else{ - assert( yyact == YY_ERROR_ACTION ); -#ifdef YYERRORSYMBOL - int yymx; -#endif -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); - } -#endif -#ifdef YYERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yymx = yypParser->yystack[yypParser->yyidx].major; - if( yymx==YYERRORSYMBOL || yyerrorhit ){ -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sDiscard input token %s\n", - yyTracePrompt,yyTokenName[yymajor]); - } -#endif - yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); - yymajor = YYNOCODE; - }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_reduce_action( - yypParser->yystack[yypParser->yyidx].stateno, - YYERRORSYMBOL)) >= YY_MIN_REDUCE - ){ - yy_pop_parser_stack(yypParser); - } - if( yypParser->yyidx < 0 || yymajor==0 ){ - yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - yy_parse_failed(yypParser); - yymajor = YYNOCODE; - }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); - } - } - yypParser->yyerrcnt = 3; - yyerrorhit = 1; -#elif defined(YYNOERRORRECOVERY) - /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to - ** do any kind of error recovery. Instead, simply invoke the syntax - ** error routine and continue going as if nothing had happened. - ** - ** Applications can set this macro (for example inside %include) if - ** they intend to abandon the parse upon the first syntax error seen. - */ - yy_syntax_error(yypParser,yymajor,yyminorunion); - yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - yymajor = YYNOCODE; - -#else /* YYERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yypParser->yyerrcnt = 3; - yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - if( yyendofinput ){ - yy_parse_failed(yypParser); - } - yymajor = YYNOCODE; -#endif - } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sReturn\n",yyTracePrompt); - } -#endif - return; -} diff --git a/src/parse.y b/src/parse.y index 797fa9bdeb..220df63681 100644 --- a/src/parse.y +++ b/src/parse.y @@ -60,6 +60,18 @@ */ #define yytestcase(X) testcase(X) +/* +** Indicate that sqlite3ParserFree() will never be called with a null +** pointer. +*/ +#define YYPARSEFREENOTNULL 1 + +/* +** Alternative datatype for the argument to the malloc() routine passed +** into sqlite3ParserAlloc(). The default is size_t. +*/ +#define YYMALLOCARGTYPE u64 + /* ** An instance of this structure holds information about the ** LIMIT clause of a SELECT statement. diff --git a/tool/lempar.c b/tool/lempar.c index b7408f60a2..19da6dd371 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -1,49 +1,66 @@ -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -*/ -/* First off, code is included that follows the "include" declaration -** in the input grammar file. */ -#include -%% -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* -** These constants (all generated automatically by the parser generator) -** specify the various kinds of tokens (terminals) that the parser -** understands. +/* +** 2000-05-29 ** -** Each symbol here is a terminal symbol in the grammar. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** Driver template for the LEMON parser generator. +** +** The "lemon" program processes an LALR(1) input grammar file, then uses +** this template to construct a parser. The "lemon" program inserts text +** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the +** interstitial "-" characters) contained in this template is changed into +** the value of the %name directive from the grammar. Otherwise, the content +** of this template is copied straight through into the generate parser +** source file. +** +** The following is the concatenation of all %include directives from the +** input grammar file: */ +#include +/************ Begin %include sections from the grammar ************************/ %% -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control +/**************** End of %include directives **********************************/ +/* These constants specify the various numeric values for terminal symbols +** in a format understandable to "makeheaders". This section is blank unless +** "lemon" is run with the "-m" command-line option. +***************** Begin makeheaders token definitions *************************/ +%% +/**************** End makeheaders token definitions ***************************/ +/* The next sections is a serices of control #defines. ** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. +** YYCODETYPE is the data type used to store the integer codes +** that represent terminal and non-terminal symbols. +** "unsigned char" is used if there are fewer than +** 256 symbols. Larger types otherwise. +** YYNOCODE is a number of type YYCODETYPE that is not used for +** any terminal or nonterminal symbol. ** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** ParseTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. +** (also known as: "terminal symbols") have fall-back +** values which should be used if the original symbol +** would not parse. This permits keywords to sometimes +** be used as identifiers, for example. +** YYACTIONTYPE is the data type used for "action codes" - numbers +** that indicate what to do in response to the next +** token. +** ParseTOKENTYPE is the data type used for minor type for terminal +** symbols. Background: A "minor type" is a semantic +** value associated with a terminal or non-terminal +** symbols. For example, for an "ID" terminal symbol, +** the minor type might be the name of the identifier. +** Each non-terminal can have a different minor type. +** Terminal symbols all have the same minor type, though. +** This macros defines the minor type for terminal +** symbols. +** YYMINORTYPE is the data type used for all minor types. ** This is typically a union of many types, one of ** which is ParseTOKENTYPE. The entry in the union -** for base tokens is called "yy0". +** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If ** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument @@ -62,7 +79,12 @@ ** YY_ACCEPT_ACTION The yy_action[] code for accept ** YY_NO_ACTION The yy_action[] code for no-op */ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/************* Begin control #defines *****************************************/ %% +/************* End control #defines *******************************************/ /* The yyzerominor constant is used to initialize instances of ** YYMINORTYPE objects to zero. */ @@ -131,11 +153,13 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. -*/ +** +*********** Begin parsing tables **********************************************/ %% +/********** End of lemon-generated parsing tables *****************************/ -/* The next table maps tokens into fallback tokens. If a construct -** like the following: +/* The next table maps tokens (terminal symbols) into fallback tokens. +** If a construct like the following: ** ** %fallback ID X Y Z. ** @@ -143,6 +167,10 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser ** but it does not parse, the type of the token is changed to ID and ** the parse is retried before an error is thrown. +** +** This feature can be used, for example, to cause some keywords in a language +** to revert to identifiers if they keyword does not apply in the context where +** it appears. */ #ifdef YYFALLBACK static const YYCODETYPE yyFallback[] = { @@ -265,6 +293,15 @@ static void yyGrowStack(yyParser *p){ } #endif +/* Datatype of the argument to the memory allocated passed as the +** second argument to ParseAlloc() below. This can be changed by +** putting an appropriate #define in the %include section of the input +** grammar. +*/ +#ifndef YYMALLOCARGTYPE +# define YYMALLOCARGTYPE size_t +#endif + /* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like @@ -277,9 +314,9 @@ static void yyGrowStack(yyParser *p){ ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ -void *ParseAlloc(void *(*mallocProc)(size_t)){ +void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); if( pParser ){ pParser->yyidx = -1; #ifdef YYTRACKMAXSTACKDEPTH @@ -294,10 +331,12 @@ void *ParseAlloc(void *(*mallocProc)(size_t)){ return pParser; } -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. +/* The following function deletes the "minor type" or semantic value +** associated with a symbol. The symbol can be either a terminal +** or nonterminal. "yymajor" is the symbol code, and "yypminor" is +** a pointer to the value to be deleted. The code used to do the +** deletions is derived from the %destructor and/or %token_destructor +** directives of the input grammar. */ static void yy_destructor( yyParser *yypParser, /* The parser */ @@ -313,10 +352,12 @@ static void yy_destructor( ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used + ** which appear on the RHS of the rule, but which are *not* used ** inside the C code. */ +/********* Begin destructor definitions ***************************************/ %% +/********* End destructor definitions *****************************************/ default: break; /* If no destructor action specified: do nothing */ } } @@ -342,23 +383,21 @@ static void yy_pop_parser_stack(yyParser *pParser){ } /* -** Deallocate and destroy a parser. Destructors are all called for +** Deallocate and destroy a parser. Destructors are called for ** all stack elements before shutting the parser down. ** -** Inputs: -**
    -**
  • A pointer to the parser. This should be a pointer -** obtained from ParseAlloc. -**
  • A pointer to a function used to reclaim memory obtained -** from malloc. -**
+** If the YYPARSEFREENEVERNULL macro exists (for example because it +** is defined in a %include section of the input grammar) then it is +** assumed that the input pointer is never NULL. */ void ParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ yyParser *pParser = (yyParser*)p; +#ifndef YYPARSEFREENEVERNULL if( pParser==0 ) return; +#endif while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); #if YYSTACKDEPTH<=0 free(pParser->yystack); @@ -379,10 +418,6 @@ int ParseStackPeak(void *p){ /* ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. */ static int yy_find_shift_action( yyParser *pParser, /* The parser */ @@ -449,10 +484,6 @@ static int yy_find_shift_action( /* ** Find the appropriate action for a parser given the non-terminal ** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. */ static int yy_find_reduce_action( int stateno, /* Current state number */ @@ -495,7 +526,9 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ +/******** Begin %stack_overflow code ******************************************/ %% +/******** End %stack_overflow code ********************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ } @@ -522,7 +555,7 @@ static void yyTraceShift(yyParser *yypParser, int yyNewState){ #endif /* -** Perform a shift action. Return the number of errors. +** Perform a shift action. */ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ @@ -593,25 +626,8 @@ static void yy_reduce( yyRuleName[yyruleno], yymsp[-yysize].stateno); } #endif /* NDEBUG */ - - /* Silence complaints from purify about yygotominor being uninitialized - ** in some cases when it is copied into the stack after the following - ** switch. yygotominor is uninitialized when a rule reduces that does - ** not set the value of its left-hand side nonterminal. Leaving the - ** value of the nonterminal uninitialized is utterly harmless as long - ** as the value is never used. So really the only thing this code - ** accomplishes is to quieten purify. - ** - ** 2007-01-16: The wireshark project (www.wireshark.org) reports that - ** without this code, their parser segfaults. I'm not sure what there - ** parser is doing to make this happen. This is the second bug report - ** from wireshark this week. Clearly they are stressing Lemon in ways - ** that it has not been previously stressed... (SQLite ticket #2172) - */ - /*memset(&yygotominor, 0, sizeof(yygotominor));*/ yygotominor = yyzerominor; - switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example ** follows: @@ -621,7 +637,9 @@ static void yy_reduce( ** #line ** break; */ +/********** Begin reduce actions **********************************************/ %% +/********** End reduce actions ************************************************/ }; assert( yyruleno>=0 && yyrulenoyyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ +/************ Begin %parse_failure code ***************************************/ %% +/************ End %parse_failure code *****************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } #endif /* YYNOERRORRECOVERY */ @@ -681,7 +701,9 @@ static void yy_syntax_error( ){ ParseARG_FETCH; #define TOKEN (yyminor.yy0) +/************ Begin %syntax_error code ****************************************/ %% +/************ End %syntax_error code ******************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -700,7 +722,9 @@ static void yy_accept( while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser accepts */ +/*********** Begin %parse_accept code *****************************************/ %% +/*********** End %parse_accept code *******************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } From 822a62f84daff89539eec5d7b979380e91046424 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Nov 2015 19:35:18 +0000 Subject: [PATCH 12/55] Fix a comment typo in the lempar.c template that was missed by the prior check-in. FossilOrigin-Name: c4a7e93fca622fd11a6e16161fbd2f39c2575f00 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lempar.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 09c98aaddf..898e6a7736 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sparser\sto\suse\sthe\sstandard\s"lempar.c"\stemplate\sover\sin\sthe\stool/\nfolder\srather\sthan\sthe\scustomized\s"lempar.c"\sfound\sin\ssrc/. -D 2015-11-09T19:33:42.333 +C Fix\sa\scomment\stypo\sin\sthe\slempar.c\stemplate\sthat\swas\smissed\sby\sthe\sprior\ncheck-in. +D 2015-11-09T19:35:18.284 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -1356,7 +1356,7 @@ F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d -F tool/lempar.c 586bd85c5840a69f7f5f5e1ea23c16a2c6f6d724 +F tool/lempar.c 02cd882bd3144a5e25c86c652af49a6bc07baeae F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0557a179f932296cc1fd5217f9a0d2f74e34ce1d -R 35d70dd8e88f4fe91342592b77f63958 +P 0a72991f4e54548f6c3268c5a9cac1c8d6437d26 +R 8fab66a5e8d9eb9e711e67490ab1fb25 U drh -Z 3f3cd24eab0db5510bf6fee027109bd0 +Z b603d5d9eb956db724fe6f00475658c3 diff --git a/manifest.uuid b/manifest.uuid index 78e17aab36..58748396f4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a72991f4e54548f6c3268c5a9cac1c8d6437d26 \ No newline at end of file +c4a7e93fca622fd11a6e16161fbd2f39c2575f00 \ No newline at end of file diff --git a/tool/lempar.c b/tool/lempar.c index 19da6dd371..1229646494 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -32,7 +32,8 @@ ***************** Begin makeheaders token definitions *************************/ %% /**************** End makeheaders token definitions ***************************/ -/* The next sections is a serices of control #defines. + +/* The next sections is a series of control #defines. ** various aspects of the generated parser. ** YYCODETYPE is the data type used to store the integer codes ** that represent terminal and non-terminal symbols. From 07b09a942059b4330464a7003602700c75360c17 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Nov 2015 00:02:49 +0000 Subject: [PATCH 13/55] Remove an unused non-terminal from the grammar. FossilOrigin-Name: 3c37c522883ea9f2eec4f0ba5c5141912c003425 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/parse.y | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 898e6a7736..a06ddf0f84 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scomment\stypo\sin\sthe\slempar.c\stemplate\sthat\swas\smissed\sby\sthe\sprior\ncheck-in. -D 2015-11-09T19:35:18.284 +C Remove\san\sunused\snon-terminal\sfrom\sthe\sgrammar. +D 2015-11-10T00:02:49.412 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -328,7 +328,7 @@ F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c ed5cff11793b6a4146582aabb29ed8613a6cf89e F src/pager.h 7fc069c07f3120ee466ff3d48a9d376974ebffa7 -F src/parse.y 89784cfb2a421e4c2257b3dac86bb79096eaa9b9 +F src/parse.y 56cd095d669ad7cf50599a39525277f37f8148f9 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0a72991f4e54548f6c3268c5a9cac1c8d6437d26 -R 8fab66a5e8d9eb9e711e67490ab1fb25 +P c4a7e93fca622fd11a6e16161fbd2f39c2575f00 +R 718dc1350ed033f1faf4636e4683af75 U drh -Z b603d5d9eb956db724fe6f00475658c3 +Z ed4dab40ca0663dda7ca06a05db43ba5 diff --git a/manifest.uuid b/manifest.uuid index 58748396f4..7b89cfcfaa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c4a7e93fca622fd11a6e16161fbd2f39c2575f00 \ No newline at end of file +3c37c522883ea9f2eec4f0ba5c5141912c003425 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 220df63681..842bf306e0 100644 --- a/src/parse.y +++ b/src/parse.y @@ -651,7 +651,6 @@ dbnm(A) ::= DOT nm(X). {A = X;} fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y);} %type joinop {int} -%type joinop2 {int} joinop(X) ::= COMMA|JOIN. { X = JT_INNER; } joinop(X) ::= JOIN_KW(A) JOIN. { X = sqlite3JoinType(pParse,&A,0,0); } joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqlite3JoinType(pParse,&A,&B,0); } From 54bb56d82a04cb05b53af5475c2052a44756e879 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Nov 2015 03:30:51 +0000 Subject: [PATCH 14/55] Performance enhancement to the tokenizer. FossilOrigin-Name: 6ea2df86c95c226052f528424e9bee367a2e765a --- manifest | 14 +++++------ manifest.uuid | 2 +- src/tokenize.c | 4 ++-- tool/mkkeywordhash.c | 56 ++++++++++++++++---------------------------- 4 files changed, 30 insertions(+), 46 deletions(-) diff --git a/manifest b/manifest index a06ddf0f84..bef5b126ef 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunused\snon-terminal\sfrom\sthe\sgrammar. -D 2015-11-10T00:02:49.412 +C Performance\senhancement\sto\sthe\stokenizer. +D 2015-11-10T03:30:51.926 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -395,7 +395,7 @@ F src/test_vfs.c 3b65d42e18b262805716bd96178c81da8f2d9283 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 -F src/tokenize.c c1006aa773da5725ef55e8d48f69c11d7141d011 +F src/tokenize.c 5606871a377f390af7040ec3c12e0d183512d785 F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f F src/update.c 40e51cd0883cb5bfd6abb7d8a7cd8aa47fab2945 @@ -1360,7 +1360,7 @@ F tool/lempar.c 02cd882bd3144a5e25c86c652af49a6bc07baeae F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa -F tool/mkkeywordhash.c dfff09dbbfaf950e89af294f48f902181b144670 +F tool/mkkeywordhash.c 37f9c2e62c31384b697ede8825e2d344e98db22c F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c4a7e93fca622fd11a6e16161fbd2f39c2575f00 -R 718dc1350ed033f1faf4636e4683af75 +P 3c37c522883ea9f2eec4f0ba5c5141912c003425 +R 40750d96ad92c103526c6bd35096918c U drh -Z ed4dab40ca0663dda7ca06a05db43ba5 +Z 8ead9b7802f9e64a677105e8e10b5cbd diff --git a/manifest.uuid b/manifest.uuid index 7b89cfcfaa..be66b8946e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3c37c522883ea9f2eec4f0ba5c5141912c003425 \ No newline at end of file +6ea2df86c95c226052f528424e9bee367a2e765a \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 81b98d593a..b85e35dc10 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -369,8 +369,8 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ break; } for(i=1; IdChar(z[i]); i++){} - *tokenType = keywordCode((char*)z, i); - return i; + *tokenType = TK_ID; + return keywordCode((char*)z, i, tokenType); } } *tokenType = TK_ILLEGAL; diff --git a/tool/mkkeywordhash.c b/tool/mkkeywordhash.c index 721611f5a3..e4d393e3fa 100644 --- a/tool/mkkeywordhash.c +++ b/tool/mkkeywordhash.c @@ -277,27 +277,8 @@ static Keyword aKeywordTable[] = { /* Number of keywords */ static int nKeyword = (sizeof(aKeywordTable)/sizeof(aKeywordTable[0])); -/* An array to map all upper-case characters into their corresponding -** lower-case character. -*/ -const unsigned char sqlite3UpperToLower[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, - 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103, - 104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121, - 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107, - 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125, - 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161, - 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179, - 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197, - 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215, - 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233, - 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251, - 252,253,254,255 -}; -#define UpperToLower sqlite3UpperToLower +/* Map all alphabetic characters into the same case */ +#define charMap(X) (0x20|(X)) /* ** Comparision function for two Keyword records @@ -347,7 +328,7 @@ static Keyword *findById(int id){ ** output. */ int main(int argc, char **argv){ - int i, j, k, h; + int i, j, k, h, m; int bestSize, bestCount; int count; int nChar; @@ -372,8 +353,8 @@ int main(int argc, char **argv){ assert( p->lenzOrigName) ); memcpy(p->zOrigName, p->zName, p->len+1); totalLen += p->len; - p->hash = (UpperToLower[(int)p->zName[0]]*4) ^ - (UpperToLower[(int)p->zName[p->len-1]]*3) ^ p->len; + p->hash = (charMap(p->zName[0])*4) ^ + (charMap(p->zName[p->len-1])*3) ^ (p->len*1); p->id = i+1; } @@ -481,7 +462,7 @@ int main(int argc, char **argv){ /* Begin generating code */ printf("%s", zHdr); printf("/* Hash score: %d */\n", bestCount); - printf("static int keywordCode(const char *z, int n){\n"); + printf("static int keywordCode(const char *z, int n, int *pType){\n"); printf(" /* zText[] encodes %d bytes of keywords in %d bytes */\n", totalLen + nKeyword, nChar+1 ); for(i=j=k=0; i=0; i=((int)aNext[i])-1){\n"); - printf(" if( aLen[i]==n &&" - " sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){\n"); + printf(" if( n>=2 ){\n"); + printf(" h = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n", + bestSize); + printf(" for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){\n"); + printf(" if( aLen[i]==n &&" + " sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){\n"); for(i=0; i Date: Tue, 10 Nov 2015 12:31:25 +0000 Subject: [PATCH 15/55] Fix harmless compiler warnings in FTS5. FossilOrigin-Name: 09752e51a18ac1b4c9642965e6ee1b6a32de00df --- ext/fts5/fts5_main.c | 1 - ext/fts5/fts5parse.y | 16 ++++++++++++---- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index ee5adc4b98..9390cb6cb2 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -874,7 +874,6 @@ static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){ int nPhrase; int nByte; int rc = SQLITE_OK; - char *zSql; const char *zRank = pCsr->zRank; const char *zRankArgs = pCsr->zRankArgs; diff --git a/ext/fts5/fts5parse.y b/ext/fts5/fts5parse.y index 065af77053..0e81771b4f 100644 --- a/ext/fts5/fts5parse.y +++ b/ext/fts5/fts5parse.y @@ -58,6 +58,18 @@ */ #define yytestcase(X) testcase(X) +/* +** Indicate that sqlite3ParserFree() will never be called with a null +** pointer. +*/ +#define YYPARSEFREENOTNULL 1 + +/* +** Alternative datatype for the argument to the malloc() routine passed +** into sqlite3ParserAlloc(). The default is size_t. +*/ +#define YYMALLOCARGTYPE u64 + } // end %include %left OR. @@ -168,7 +180,3 @@ phrase(A) ::= STRING(Y) star_opt(Z). { star_opt(A) ::= STAR. { A = 1; } star_opt(A) ::= . { A = 0; } - - - - diff --git a/manifest b/manifest index bef5b126ef..f9984ba6ea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancement\sto\sthe\stokenizer. -D 2015-11-10T03:30:51.926 +C Fix\sharmless\scompiler\swarnings\sin\sFTS5. +D 2015-11-10T12:31:25.172 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -110,7 +110,7 @@ F ext/fts5/fts5_config.c 6fc92c0b1bda5244c28a54c9ba740736bd5513d9 F ext/fts5/fts5_expr.c 28b15c9ae296204bc0a2e5cf7a667d840a9d2900 F ext/fts5/fts5_hash.c a9d4c1efebc2a91d26ad7ebdfcbf2678ceac405f F ext/fts5/fts5_index.c b622a0a70f57a96469e6828da2dd70e0872aeb37 -F ext/fts5/fts5_main.c 0569cd9fc18f3b56f6eeac601836df8ed5fb54cb +F ext/fts5/fts5_main.c 7581280ee242785477df67402f2853c66f77d45b F ext/fts5/fts5_storage.c 9ea3d92178743758b6c54d9fe8836bbbdcc92e3b F ext/fts5/fts5_tcl.c 3bf445e66de32137d4693694ff7b1fd6074e32bd F ext/fts5/fts5_test_mi.c e96be827aa8f571031e65e481251dc1981d608bf @@ -118,7 +118,7 @@ F ext/fts5/fts5_tokenize.c 12c5d925286491a71bb3dad7c8924ce9cfd18320 F ext/fts5/fts5_unicode2.c 78273fbd588d1d9bd0a7e4e0ccc9207348bae33c F ext/fts5/fts5_varint.c 3f86ce09cab152e3d45490d7586b7ed2e40c13f1 F ext/fts5/fts5_vocab.c 3742d0abfe8aa8c3cb4a7df56aa38f2e3c3fb1c2 -F ext/fts5/fts5parse.y e83dca6028e3309178d05b5bd920e372dc295d35 +F ext/fts5/fts5parse.y 1647eba089b9b3fc058b4dc989d9da87d15b9580 F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba F ext/fts5/test/fts5_common.tcl 51f7ef3af444b89c6f6ce3896a0ac349ff4e996d F ext/fts5/test/fts5aa.test 2c553eea4dab4bc5a75928f56729277c7bc1d206 @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3c37c522883ea9f2eec4f0ba5c5141912c003425 -R 40750d96ad92c103526c6bd35096918c +P 6ea2df86c95c226052f528424e9bee367a2e765a +R c4fc880f1c9308c0365b7757399767dc U drh -Z 8ead9b7802f9e64a677105e8e10b5cbd +Z 622f282d2cf652046e0082888bbfa948 diff --git a/manifest.uuid b/manifest.uuid index be66b8946e..d47f9624b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6ea2df86c95c226052f528424e9bee367a2e765a \ No newline at end of file +09752e51a18ac1b4c9642965e6ee1b6a32de00df \ No newline at end of file From 3334d08989e24ebde4e39d5bf1d775b10960024a Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Nov 2015 13:45:21 +0000 Subject: [PATCH 16/55] Save a few bytes in the parser by using "int" instead of "u8" or "u16" for all small integer types. FossilOrigin-Name: 5dcd212bf6489f4698a0ed0f21497c78379f7c0f --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/parse.y | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index b09b4ed00f..cc368e18c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sall\sparsers\sto\suse\sthe\sstandard\s"lempar.c"\stemplate\sin\sthe\stool/\nfolder\sand\sremove\sthe\scustomized\slempar.c\sfrom\ssrc/,\splus\sother\scompiler\nperformance\sand\sspace\senhancements. -D 2015-11-10T12:41:03.723 +C Save\sa\sfew\sbytes\sin\sthe\sparser\sby\susing\s"int"\sinstead\sof\s"u8"\sor\s"u16"\sfor\nall\ssmall\sinteger\stypes. +D 2015-11-10T13:45:21.998 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -328,7 +328,7 @@ F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c ed5cff11793b6a4146582aabb29ed8613a6cf89e F src/pager.h 7fc069c07f3120ee466ff3d48a9d376974ebffa7 -F src/parse.y 56cd095d669ad7cf50599a39525277f37f8148f9 +F src/parse.y 8a364a7a692e517dea8711b3c7f0d07fe32727d8 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 @@ -1402,8 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0557a179f932296cc1fd5217f9a0d2f74e34ce1d 09752e51a18ac1b4c9642965e6ee1b6a32de00df -R c4fc880f1c9308c0365b7757399767dc -T +closed 09752e51a18ac1b4c9642965e6ee1b6a32de00df +P 0e7fb24ad3c010884763a97e6ae7a3fd39d0e5a9 +R e95251a17c80e6e8bd0fe3b50f525483 U drh -Z 094c96712972b6d193fe37091ddcf067 +Z 63fd373db42b2e308a08a76dcf855a61 diff --git a/manifest.uuid b/manifest.uuid index 07d0e55fcb..9eec6dca49 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0e7fb24ad3c010884763a97e6ae7a3fd39d0e5a9 \ No newline at end of file +5dcd212bf6489f4698a0ed0f21497c78379f7c0f \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 842bf306e0..64f234ca7c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -174,7 +174,7 @@ create_table_args ::= AS select(S). { sqlite3EndTable(pParse,0,0,0,S); sqlite3SelectDelete(pParse->db, S); } -%type table_options {u8} +%type table_options {int} table_options(A) ::= . {A = 0;} table_options(A) ::= WITHOUT nm(X). { if( X.n==5 && sqlite3_strnicmp(X.z,"rowid",5)==0 ){ @@ -376,12 +376,12 @@ defer_subclause_opt(A) ::= defer_subclause(X). {A = X;} // default behavior when there is a constraint conflict. // %type onconf {int} -%type orconf {u8} +%type orconf {int} %type resolvetype {int} onconf(A) ::= . {A = OE_Default;} onconf(A) ::= ON CONFLICT resolvetype(X). {A = X;} orconf(A) ::= . {A = OE_Default;} -orconf(A) ::= OR resolvetype(X). {A = (u8)X;} +orconf(A) ::= OR resolvetype(X). {A = X;} resolvetype(A) ::= raisetype(X). {A = X;} resolvetype(A) ::= IGNORE. {A = OE_Ignore;} resolvetype(A) ::= REPLACE. {A = OE_Replace;} @@ -538,7 +538,7 @@ values(A) ::= values(X) COMMA LP exprlist(Y) RP. { // The "distinct" nonterminal is true (1) if the DISTINCT keyword is // present and false (0) if it is not. // -%type distinct {u16} +%type distinct {int} distinct(A) ::= DISTINCT. {A = SF_Distinct;} distinct(A) ::= ALL. {A = SF_All;} distinct(A) ::= . {A = 0;} @@ -811,7 +811,7 @@ cmd ::= with(W) insert_cmd(R) INTO fullname(X) idlist_opt(F) DEFAULT VALUES. sqlite3Insert(pParse, X, 0, F, R); } -%type insert_cmd {u8} +%type insert_cmd {int} insert_cmd(A) ::= INSERT orconf(R). {A = R;} insert_cmd(A) ::= REPLACE. {A = OE_Replace;} From 97e58a2feb32da44234eb24b343ffc968acdccd2 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Nov 2015 14:27:17 +0000 Subject: [PATCH 17/55] Make the output of "PRAGMA parser_trace" go to stdout instead of stderr. FossilOrigin-Name: 1e4849911e3eed65eabee18fdee63bab4faae57a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index cc368e18c4..4e26b0e80e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Save\sa\sfew\sbytes\sin\sthe\sparser\sby\susing\s"int"\sinstead\sof\s"u8"\sor\s"u16"\sfor\nall\ssmall\sinteger\stypes. -D 2015-11-10T13:45:21.998 +C Make\sthe\soutput\sof\s"PRAGMA\sparser_trace"\sgo\sto\sstdout\sinstead\sof\sstderr. +D 2015-11-10T14:27:17.622 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -332,7 +332,7 @@ F src/parse.y 8a364a7a692e517dea8711b3c7f0d07fe32727d8 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 -F src/pragma.c 8fd4c8a12e25f0d916426f160255ebe25415eba7 +F src/pragma.c 9dbb9ba2453d79bfc5905be0398aa30342b066bb F src/pragma.h 631a91c8b0e6ca8f051a1d8a4a0da4150e04620a F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0e7fb24ad3c010884763a97e6ae7a3fd39d0e5a9 -R e95251a17c80e6e8bd0fe3b50f525483 +P 5dcd212bf6489f4698a0ed0f21497c78379f7c0f +R d246e800f7bbd35b4c91162f9a5cfe01 U drh -Z 63fd373db42b2e308a08a76dcf855a61 +Z 7a87ce17e8bd737f41d12f3fe2d64903 diff --git a/manifest.uuid b/manifest.uuid index 9eec6dca49..63c210a12f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5dcd212bf6489f4698a0ed0f21497c78379f7c0f \ No newline at end of file +1e4849911e3eed65eabee18fdee63bab4faae57a \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 14c4811746..a0e394f782 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1324,7 +1324,7 @@ void sqlite3Pragma( case PragTyp_PARSER_TRACE: { if( zRight ){ if( sqlite3GetBoolean(zRight, 0) ){ - sqlite3ParserTrace(stderr, "parser: "); + sqlite3ParserTrace(stdout, "parser: "); }else{ sqlite3ParserTrace(0, 0); } From 0c4105ee1930c56b0b1fce4fa7a27c13f838086d Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 10 Nov 2015 14:51:22 +0000 Subject: [PATCH 18/55] Improved output formatting for "PRAGMA parser_trace=ON;". FossilOrigin-Name: e43e1171fd7837a08069dc25df4eac14db1c2afe --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/lempar.c | 29 +++++++++++++++++++---------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 4e26b0e80e..cae104ad32 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\soutput\sof\s"PRAGMA\sparser_trace"\sgo\sto\sstdout\sinstead\sof\sstderr. -D 2015-11-10T14:27:17.622 +C Improved\soutput\sformatting\sfor\s"PRAGMA\sparser_trace=ON;". +D 2015-11-10T14:51:22.311 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -1356,7 +1356,7 @@ F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c 799e73e19a33b8dd7767a7fa34618ed2a9c2397d -F tool/lempar.c 02cd882bd3144a5e25c86c652af49a6bc07baeae +F tool/lempar.c 3ec1463a034b37d87d782be5f6b8b10a3b1ecbe7 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5dcd212bf6489f4698a0ed0f21497c78379f7c0f -R d246e800f7bbd35b4c91162f9a5cfe01 +P 1e4849911e3eed65eabee18fdee63bab4faae57a +R 09ae4147f1c84fb513e1a92470f43128 U drh -Z 7a87ce17e8bd737f41d12f3fe2d64903 +Z 86e43e17960e74008de165832cc2a68a diff --git a/manifest.uuid b/manifest.uuid index 63c210a12f..cd04978930 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e4849911e3eed65eabee18fdee63bab4faae57a \ No newline at end of file +e43e1171fd7837a08069dc25df4eac14db1c2afe \ No newline at end of file diff --git a/tool/lempar.c b/tool/lempar.c index 1229646494..312507e5f1 100644 --- a/tool/lempar.c +++ b/tool/lempar.c @@ -539,15 +539,13 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ #ifndef NDEBUG static void yyTraceShift(yyParser *yypParser, int yyNewState){ if( yyTraceFILE ){ - int i; if( yyNewStateyyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); + fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n", + yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major], + yyNewState); }else{ - fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt); + fprintf(yyTraceFILE,"%sShift '%s'\n", + yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]); } } } @@ -623,7 +621,7 @@ static void yy_reduce( if( yyTraceFILE && yyruleno>=0 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ yysize = yyRuleInfo[yyruleno].nrhs; - fprintf(yyTraceFILE, "%sReduce [%s] -> state %d.\n", yyTracePrompt, + fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, yyRuleName[yyruleno], yymsp[-yysize].stateno); } #endif /* NDEBUG */ @@ -779,6 +777,12 @@ void Parse( yypParser->yyerrcnt = -1; yypParser->yystack[0].stateno = 0; yypParser->yystack[0].major = 0; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n", + yyTracePrompt); + } +#endif } yyminorunion.yy0 = yyminor; #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) @@ -788,7 +792,7 @@ void Parse( #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); } #endif @@ -902,7 +906,12 @@ void Parse( }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sReturn\n",yyTracePrompt); + int i; + fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); + for(i=1; i<=yypParser->yyidx; i++) + fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ', + yyTokenName[yypParser->yystack[i].major]); + fprintf(yyTraceFILE,"]\n"); } #endif return; From 3d38cec99a5e635b2a69ca0ca8adfdeb99b96006 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 11 Nov 2015 15:28:52 +0000 Subject: [PATCH 19/55] Improvements to the SQLITE_CONFIG_PAGECACHE documentation. Enhance the command-line shell to be able to take advantage of the full range of SQLITE_CONFIG_PAGECACHE capabilities, such as setting pMem==NULL and N<0. FossilOrigin-Name: 2518d5c971c4b32d9227b3bb7259162e3e27b00b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 6 +++--- src/sqlite.h.in | 37 +++++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index cae104ad32..5e942ee5cf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\soutput\sformatting\sfor\s"PRAGMA\sparser_trace=ON;". -D 2015-11-10T14:51:22.311 +C Improvements\sto\sthe\sSQLITE_CONFIG_PAGECACHE\sdocumentation.\s\sEnhance\sthe\ncommand-line\sshell\sto\sbe\sable\sto\stake\sadvantage\sof\sthe\sfull\srange\sof\nSQLITE_CONFIG_PAGECACHE\scapabilities,\ssuch\sas\ssetting\spMem==NULL\sand\sN<0. +D 2015-11-11T15:28:52.898 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -340,8 +340,8 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 00a2a10d4298a685d0eeb05b09ef018a2bd81bf8 -F src/shell.c d25df04168d6ba5a4fa05bdbf859df667f9eb621 -F src/sqlite.h.in 3cfc86c55e57c63d86b9e1e92869e2bfb162ca8e +F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 +F src/sqlite.h.in 278df052181b0e5b0bcdb2089ff09596ae9eca15 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 F src/sqliteInt.h bc6d24460fe544323517630b1e20539146379077 @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1e4849911e3eed65eabee18fdee63bab4faae57a -R 09ae4147f1c84fb513e1a92470f43128 +P e43e1171fd7837a08069dc25df4eac14db1c2afe +R 9a1d72f8baac116c36385e92e48c0378 U drh -Z 86e43e17960e74008de165832cc2a68a +Z 9d52ec874b9a01b7b0eb1dab69dbb993 diff --git a/manifest.uuid b/manifest.uuid index cd04978930..bf01d0ad61 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e43e1171fd7837a08069dc25df4eac14db1c2afe \ No newline at end of file +2518d5c971c4b32d9227b3bb7259162e3e27b00b \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index f79087122c..7c53995799 100644 --- a/src/shell.c +++ b/src/shell.c @@ -4601,10 +4601,10 @@ int SQLITE_CDECL main(int argc, char **argv){ int n, sz; sz = (int)integerValue(cmdline_option_value(argc,argv,++i)); if( sz>70000 ) sz = 70000; - if( sz<800 ) sz = 800; + if( sz<0 ) sz = 0; n = (int)integerValue(cmdline_option_value(argc,argv,++i)); - if( n<10 ) n = 10; - sqlite3_config(SQLITE_CONFIG_PAGECACHE, malloc(n*sz+1), sz, n); + sqlite3_config(SQLITE_CONFIG_PAGECACHE, + (n>0 && sz>0) ? malloc(n*sz) : 0, sz, n); data.shellFlgs |= SHFLG_Pagecache; }else if( strcmp(z,"-lookaside")==0 ){ int n, sz; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 961c5169fc..9280343507 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1599,29 +1599,34 @@ struct sqlite3_mem_methods { ** ** ** [[SQLITE_CONFIG_PAGECACHE]]
SQLITE_CONFIG_PAGECACHE
-**
^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer +**
^The SQLITE_CONFIG_PAGECACHE option a memory pool ** that SQLite can use for the database page cache with the default page ** cache implementation. -** This configuration should not be used if an application-define page -** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2] -** configuration option. +** This configuration option is a no-op if an application-define page +** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to -** 8-byte aligned -** memory, the size of each page buffer (sz), and the number of pages (N). +** 8-byte aligned memory (pMem), the size of each page cache line (sz), +** and the number of cache lines (N). ** The sz argument should be the size of the largest database page ** (a power of two between 512 and 65536) plus some extra bytes for each ** page header. ^The number of extra bytes needed by the page header -** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option -** to [sqlite3_config()]. +** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. ** ^It is harmless, apart from the wasted memory, -** for the sz parameter to be larger than necessary. The first -** argument should pointer to an 8-byte aligned block of memory that -** is at least sz*N bytes of memory, otherwise subsequent behavior is -** undefined. -** ^SQLite will use the memory provided by the first argument to satisfy its -** memory needs for the first N pages that it adds to cache. ^If additional -** page cache memory is needed beyond what is provided by this option, then -** SQLite goes to [sqlite3_malloc()] for the additional storage space.
+** for the sz parameter to be larger than necessary. The pMem +** argument must be either a NULL pointer or a pointer to an 8-byte +** aligned block of memory of at least sz*N bytes, otherwise +** subsequent behavior is undefined. +** ^When pMem is not NULL, SQLite will strive to use the memory provided +** to satisfy page cache needs, falling back to [sqlite3_malloc()] if +** a page cache line is larger than sz bytes or if all of the pMem buffer +** is exhausted. +** ^If pMem is NULL and N is non-zero, then each database connection +** does an initial bulk allocation for page cache memory +** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or +** of -1024*N bytes if N is negative, . ^If additional +** page cache memory is needed beyond what is provided by the initial +** allocation, then SQLite goes to [sqlite3_malloc()] separately for each +** additional cache line. ** ** [[SQLITE_CONFIG_HEAP]]
SQLITE_CONFIG_HEAP
**
^The SQLITE_CONFIG_HEAP option specifies a static memory buffer From 24e9895f81c103fb3aaaf07fe75260e2ec7de146 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 11 Nov 2015 18:43:49 +0000 Subject: [PATCH 20/55] Fix missing word in a documentation comment. No changes to code. FossilOrigin-Name: ed24d302657e8495bef7f5ed698c7cca12717be9 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 5e942ee5cf..21a3de1f3f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\sSQLITE_CONFIG_PAGECACHE\sdocumentation.\s\sEnhance\sthe\ncommand-line\sshell\sto\sbe\sable\sto\stake\sadvantage\sof\sthe\sfull\srange\sof\nSQLITE_CONFIG_PAGECACHE\scapabilities,\ssuch\sas\ssetting\spMem==NULL\sand\sN<0. -D 2015-11-11T15:28:52.898 +C Fix\smissing\sword\sin\sa\sdocumentation\scomment.\s\sNo\schanges\sto\scode. +D 2015-11-11T18:43:49.517 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -341,7 +341,7 @@ F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 00a2a10d4298a685d0eeb05b09ef018a2bd81bf8 F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 -F src/sqlite.h.in 278df052181b0e5b0bcdb2089ff09596ae9eca15 +F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 F src/sqliteInt.h bc6d24460fe544323517630b1e20539146379077 @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e43e1171fd7837a08069dc25df4eac14db1c2afe -R 9a1d72f8baac116c36385e92e48c0378 -U drh -Z 9d52ec874b9a01b7b0eb1dab69dbb993 +P 2518d5c971c4b32d9227b3bb7259162e3e27b00b +R 3dc308897daa57a7c4272c874c792ced +U mistachkin +Z 5a3c62c2da73a7a92ccd94cbe3857768 diff --git a/manifest.uuid b/manifest.uuid index bf01d0ad61..5f07e1aae7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2518d5c971c4b32d9227b3bb7259162e3e27b00b \ No newline at end of file +ed24d302657e8495bef7f5ed698c7cca12717be9 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9280343507..13c97d8d4a 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1599,7 +1599,7 @@ struct sqlite3_mem_methods { **
** ** [[SQLITE_CONFIG_PAGECACHE]]
SQLITE_CONFIG_PAGECACHE
-**
^The SQLITE_CONFIG_PAGECACHE option a memory pool +**
^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool ** that SQLite can use for the database page cache with the default page ** cache implementation. ** This configuration option is a no-op if an application-define page From 9b0cf34f813b7d542f593b59e6466f94d7cc11e2 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Nov 2015 14:57:19 +0000 Subject: [PATCH 21/55] First attempt at enhancing the "PRAGMA cache_spill" statement to accept a cache threashold size. FossilOrigin-Name: 549d42be0dac87dc04c3eeccfdc60615c3a6ad3f --- manifest | 33 ++++++------ manifest.uuid | 2 +- src/btree.c | 38 +++++++++----- src/btree.h | 1 + src/pager.c | 11 +++- src/pager.h | 1 + src/pcache.c | 72 ++++++++++++++++---------- src/pcache.h | 7 +++ src/pragma.c | 117 +++++++++++++++++++++++++++++-------------- src/pragma.h | 79 ++++++++++++++--------------- test/pragma2.test | 34 ++++++++++--- tool/mkpragmatab.tcl | 2 - 12 files changed, 257 insertions(+), 140 deletions(-) diff --git a/manifest b/manifest index 5e942ee5cf..d7ec4d4e08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\sSQLITE_CONFIG_PAGECACHE\sdocumentation.\s\sEnhance\sthe\ncommand-line\sshell\sto\sbe\sable\sto\stake\sadvantage\sof\sthe\sfull\srange\sof\nSQLITE_CONFIG_PAGECACHE\scapabilities,\ssuch\sas\ssetting\spMem==NULL\sand\sN<0. -D 2015-11-11T15:28:52.898 +C First\sattempt\sat\senhancing\sthe\s"PRAGMA\scache_spill"\sstatement\sto\saccept\sa\ncache\sthreashold\ssize. +D 2015-11-12T14:57:19.268 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -282,8 +282,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc F src/bitvec.c d1f21d7d91690747881f03940584f4cc548c9d3d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 9e5d713bf54be8bfcae9b60210173dd53570f56d -F src/btree.h 1b8bf2818b5e256c25a5e09126720113b1d783da +F src/btree.c d3bdd8462a86492e2ebc9aca4a0168429017de25 +F src/btree.h 2d76dee44704c47eed323356a758662724b674a0 F src/btreeInt.h 3ab435ed27adea54d040584b0bcc488ee7db1e38 F src/build.c ca574d33ffb1763cfd2979383f4d507095bfbe19 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 @@ -326,14 +326,14 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c cf72e06e15839ebe7121e01d3eebf256c039b0ca F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca -F src/pager.c ed5cff11793b6a4146582aabb29ed8613a6cf89e -F src/pager.h 7fc069c07f3120ee466ff3d48a9d376974ebffa7 +F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e +F src/pager.h 87c4118a71ba3965184148b379a6d93179071091 F src/parse.y 8a364a7a692e517dea8711b3c7f0d07fe32727d8 -F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef -F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 +F src/pcache.c f72f19956f8182ecd97cf9b7b0faa201711225b8 +F src/pcache.h 1ff11adce609ba7de139b6abfabaf9a2bac947b5 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 -F src/pragma.c 9dbb9ba2453d79bfc5905be0398aa30342b066bb -F src/pragma.h 631a91c8b0e6ca8f051a1d8a4a0da4150e04620a +F src/pragma.c 26a612db31748a23dc17b97296e521cf2ef42081 +F src/pragma.h 31b110aaecb5603829c97747b99abfe491df5fa0 F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 @@ -931,7 +931,7 @@ F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 4ea119731c62d2f7d0aa86dd5b184cbb61ca411b F test/pragma.test a44253f911e7d50127d4a08f927f47c861a4c772 -F test/pragma2.test b5e2ce4c892afceb308c6ae6163a9099b2a0d8d7 +F test/pragma2.test 93ef4f24fb97a59d935859daf26078384b265c12 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test 0b61566dd1c0f0b802f59dffa228c5dc5aa6b054 @@ -1364,7 +1364,7 @@ F tool/mkkeywordhash.c 37f9c2e62c31384b697ede8825e2d344e98db22c F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e -F tool/mkpragmatab.tcl 84af2b180484323a2ea22a2279e8bd9e3e1e492e +F tool/mkpragmatab.tcl 473b6a156bc018d36aac5288d8479a879d570b93 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 87240b09c20042999b41d5fabe091b7111287835 F tool/mksqlite3c.tcl b66b4170f693602cd6985aed15d9509fe2f18c84 @@ -1402,7 +1402,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e43e1171fd7837a08069dc25df4eac14db1c2afe -R 9a1d72f8baac116c36385e92e48c0378 +P 2518d5c971c4b32d9227b3bb7259162e3e27b00b +R 337aa604616b296340bdf382cbd4b435 +T *branch * cache_spill=N +T *sym-cache_spill=N * +T -sym-trunk * U drh -Z 9d52ec874b9a01b7b0eb1dab69dbb993 +Z e21337491dfb1b39176b63de38883141 diff --git a/manifest.uuid b/manifest.uuid index bf01d0ad61..a425302e46 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2518d5c971c4b32d9227b3bb7259162e3e27b00b \ No newline at end of file +549d42be0dac87dc04c3eeccfdc60615c3a6ad3f \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a61a6edf2f..4a51b01d75 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2556,19 +2556,11 @@ int sqlite3BtreeClose(Btree *p){ } /* -** Change the limit on the number of pages allowed in the cache. -** -** The maximum number of cache pages is set to the absolute -** value of mxPage. If mxPage is negative, the pager will -** operate asynchronously - it will not stop to do fsync()s -** to insure data is written to the disk surface before -** continuing. Transactions still work if synchronous is off, -** and the database cannot be corrupted if this program -** crashes. But if the operating system crashes or there is -** an abrupt power failure when synchronous is off, the database -** could be left in an inconsistent and unrecoverable state. -** Synchronous is on by default so database corruption is not -** normally a worry. +** Change the "soft" limit on the number of pages in the cache. +** Unused and unmodified pages will be recycled when the number of +** pages in the cache exceeds this soft limit. But the size of the +** cache is allowed to grow larger than this limit if it contains +** dirty pages or pages still in active use. */ int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){ BtShared *pBt = p->pBt; @@ -2579,6 +2571,26 @@ int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){ return SQLITE_OK; } +/* +** Change the "spill" limit on the number of pages in the cache. +** If the number of pages exceeds this limit during a write transaction, +** the pager might attempt to "spill" pages to the journal early in +** order to free up memory. +** +** The value returned is the current spill size. If zero is passed +** as an argument, no changes are made to the spill size setting, so +** using mxPage of 0 is a way to query the current spill size. +*/ +int sqlite3BtreeSetSpillSize(Btree *p, int mxPage){ + BtShared *pBt = p->pBt; + int res; + assert( sqlite3_mutex_held(p->db->mutex) ); + sqlite3BtreeEnter(p); + res = sqlite3PagerSetSpillsize(pBt->pPager, mxPage); + sqlite3BtreeLeave(p); + return res; +} + #if SQLITE_MAX_MMAP_SIZE>0 /* ** Change the limit on the amount of the database file that may be diff --git a/src/btree.h b/src/btree.h index 0c15a59c11..09b713f3db 100644 --- a/src/btree.h +++ b/src/btree.h @@ -63,6 +63,7 @@ int sqlite3BtreeOpen( int sqlite3BtreeClose(Btree*); int sqlite3BtreeSetCacheSize(Btree*,int); +int sqlite3BtreeSetSpillSize(Btree*,int); #if SQLITE_MAX_MMAP_SIZE>0 int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); #endif diff --git a/src/pager.c b/src/pager.c index b537e9e931..f633a77927 100644 --- a/src/pager.c +++ b/src/pager.c @@ -3392,12 +3392,21 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){ } /* -** Change the maximum number of in-memory pages that are allowed. +** Change the maximum number of in-memory pages that are allowed +** before attempting to recycle clean and unused pages. */ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){ sqlite3PcacheSetCachesize(pPager->pPCache, mxPage); } +/* +** Change the maximum number of in-memory pages that are allowed +** before attempting to spill pages to journal. +*/ +int sqlite3PagerSetSpillsize(Pager *pPager, int mxPage){ + return sqlite3PcacheSetSpillsize(pPager->pPCache, mxPage); +} + /* ** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap. */ diff --git a/src/pager.h b/src/pager.h index 9d541dede9..22e73f4c76 100644 --- a/src/pager.h +++ b/src/pager.h @@ -123,6 +123,7 @@ void sqlite3PagerAlignReserve(Pager*,Pager*); #endif int sqlite3PagerMaxPageCount(Pager*, int); void sqlite3PagerSetCachesize(Pager*, int); +int sqlite3PagerSetSpillsize(Pager*, int); void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); void sqlite3PagerShrink(Pager*); void sqlite3PagerSetFlags(Pager*,unsigned); diff --git a/src/pcache.c b/src/pcache.c index e39262cb8c..ddcb0bcc45 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -21,6 +21,7 @@ struct PCache { PgHdr *pSynced; /* Last synced page in dirty page list */ int nRefSum; /* Sum of ref counts over all pages */ int szCache; /* Configured cache size */ + int szSpill; /* Size before spilling occurs */ int szPage; /* Size of every page in this cache */ int szExtra; /* Size of extra space for each page */ u8 bPurgeable; /* True if pages are on backing store */ @@ -110,10 +111,8 @@ static void pcacheUnpin(PgHdr *p){ } /* -** Compute the number of pages of cache requested. p->szCache is the +** Compute the number of pages of cache requested. p->szCache is the ** cache size requested by the "PRAGMA cache_size" statement. -** -** */ static int numberOfCachePages(PCache *p){ if( p->szCache>=0 ){ @@ -176,6 +175,7 @@ int sqlite3PcacheOpen( p->xStress = xStress; p->pStress = pStress; p->szCache = 100; + p->szSpill = 1; return sqlite3PcacheSetPageSize(p, szPage); } @@ -271,32 +271,33 @@ int sqlite3PcacheFetchStress( PgHdr *pPg; if( pCache->eCreate==2 ) return 0; - - /* Find a dirty page to write-out and recycle. First try to find a - ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC - ** cleared), but if that is not possible settle for any other - ** unreferenced dirty page. - */ - for(pPg=pCache->pSynced; - pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); - pPg=pPg->pDirtyPrev - ); - pCache->pSynced = pPg; - if( !pPg ){ - for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev); - } - if( pPg ){ - int rc; + if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){ + /* Find a dirty page to write-out and recycle. First try to find a + ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC + ** cleared), but if that is not possible settle for any other + ** unreferenced dirty page. + */ + for(pPg=pCache->pSynced; + pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); + pPg=pPg->pDirtyPrev + ); + pCache->pSynced = pPg; + if( !pPg ){ + for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev); + } + if( pPg ){ + int rc; #ifdef SQLITE_LOG_CACHE_SPILL - sqlite3_log(SQLITE_FULL, - "spill page %d making room for %d - cache used: %d/%d", - pPg->pgno, pgno, - sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), + sqlite3_log(SQLITE_FULL, + "spill page %d making room for %d - cache used: %d/%d", + pPg->pgno, pgno, + sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), numberOfCachePages(pCache)); #endif - rc = pCache->xStress(pCache->pStress, pPg); - if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ - return rc; + rc = pCache->xStress(pCache->pStress, pPg); + if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ + return rc; + } } } *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2); @@ -641,6 +642,25 @@ void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){ numberOfCachePages(pCache)); } +/* +** Set the suggested cache-spill value. Make no changes if if the +** argument is zero. Return the effective cache-spill size, which will +** be the larger of the szSpill and szCache. +*/ +int sqlite3PcacheSetSpillsize(PCache *p, int mxPage){ + int res; + assert( p->pCache!=0 ); + if( mxPage ){ + if( mxPage<0 ){ + mxPage = (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); + } + p->szSpill = mxPage; + } + res = numberOfCachePages(p); + if( resszSpill ) res = p->szSpill; + return res; +} + /* ** Free up as much memory as possible from the page cache. */ diff --git a/src/pcache.h b/src/pcache.h index a0724df22f..42c44cf7ba 100644 --- a/src/pcache.h +++ b/src/pcache.h @@ -146,6 +146,13 @@ void sqlite3PcacheSetCachesize(PCache *, int); int sqlite3PcacheGetCachesize(PCache *); #endif +/* Set or get the suggested spill-size for the specified pager-cache. +** +** The spill-size is the minimum number of pages in cache before the cache +** will attempt to spill dirty pages by calling xStress. +*/ +int sqlite3PcacheSetSpillsize(PCache *, int); + /* Free up as much memory as possible from the page cache */ void sqlite3PcacheShrink(PCache*); diff --git a/src/pragma.c b/src/pragma.c index a0e394f782..85693cddfe 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -279,7 +279,7 @@ const char *sqlite3JournalModename(int eMode){ ** ** Pragmas are of this form: ** -** PRAGMA [database.]id [= value] +** PRAGMA [schema.]id [= value] ** ** The identifier might also be a string. The value is a string, and ** identifier, or a number. If minusFlag is true, then the value is @@ -291,8 +291,8 @@ const char *sqlite3JournalModename(int eMode){ */ void sqlite3Pragma( Parse *pParse, - Token *pId1, /* First part of [database.]id field */ - Token *pId2, /* Second part of [database.]id field, or NULL */ + Token *pId1, /* First part of [schema.]id field */ + Token *pId2, /* Second part of [schema.]id field, or NULL */ Token *pValue, /* Token for , or NULL */ int minusFlag /* True if a '-' sign preceded */ ){ @@ -313,7 +313,7 @@ void sqlite3Pragma( sqlite3VdbeRunOnlyOnce(v); pParse->nMem = 2; - /* Interpret the [database.] part of the pragma statement. iDb is the + /* Interpret the [schema.] part of the pragma statement. iDb is the ** index of the database this pragma is being applied to in db.aDb[]. */ iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); if( iDb<0 ) return; @@ -402,8 +402,8 @@ void sqlite3Pragma( #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) /* - ** PRAGMA [database.]default_cache_size - ** PRAGMA [database.]default_cache_size=N + ** PRAGMA [schema.]default_cache_size + ** PRAGMA [schema.]default_cache_size=N ** ** The first form reports the current persistent setting for the ** page cache size. The value returned is the maximum number of @@ -454,8 +454,8 @@ void sqlite3Pragma( #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) /* - ** PRAGMA [database.]page_size - ** PRAGMA [database.]page_size=N + ** PRAGMA [schema.]page_size + ** PRAGMA [schema.]page_size=N ** ** The first form reports the current setting for the ** database page size in bytes. The second form sets the @@ -481,8 +481,8 @@ void sqlite3Pragma( } /* - ** PRAGMA [database.]secure_delete - ** PRAGMA [database.]secure_delete=ON/OFF + ** PRAGMA [schema.]secure_delete + ** PRAGMA [schema.]secure_delete=ON/OFF ** ** The first form reports the current setting for the ** secure_delete flag. The second form changes the secure_delete @@ -507,8 +507,8 @@ void sqlite3Pragma( } /* - ** PRAGMA [database.]max_page_count - ** PRAGMA [database.]max_page_count=N + ** PRAGMA [schema.]max_page_count + ** PRAGMA [schema.]max_page_count=N ** ** The first form reports the current setting for the ** maximum number of pages in the database file. The @@ -519,7 +519,7 @@ void sqlite3Pragma( ** change. The only purpose is to provide an easy way to test ** the sqlite3AbsInt32() function. ** - ** PRAGMA [database.]page_count + ** PRAGMA [schema.]page_count ** ** Return the number of pages in the specified database. */ @@ -540,8 +540,8 @@ void sqlite3Pragma( } /* - ** PRAGMA [database.]locking_mode - ** PRAGMA [database.]locking_mode = (normal|exclusive) + ** PRAGMA [schema.]locking_mode + ** PRAGMA [schema.]locking_mode = (normal|exclusive) */ case PragTyp_LOCKING_MODE: { const char *zRet = "normal"; @@ -586,8 +586,8 @@ void sqlite3Pragma( } /* - ** PRAGMA [database.]journal_mode - ** PRAGMA [database.]journal_mode = + ** PRAGMA [schema.]journal_mode + ** PRAGMA [schema.]journal_mode = ** (delete|persist|off|truncate|memory|wal|off) */ case PragTyp_JOURNAL_MODE: { @@ -627,8 +627,8 @@ void sqlite3Pragma( } /* - ** PRAGMA [database.]journal_size_limit - ** PRAGMA [database.]journal_size_limit=N + ** PRAGMA [schema.]journal_size_limit + ** PRAGMA [schema.]journal_size_limit=N ** ** Get or set the size limit on rollback journal files. */ @@ -647,8 +647,8 @@ void sqlite3Pragma( #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ /* - ** PRAGMA [database.]auto_vacuum - ** PRAGMA [database.]auto_vacuum=N + ** PRAGMA [schema.]auto_vacuum + ** PRAGMA [schema.]auto_vacuum=N ** ** Get or set the value of the database 'auto-vacuum' parameter. ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL @@ -699,7 +699,7 @@ void sqlite3Pragma( #endif /* - ** PRAGMA [database.]incremental_vacuum(N) + ** PRAGMA [schema.]incremental_vacuum(N) ** ** Do N steps of incremental vacuuming on a database. */ @@ -722,8 +722,8 @@ void sqlite3Pragma( #ifndef SQLITE_OMIT_PAGER_PRAGMAS /* - ** PRAGMA [database.]cache_size - ** PRAGMA [database.]cache_size=N + ** PRAGMA [schema.]cache_size + ** PRAGMA [schema.]cache_size=N ** ** The first form reports the current local setting for the ** page cache size. The second form sets the local @@ -747,7 +747,50 @@ void sqlite3Pragma( } /* - ** PRAGMA [database.]mmap_size(N) + ** PRAGMA [schema.]cache_spill + ** PRAGMA cache_spill=BOOLEAN + ** PRAGMA [schema.]cache_spill=N + ** + ** The first form reports the current local setting for the + ** page cache spill size. The second form turns cache spill on + ** or off. When turnning cache spill on, the size is set to the + ** current cache_size. The third form sets a spill size that + ** may be different form the cache size. + ** If N is positive then that is the + ** number of pages in the cache. If N is negative, then the + ** number of pages is adjusted so that the cache uses -N kibibytes + ** of memory. + ** + ** If the number of cache_spill pages is less then the number of + ** cache_size pages, no spilling occurs until the page count exceeds + ** the number of cache_size pages. + ** + ** The cache_spill=BOOLEAN setting applies to all attached schemas, + ** not just the schema specified. + */ + case PragTyp_CACHE_SPILL: { + int size; + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); + if( !zRight ){ + if( sqlite3ReadSchema(pParse) ) goto pragma_out; + returnSingleInt(v, "cache_spill", + (db->flags & SQLITE_CacheSpill)==0 ? 0 : + sqlite3BtreeSetSpillSize(pDb->pBt,0)); + }else{ + if( sqlite3GetInt32(zRight, &size) ){ + sqlite3BtreeSetSpillSize(pDb->pBt, size); + } + if( sqlite3GetBoolean(zRight, 0) ){ + db->flags |= SQLITE_CacheSpill; + }else{ + db->flags &= ~SQLITE_CacheSpill; + } + } + break; + } + + /* + ** PRAGMA [schema.]mmap_size(N) ** ** Used to set mapping size limit. The mapping size limit is ** used to limit the aggregate size of all memory mapped regions of the @@ -891,8 +934,8 @@ void sqlite3Pragma( #if SQLITE_ENABLE_LOCKING_STYLE /* - ** PRAGMA [database.]lock_proxy_file - ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path" + ** PRAGMA [schema.]lock_proxy_file + ** PRAGMA [schema.]lock_proxy_file = ":auto:"|"lock_file_path" ** ** Return or set the value of the lock_proxy_file flag. Changing ** the value sets a specific file to be used for database access locks. @@ -927,8 +970,8 @@ void sqlite3Pragma( #endif /* SQLITE_ENABLE_LOCKING_STYLE */ /* - ** PRAGMA [database.]synchronous - ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL + ** PRAGMA [schema.]synchronous + ** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL ** ** Return or set the local value of the synchronous flag. Changing ** the local value does not make changes to the disk file and the @@ -1644,16 +1687,16 @@ void sqlite3Pragma( #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS /* - ** PRAGMA [database.]schema_version - ** PRAGMA [database.]schema_version = + ** PRAGMA [schema.]schema_version + ** PRAGMA [schema.]schema_version = ** - ** PRAGMA [database.]user_version - ** PRAGMA [database.]user_version = + ** PRAGMA [schema.]user_version + ** PRAGMA [schema.]user_version = ** - ** PRAGMA [database.]freelist_count = + ** PRAGMA [schema.]freelist_count = ** - ** PRAGMA [database.]application_id - ** PRAGMA [database.]application_id = + ** PRAGMA [schema.]application_id + ** PRAGMA [schema.]application_id = ** ** The pragma's schema_version and user_version are used to set or get ** the value of the schema-version and user-version, respectively. Both @@ -1728,7 +1771,7 @@ void sqlite3Pragma( #ifndef SQLITE_OMIT_WAL /* - ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate + ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate ** ** Checkpoint the database. */ diff --git a/src/pragma.h b/src/pragma.h index 9e206dac49..1bb6691224 100644 --- a/src/pragma.h +++ b/src/pragma.h @@ -8,43 +8,44 @@ #define PragTyp_FLAG 2 #define PragTyp_BUSY_TIMEOUT 3 #define PragTyp_CACHE_SIZE 4 -#define PragTyp_CASE_SENSITIVE_LIKE 5 -#define PragTyp_COLLATION_LIST 6 -#define PragTyp_COMPILE_OPTIONS 7 -#define PragTyp_DATA_STORE_DIRECTORY 8 -#define PragTyp_DATABASE_LIST 9 -#define PragTyp_DEFAULT_CACHE_SIZE 10 -#define PragTyp_ENCODING 11 -#define PragTyp_FOREIGN_KEY_CHECK 12 -#define PragTyp_FOREIGN_KEY_LIST 13 -#define PragTyp_INCREMENTAL_VACUUM 14 -#define PragTyp_INDEX_INFO 15 -#define PragTyp_INDEX_LIST 16 -#define PragTyp_INTEGRITY_CHECK 17 -#define PragTyp_JOURNAL_MODE 18 -#define PragTyp_JOURNAL_SIZE_LIMIT 19 -#define PragTyp_LOCK_PROXY_FILE 20 -#define PragTyp_LOCKING_MODE 21 -#define PragTyp_PAGE_COUNT 22 -#define PragTyp_MMAP_SIZE 23 -#define PragTyp_PAGE_SIZE 24 -#define PragTyp_SECURE_DELETE 25 -#define PragTyp_SHRINK_MEMORY 26 -#define PragTyp_SOFT_HEAP_LIMIT 27 -#define PragTyp_STATS 28 -#define PragTyp_SYNCHRONOUS 29 -#define PragTyp_TABLE_INFO 30 -#define PragTyp_TEMP_STORE 31 -#define PragTyp_TEMP_STORE_DIRECTORY 32 -#define PragTyp_THREADS 33 -#define PragTyp_WAL_AUTOCHECKPOINT 34 -#define PragTyp_WAL_CHECKPOINT 35 -#define PragTyp_ACTIVATE_EXTENSIONS 36 -#define PragTyp_HEXKEY 37 -#define PragTyp_KEY 38 -#define PragTyp_REKEY 39 -#define PragTyp_LOCK_STATUS 40 -#define PragTyp_PARSER_TRACE 41 +#define PragTyp_CACHE_SPILL 5 +#define PragTyp_CASE_SENSITIVE_LIKE 6 +#define PragTyp_COLLATION_LIST 7 +#define PragTyp_COMPILE_OPTIONS 8 +#define PragTyp_DATA_STORE_DIRECTORY 9 +#define PragTyp_DATABASE_LIST 10 +#define PragTyp_DEFAULT_CACHE_SIZE 11 +#define PragTyp_ENCODING 12 +#define PragTyp_FOREIGN_KEY_CHECK 13 +#define PragTyp_FOREIGN_KEY_LIST 14 +#define PragTyp_INCREMENTAL_VACUUM 15 +#define PragTyp_INDEX_INFO 16 +#define PragTyp_INDEX_LIST 17 +#define PragTyp_INTEGRITY_CHECK 18 +#define PragTyp_JOURNAL_MODE 19 +#define PragTyp_JOURNAL_SIZE_LIMIT 20 +#define PragTyp_LOCK_PROXY_FILE 21 +#define PragTyp_LOCKING_MODE 22 +#define PragTyp_PAGE_COUNT 23 +#define PragTyp_MMAP_SIZE 24 +#define PragTyp_PAGE_SIZE 25 +#define PragTyp_SECURE_DELETE 26 +#define PragTyp_SHRINK_MEMORY 27 +#define PragTyp_SOFT_HEAP_LIMIT 28 +#define PragTyp_STATS 29 +#define PragTyp_SYNCHRONOUS 30 +#define PragTyp_TABLE_INFO 31 +#define PragTyp_TEMP_STORE 32 +#define PragTyp_TEMP_STORE_DIRECTORY 33 +#define PragTyp_THREADS 34 +#define PragTyp_WAL_AUTOCHECKPOINT 35 +#define PragTyp_WAL_CHECKPOINT 36 +#define PragTyp_ACTIVATE_EXTENSIONS 37 +#define PragTyp_HEXKEY 38 +#define PragTyp_KEY 39 +#define PragTyp_REKEY 40 +#define PragTyp_LOCK_STATUS 41 +#define PragTyp_PARSER_TRACE 42 #define PragFlag_NeedSchema 0x01 #define PragFlag_ReadOnly 0x02 static const struct sPragmaNames { @@ -91,9 +92,9 @@ static const struct sPragmaNames { #endif #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) { /* zName: */ "cache_spill", - /* ePragTyp: */ PragTyp_FLAG, + /* ePragTyp: */ PragTyp_CACHE_SPILL, /* ePragFlag: */ 0, - /* iArg: */ SQLITE_CacheSpill }, + /* iArg: */ 0 }, #endif { /* zName: */ "case_sensitive_like", /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, diff --git a/test/pragma2.test b/test/pragma2.test index e2c87019eb..c0b4f239e5 100644 --- a/test/pragma2.test +++ b/test/pragma2.test @@ -138,7 +138,7 @@ do_execsql_test pragma2-4.1 { PRAGMA cache_spill; PRAGMA main.cache_spill; PRAGMA temp.cache_spill; -} {1 1 1} +} {2000 2000 2000} do_execsql_test pragma2-4.2 { PRAGMA cache_spill=OFF; PRAGMA cache_spill; @@ -178,21 +178,43 @@ do_test pragma2-4.4 { PRAGMA lock_status; } } {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill -do_test pragma2-4.5 { +do_test pragma2-4.5.1 { db eval { - COMMIT; + ROLLBACK; PRAGMA cache_spill=OFF; + PRAGMA Cache_Spill; BEGIN; - UPDATE t1 SET c=c-1; + UPDATE t1 SET c=c+1; PRAGMA lock_status; } -} {main reserved temp unknown} ;# No cache spill, so no exclusive lock +} {0 main reserved temp unknown} ;# No cache spill, so no exclusive lock +do_test pragma2-4.5.2 { + db eval { + ROLLBACK; + PRAGMA cache_spill=100000; + PRAGMA cache_spill; + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } +} {100000 main reserved temp unknown} ;# Large cache spill threshold +do_test pragma2-4.5.3 { + db eval { + ROLLBACK; + PRAGMA cache_spill=25; + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } +} {main exclusive temp unknown} ;# Large cache spill, so no exclusive lock + # Verify that newly attached databases inherit the cache_spill=OFF # setting. # do_execsql_test pragma2-4.6 { - COMMIT; + ROLLBACK; + PRAGMA cache_spill=OFF; ATTACH 'test2.db' AS aux1; PRAGMA aux1.cache_size=50; BEGIN; diff --git a/tool/mkpragmatab.tcl b/tool/mkpragmatab.tcl index bbdf9da754..9e0c7d5153 100644 --- a/tool/mkpragmatab.tcl +++ b/tool/mkpragmatab.tcl @@ -47,8 +47,6 @@ set pragma_def { IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS) NAME: cache_spill - TYPE: FLAG - ARG: SQLITE_CacheSpill IF: !defined(SQLITE_OMIT_FLAG_PRAGMAS) NAME: reverse_unordered_selects From 644f4c1bbb2335d23c245e2bfd4fce0fe33967c7 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Nov 2015 15:04:05 +0000 Subject: [PATCH 22/55] Fix a #define in parse.y that disabled unused code in the generated parser. FossilOrigin-Name: f84e3085c87cfffe4aba0eb4c4a3298b4027db83 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/parse.y | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 21a3de1f3f..0565883d76 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\smissing\sword\sin\sa\sdocumentation\scomment.\s\sNo\schanges\sto\scode. -D 2015-11-11T18:43:49.517 +C Fix\sa\s#define\sin\sparse.y\sthat\sdisabled\sunused\scode\sin\sthe\sgenerated\sparser. +D 2015-11-12T15:04:05.278 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -328,7 +328,7 @@ F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c ed5cff11793b6a4146582aabb29ed8613a6cf89e F src/pager.h 7fc069c07f3120ee466ff3d48a9d376974ebffa7 -F src/parse.y 8a364a7a692e517dea8711b3c7f0d07fe32727d8 +F src/parse.y aad5cc866dc23719f361fe7e0b8eaec8ce4861a4 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 @@ -1402,7 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2518d5c971c4b32d9227b3bb7259162e3e27b00b -R 3dc308897daa57a7c4272c874c792ced -U mistachkin -Z 5a3c62c2da73a7a92ccd94cbe3857768 +P ed24d302657e8495bef7f5ed698c7cca12717be9 +R d2bed45a676ff9fbad30132bc7912ff2 +U drh +Z 9ab7252fe5fcd6a0ff588f1afe46df1d diff --git a/manifest.uuid b/manifest.uuid index 5f07e1aae7..6e51c4b405 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed24d302657e8495bef7f5ed698c7cca12717be9 \ No newline at end of file +f84e3085c87cfffe4aba0eb4c4a3298b4027db83 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 64f234ca7c..e504e64548 100644 --- a/src/parse.y +++ b/src/parse.y @@ -64,7 +64,7 @@ ** Indicate that sqlite3ParserFree() will never be called with a null ** pointer. */ -#define YYPARSEFREENOTNULL 1 +#define YYPARSEFREENEVERNULL 1 /* ** Alternative datatype for the argument to the malloc() routine passed From 4f9c8ec62dbfc5645f14b059862a87dfe3fd58b7 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Nov 2015 15:47:48 +0000 Subject: [PATCH 23/55] Test cases. Minor problems fixed. All appears to work now. FossilOrigin-Name: 9a431362dccbc9b8f93375f30a3b8955903cca79 --- manifest | 19 ++++++++----------- manifest.uuid | 2 +- src/pcache.c | 2 +- src/pragma.c | 5 +++-- test/pragma2.test | 35 +++++++++++++++++++++++++++++++++-- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index d7ec4d4e08..1b21bffde4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C First\sattempt\sat\senhancing\sthe\s"PRAGMA\scache_spill"\sstatement\sto\saccept\sa\ncache\sthreashold\ssize. -D 2015-11-12T14:57:19.268 +C Test\scases.\s\sMinor\sproblems\sfixed.\s\sAll\sappears\sto\swork\snow. +D 2015-11-12T15:47:48.274 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -329,10 +329,10 @@ F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e F src/pager.h 87c4118a71ba3965184148b379a6d93179071091 F src/parse.y 8a364a7a692e517dea8711b3c7f0d07fe32727d8 -F src/pcache.c f72f19956f8182ecd97cf9b7b0faa201711225b8 +F src/pcache.c 73895411fa6b7bd6f0091212feabbe833b358d23 F src/pcache.h 1ff11adce609ba7de139b6abfabaf9a2bac947b5 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 -F src/pragma.c 26a612db31748a23dc17b97296e521cf2ef42081 +F src/pragma.c 0e91830e5cea31771121eb8967e8c110f7e8216a F src/pragma.h 31b110aaecb5603829c97747b99abfe491df5fa0 F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a @@ -931,7 +931,7 @@ F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 4ea119731c62d2f7d0aa86dd5b184cbb61ca411b F test/pragma.test a44253f911e7d50127d4a08f927f47c861a4c772 -F test/pragma2.test 93ef4f24fb97a59d935859daf26078384b265c12 +F test/pragma2.test a8e11a7a38e2a5053fe4b807fc806c937d9a7469 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test 0b61566dd1c0f0b802f59dffa228c5dc5aa6b054 @@ -1402,10 +1402,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2518d5c971c4b32d9227b3bb7259162e3e27b00b -R 337aa604616b296340bdf382cbd4b435 -T *branch * cache_spill=N -T *sym-cache_spill=N * -T -sym-trunk * +P 549d42be0dac87dc04c3eeccfdc60615c3a6ad3f +R 675bbffc41ae7c4e7c58162bf39590a3 U drh -Z e21337491dfb1b39176b63de38883141 +Z 4ec2916143a078881954f66921bb963f diff --git a/manifest.uuid b/manifest.uuid index a425302e46..27ce563ab6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -549d42be0dac87dc04c3eeccfdc60615c3a6ad3f \ No newline at end of file +9a431362dccbc9b8f93375f30a3b8955903cca79 \ No newline at end of file diff --git a/src/pcache.c b/src/pcache.c index ddcb0bcc45..5ac9d34a1e 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -652,7 +652,7 @@ int sqlite3PcacheSetSpillsize(PCache *p, int mxPage){ assert( p->pCache!=0 ); if( mxPage ){ if( mxPage<0 ){ - mxPage = (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); + mxPage = (int)((-1024*(i64)mxPage)/(p->szPage+p->szExtra)); } p->szSpill = mxPage; } diff --git a/src/pragma.c b/src/pragma.c index 85693cddfe..7754e26c89 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -769,7 +769,6 @@ void sqlite3Pragma( ** not just the schema specified. */ case PragTyp_CACHE_SPILL: { - int size; assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( !zRight ){ if( sqlite3ReadSchema(pParse) ) goto pragma_out; @@ -777,14 +776,16 @@ void sqlite3Pragma( (db->flags & SQLITE_CacheSpill)==0 ? 0 : sqlite3BtreeSetSpillSize(pDb->pBt,0)); }else{ + int size = 1; if( sqlite3GetInt32(zRight, &size) ){ sqlite3BtreeSetSpillSize(pDb->pBt, size); } - if( sqlite3GetBoolean(zRight, 0) ){ + if( sqlite3GetBoolean(zRight, size!=0) ){ db->flags |= SQLITE_CacheSpill; }else{ db->flags &= ~SQLITE_CacheSpill; } + setAllPagerFlags(db); } break; } diff --git a/test/pragma2.test b/test/pragma2.test index c0b4f239e5..9cb31fa14f 100644 --- a/test/pragma2.test +++ b/test/pragma2.test @@ -197,16 +197,27 @@ do_test pragma2-4.5.2 { UPDATE t1 SET c=c+1; PRAGMA lock_status; } -} {100000 main reserved temp unknown} ;# Large cache spill threshold +} {100000 main reserved temp unknown} ;# Big spill threshold -> no excl lock do_test pragma2-4.5.3 { db eval { ROLLBACK; PRAGMA cache_spill=25; + PRAGMA main.cache_spill; BEGIN; UPDATE t1 SET c=c+1; PRAGMA lock_status; } -} {main exclusive temp unknown} ;# Large cache spill, so no exclusive lock +} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock +do_test pragma2-4.5.4 { + db eval { + ROLLBACK; + PRAGMA cache_spill(-25); + PRAGMA main.cache_spill; + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } +} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock # Verify that newly attached databases inherit the cache_spill=OFF @@ -231,6 +242,26 @@ do_execsql_test pragma2-4.8 { UPDATE t2 SET c=c-1; PRAGMA lock_status; } {main unlocked temp unknown aux1 exclusive} +db close +forcedelete test.db +sqlite3 db test.db + +breakpoint +do_execsql_test pragma2-5.1 { + PRAGMA page_size=16384; + CREATE TABLE t1(x); + PRAGMA cache_size=2; + PRAGMA cache_spill=YES; + PRAGMA cache_spill; +} {2} +do_execsql_test pragma2-5.2 { + PRAGMA cache_spill=NO; + PRAGMA cache_spill; +} {0} +do_execsql_test pragma2-5.3 { + PRAGMA cache_spill(-51); + PRAGMA cache_spill; +} {3} test_restore_config_pagecache finish_test From d83f7ca1140e152f9bfa4ad2e07d78c167a5d203 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 12 Nov 2015 20:12:51 +0000 Subject: [PATCH 24/55] Add support for the SQLITE_SQLLOG_CONDITIONAL environment variable to the logging code in test_sqllog.c. When defined, logging is only performed if the "-sqllog" file is present in the file system when the main database is opened. FossilOrigin-Name: cab8126be9f63dd596719b12704ba77c128282bc --- manifest | 26 +++++----- manifest.uuid | 2 +- src/main.c | 6 +++ src/sqliteInt.h | 8 ++++ src/test1.c | 25 ++++++++++ src/test_config.c | 6 +++ src/test_sqllog.c | 81 ++++++++++++++++++++++++------- test/sqllog.test | 116 +++++++++++++++++++++++++++++++++++++++++++++ test/trigger7.test | 1 - 9 files changed, 239 insertions(+), 32 deletions(-) create mode 100644 test/sqllog.test diff --git a/manifest b/manifest index 06f06b267c..183d8a99ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\s"PRAGMA\scache_spill"\sstatement\sto\saccept\san\sinteger\sargument\swhich\nis\sthe\sthreshold\sat\swhich\sspilling\swill\sbegin. -D 2015-11-12T16:44:40.812 +C Add\ssupport\sfor\sthe\sSQLITE_SQLLOG_CONDITIONAL\senvironment\svariable\sto\sthe\slogging\scode\sin\stest_sqllog.c.\sWhen\sdefined,\slogging\sis\sonly\sperformed\sif\sthe\s"-sqllog"\sfile\sis\spresent\sin\sthe\sfile\ssystem\swhen\sthe\smain\sdatabase\sis\sopened. +D 2015-11-12T20:12:51.646 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -304,7 +304,7 @@ F src/insert.c 419a947f27ce2da18eebf440a5aa80cc825defae F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 -F src/main.c f393acc6e5d604cbe0054376d62f668a5560b3f1 +F src/main.c bf26fbebab82069cd7d15c41a58110be8075c87e F src/malloc.c 337bbe9c7d436ef9b7d06b5dd10bbfc8f3025972 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b @@ -344,12 +344,12 @@ F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h bc6d24460fe544323517630b1e20539146379077 +F src/sqliteInt.h ebd88d3a2c03440f48145a47df51f0a502bbf24e F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e F src/tclsqlite.c d9439b6a910985b7fff43ba6756bcef00de22649 -F src/test1.c a719afff3144f7f01c6dc3f7d118ac31d15e7527 +F src/test1.c 05df2a9e4f483b2fb642162209e3aeb11c24b44f F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b F src/test3.c a8887dabbbee3059af338f20d290084a63ed1b0f F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -363,7 +363,7 @@ F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 F src/test_backup.c 2e6e6a081870150f20c526a2e9d0d29cda47d803 F src/test_blob.c e5a7a81d61a780da79101aeb1e60d300af169e07 F src/test_btree.c 2e9978eca99a9a4bfa8cae949efb00886860a64f -F src/test_config.c 426527fbb12fc23669a1e973ecdc8c5e92c2e2cf +F src/test_config.c 7523f8bd7604aec88a9d1c303d93c925bcfcc9f9 F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f @@ -386,7 +386,7 @@ F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d F src/test_rtree.c 43fff4c5a01576d6d213f27472598801a247890c F src/test_schema.c 2bdba21b82f601da69793e1f1d11bf481a79b091 F src/test_server.c a2615049954cbb9cfb4a62e18e2f0616e4dc38fe -F src/test_sqllog.c b690c12933f50ff46491e0d56a251f84ae16e914 +F src/test_sqllog.c 0d138a8180a312bf996b37fa66da5c5799d4d57b F src/test_superlock.c 06797157176eb7085027d9dd278c0d7a105e3ec9 F src/test_syscall.c 2e21ca7f7dc54a028f1967b63f1e76155c356f9b F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa @@ -1038,6 +1038,7 @@ F test/spellfix.test 0597065ff57042df1f138e6a2611ae19c2698135 F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test 89b3d5aad05b99f707ee3786bdd4416dccf83304 +F test/sqllog.test a8faa2df39610a037dd372ed872d124260d32953 F test/stat.test 8de91498c99f5298b303f70f1d1f3b9557af91bf F test/statfault.test f525a7bf633e50afd027700e9a486090684b1ac1 F test/stmt.test 25d64e3dbf9a3ce89558667d7f39d966fe2a71b9 @@ -1226,7 +1227,7 @@ F test/trigger3.test aa640bb2bbb03edd5ff69c055117ea088f121945 F test/trigger4.test 74700b76ebf3947b2f7a92405141eb2cf2a5d359 F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83 F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9 -F test/trigger7.test 200dd51e728c9cdc20c72d99d9e9d45c667248f8 +F test/trigger7.test 799c9d2561facef70340cc9e0dee98aee9b5bdfe F test/trigger8.test 30cb0530bd7c4728055420e3f739aa00412eafa4 F test/trigger9.test 2226ec795a33b0460ab5cf8891e9054cc7edef41 F test/triggerA.test fe5597f47ee21bacb4936dc827994ed94161e332 @@ -1402,8 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f84e3085c87cfffe4aba0eb4c4a3298b4027db83 9a431362dccbc9b8f93375f30a3b8955903cca79 -R 5f87cb60f8f27cae7787baa81cd88247 -T +closed 9a431362dccbc9b8f93375f30a3b8955903cca79 -U drh -Z c0a66dbf9634d84e657f233ea4ee622f +P f79d264db24a470d1a4571e15a99cd3d68b5166c +R 832ba4972d7900eed0d1e5716cf55baa +U dan +Z 957802b71a98a3fb9167ff96a716895f diff --git a/manifest.uuid b/manifest.uuid index 9052b6aab8..2eb3af5615 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f79d264db24a470d1a4571e15a99cd3d68b5166c \ No newline at end of file +cab8126be9f63dd596719b12704ba77c128282bc \ No newline at end of file diff --git a/src/main.c b/src/main.c index 56d4588494..138626746d 100644 --- a/src/main.c +++ b/src/main.c @@ -220,6 +220,12 @@ int sqlite3_initialize(void){ if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); sqlite3GlobalConfig.inProgress = 1; +#ifdef SQLITE_INIT_SQLLOG + { + extern void SQLITE_INIT_SQLLOG(void); + SQLITE_INIT_SQLLOG(); + } +#endif memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); sqlite3RegisterGlobalFunctions(); if( sqlite3GlobalConfig.isPCacheInit==0 ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index c65e0f2051..fdd82f9915 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -527,6 +527,14 @@ # define SQLITE_DEFAULT_PCACHE_INITSZ 100 #endif +/* +** If SQLITE_INIT_SQLLOG is defined, then SQLITE_ENABLE_SQLLOG is +** automatically defined as well. +*/ +#if defined(SQLITE_INIT_SQLLOG) && !defined(SQLITE_ENABLE_SQLLOG) +# define SQLITE_ENABLE_SQLLOG 1 +#endif + /* ** GCC does not define the offsetof() macro so we'll have to do it diff --git a/src/test1.c b/src/test1.c index 7ce4ed5a5a..43feb2dc2d 100644 --- a/src/test1.c +++ b/src/test1.c @@ -2226,6 +2226,28 @@ static int test_stmt_scanstatus_reset( } #endif +#ifdef SQLITE_ENABLE_SQLLOG +/* +** Usage: sqlite3_config_sqllog +** +** Zero the SQLITE_CONFIG_SQLLOG configuration +*/ +static int test_config_sqllog( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + sqlite3_stmt *pStmt; /* First argument */ + if( objc!=1 ){ + Tcl_WrongNumArgs(interp, 1, objv, ""); + return TCL_ERROR; + } + sqlite3_config(SQLITE_CONFIG_SQLLOG, 0, 0); + return TCL_OK; +} +#endif + /* ** Usage: sqlite3_next_stmt DB STMT ** @@ -7036,6 +7058,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_stmt_scanstatus", test_stmt_scanstatus, 0 }, { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset, 0 }, #endif +#ifdef SQLITE_ENABLE_SQLLOG + { "sqlite3_config_sqllog", test_config_sqllog, 0 }, +#endif }; static int bitmask_size = sizeof(Bitmask)*8; diff --git a/src/test_config.c b/src/test_config.c index be43f87e73..4cb5c0057a 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -657,6 +657,12 @@ Tcl_SetVar2(interp, "sqlite_options", "mergesort", "1", TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "sqlite_options", "yytrackmaxstackdepth", "0", TCL_GLOBAL_ONLY); #endif +#ifdef SQLITE_ENABLE_SQLLOG + Tcl_SetVar2(interp, "sqlite_options", "sqllog", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "sqllog", "0", TCL_GLOBAL_ONLY); +#endif + #define LINKVAR(x) { \ static const int cv_ ## x = SQLITE_ ## x; \ Tcl_LinkVar(interp, "SQLITE_" #x, (char *)&(cv_ ## x), \ diff --git a/src/test_sqllog.c b/src/test_sqllog.c index 6c0bf954ba..31d5ad2f5b 100644 --- a/src/test_sqllog.c +++ b/src/test_sqllog.c @@ -46,6 +46,12 @@ ** separate copy is taken each time the database file is opened or attached) ** by setting the environment variable SQLITE_SQLLOG_REUSE_FILES to 0. ** +** If the environment variable SQLITE_SQLLOG_CONDITIONAL is defined, then +** logging is only done for database connections if a file named +** "-sqllog" exists in the same directly as the main database +** file when it is first opened ("" is replaced by the actual +** name of the main database file). +** ** OUTPUT: ** ** The SQLITE_SQLLOG_DIR is populated with three types of files: @@ -88,6 +94,7 @@ static int getProcessId(void){ /* Names of environment variables to be used */ #define ENVIRONMENT_VARIABLE1_NAME "SQLITE_SQLLOG_DIR" #define ENVIRONMENT_VARIABLE2_NAME "SQLITE_SQLLOG_REUSE_FILES" +#define ENVIRONMENT_VARIABLE3_NAME "SQLITE_SQLLOG_CONDITIONAL" /* Assume that all database and database file names are shorted than this. */ #define SQLLOG_NAMESZ 512 @@ -116,6 +123,7 @@ static struct SLGlobal { int nConn; /* Size of aConn[] array */ /* Protected by SLGlobal.mutex */ + int bConditional; /* Only trace if *-sqllog file is present */ int bReuse; /* True to avoid extra copies of db files */ char zPrefix[SQLLOG_NAMESZ]; /* Prefix for all created files */ char zIdx[SQLLOG_NAMESZ]; /* Full path to *.idx file */ @@ -215,7 +223,7 @@ static char *sqllogFindFile(const char *zFile){ } static int sqllogFindAttached( - struct SLConn *p, /* Database connection */ + sqlite3 *db, /* Database connection */ const char *zSearch, /* Name to search for (or NULL) */ char *zName, /* OUT: Name of attached database */ char *zFile /* OUT: Name of attached file */ @@ -228,7 +236,7 @@ static int sqllogFindAttached( ** described by the last row returned. */ assert( sqllogglobal.bRec==0 ); sqllogglobal.bRec = 1; - rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); + rc = sqlite3_prepare_v2(db, "PRAGMA database_list", -1, &pStmt, 0); if( rc==SQLITE_OK ){ while( SQLITE_ROW==sqlite3_step(pStmt) ){ const char *zVal1; int nVal1; @@ -236,7 +244,9 @@ static int sqllogFindAttached( zVal1 = (const char*)sqlite3_column_text(pStmt, 1); nVal1 = sqlite3_column_bytes(pStmt, 1); - memcpy(zName, zVal1, nVal1+1); + if( zName ){ + memcpy(zName, zVal1, nVal1+1); + } zVal2 = (const char*)sqlite3_column_text(pStmt, 2); nVal2 = sqlite3_column_bytes(pStmt, 2); @@ -285,7 +295,7 @@ static void sqllogCopydb(struct SLConn *p, const char *zSearch, int bLog){ char *zInit = 0; int rc; - rc = sqllogFindAttached(p, zSearch, zName, zFile); + rc = sqllogFindAttached(p->db, zSearch, zName, zFile); if( rc!=SQLITE_OK ) return; if( zFile[0]=='\0' ){ @@ -405,6 +415,35 @@ static void testSqllogStmt(struct SLConn *p, const char *zSql){ } } +/* +** The database handle passed as the only argument has just been opened. +** Return true if this module should log initial databases and SQL +** statements for this connection, or false otherwise. +** +** If an error occurs, sqlite3_log() is invoked to report it to the user +** and zero returned. +*/ +static int sqllogTraceDb(sqlite3 *db){ + int bRet = 1; + if( sqllogglobal.bConditional ){ + char zFile[SQLLOG_NAMESZ]; /* Attached database name */ + int rc = sqllogFindAttached(db, "main", 0, zFile); + if( rc==SQLITE_OK ){ + int nFile = strlen(zFile); + if( (SQLLOG_NAMESZ-nFile)<8 ){ + sqlite3_log(SQLITE_IOERR, + "sqllogTraceDb(): database name too long (%d bytes)", nFile + ); + bRet = 0; + }else{ + memcpy(&zFile[nFile], "-sqllog", 8); + bRet = !access(zFile, F_OK); + } + } + } + return bRet; +} + /* ** The SQLITE_CONFIG_SQLLOG callback registered by sqlite3_init_sqllog(). ** @@ -439,15 +478,19 @@ static void testSqllog(void *pCtx, sqlite3 *db, const char *zSql, int eType){ if( sqllogglobal.mutex==0 ){ sqllogglobal.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE); } - p = &sqllogglobal.aConn[sqllogglobal.nConn++]; - p->fd = 0; - p->db = db; - p->iLog = sqllogglobal.iNextLog++; sqlite3_mutex_leave(master); - /* Open the log and take a copy of the main database file */ sqlite3_mutex_enter(sqllogglobal.mutex); - if( sqllogglobal.bRec==0 ){ + if( sqllogglobal.bRec==0 && sqllogTraceDb(db) ){ + + sqlite3_mutex_enter(master); + p = &sqllogglobal.aConn[sqllogglobal.nConn++]; + p->fd = 0; + p->db = db; + p->iLog = sqllogglobal.iNextLog++; + sqlite3_mutex_leave(master); + + /* Open the log and take a copy of the main database file */ sqllogOpenlog(p); if( p->fd ) sqllogCopydb(p, "main", 0); } @@ -461,20 +504,21 @@ static void testSqllog(void *pCtx, sqlite3 *db, const char *zSql, int eType){ p = &sqllogglobal.aConn[i]; if( p->db==db ) break; } - if( i==sqllogglobal.nConn ) return; /* A database handle close command */ if( eType==2 ){ sqlite3_mutex_enter(master); - if( p->fd ) fclose(p->fd); - p->db = 0; - p->fd = 0; + if( ifd ) fclose(p->fd); + p->db = 0; + p->fd = 0; + sqllogglobal.nConn--; + } - sqllogglobal.nConn--; if( sqllogglobal.nConn==0 ){ sqlite3_mutex_free(sqllogglobal.mutex); sqllogglobal.mutex = 0; - }else{ + }else if( i0 ){ memmove(p, &p[1], nShift*sizeof(struct SLConn)); @@ -483,7 +527,7 @@ static void testSqllog(void *pCtx, sqlite3 *db, const char *zSql, int eType){ sqlite3_mutex_leave(master); /* An ordinary SQL command. */ - }else if( p->fd ){ + }else if( ifd ){ sqlite3_mutex_enter(sqllogglobal.mutex); if( sqllogglobal.bRec==0 ){ testSqllogStmt(p, zSql); @@ -504,6 +548,9 @@ void sqlite3_init_sqllog(void){ if( SQLITE_OK==sqlite3_config(SQLITE_CONFIG_SQLLOG, testSqllog, 0) ){ memset(&sqllogglobal, 0, sizeof(sqllogglobal)); sqllogglobal.bReuse = 1; + if( getenv(ENVIRONMENT_VARIABLE3_NAME) ){ + sqllogglobal.bConditional = 1; + } } } } diff --git a/test/sqllog.test b/test/sqllog.test new file mode 100644 index 0000000000..dca5781dbd --- /dev/null +++ b/test/sqllog.test @@ -0,0 +1,116 @@ +# 2015 November 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the test_sqllog.c module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix sqllog + +ifcapable !sqllog { + finish_test + return +} + +proc readfile {f} { + set fd [open $f] + set txt [read $fd] + close $fd + set txt +} + +proc delete_all_sqllog_files {} { + forcedelete {*}[glob -nocomplain sqllog_*.sql] + forcedelete {*}[glob -nocomplain sqllog_*.db] + forcedelete {*}[glob -nocomplain sqllog_*.idx] +} + +proc touch {f} { + set fd [open $f w+] + close $fd +} + +db close +sqlite3_shutdown +set ::env(SQLITE_SQLLOG_DIR) [pwd] + +delete_all_sqllog_files + +sqlite3 db test.db +set a a +set b b +do_execsql_test 1.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES($a, $b); + SELECT * FROM t1; +} {1 2 a b} +db close + +do_test 1.1 { + readfile [lindex [glob sqllog_*.sql] 0] +} [string trimleft { +/-- Main database is '.*/sqllog_.*_0.db' +CREATE TABLE t1\(x, y\);; -- clock=0 +INSERT INTO t1 VALUES\(1, 2\);; -- clock=1 +INSERT INTO t1 VALUES\('a', 'b'\);; -- clock=2 +SELECT . FROM t1;; -- clock=3 +/}] + +do_test 1.2 { + file size [lindex [glob sqllog_*_0.db] 0] +} 1024 + +#------------------------------------------------------------------------- +catch { db close } +sqlite3_shutdown +delete_all_sqllog_files +forcedelete test.db-sqllog + +set ::env(SQLITE_SQLLOG_CONDITIONAL) 1 +sqlite3 db test.db +do_execsql_test 2.1 { + INSERT INTO t1 VALUES(4, 5); + SELECT * FROM t1; +} {1 2 a b 4 5} + +do_test 2.2 { + glob -nocomplain sqllog_* +} {} + +db close +touch test.db-sqllog +sqlite3 db test.db +do_execsql_test 2.3 { + INSERT INTO t1 VALUES(6, 7); + SELECT * FROM t1; +} {1 2 a b 4 5 6 7} +db close + +do_test 2.4 { + readfile [lindex [glob sqllog_*.sql] 0] +} [string trimleft { +/-- Main database is '.*/sqllog_.*_0.db' +INSERT INTO t1 VALUES\(6, 7\);; -- clock=0 +SELECT . FROM t1;; -- clock=1 +/}] + +catch { db close } +sqlite3_shutdown +unset ::env(SQLITE_SQLLOG_DIR) +unset ::env(SQLITE_SQLLOG_CONDITIONAL) +sqlite3_config_sqllog +sqlite3_initialize +breakpoint +finish_test + + diff --git a/test/trigger7.test b/test/trigger7.test index 221962406b..847d78cd7a 100644 --- a/test/trigger7.test +++ b/test/trigger7.test @@ -21,7 +21,6 @@ ifcapable {!trigger} { return } - # Error messages resulting from qualified trigger names. # do_test trigger7-1.1 { From d66b2e02ee523ac6bb44ab75f3426a0bcb3617c2 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Nov 2015 21:42:40 +0000 Subject: [PATCH 25/55] Add a space before each line of error output in the test scripts so that all errors can be conveniently located in logs by doing "grep '^ '". FossilOrigin-Name: 9d532fb50d310df629ea65193f21dc9b3594ff5f --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- test/pragma2.test | 2 ++ test/tester.tcl | 6 +++--- test/wal3.test | 8 ++++---- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 183d8a99ba..3af41656d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sthe\sSQLITE_SQLLOG_CONDITIONAL\senvironment\svariable\sto\sthe\slogging\scode\sin\stest_sqllog.c.\sWhen\sdefined,\slogging\sis\sonly\sperformed\sif\sthe\s"-sqllog"\sfile\sis\spresent\sin\sthe\sfile\ssystem\swhen\sthe\smain\sdatabase\sis\sopened. -D 2015-11-12T20:12:51.646 +C Add\sa\sspace\sbefore\seach\sline\sof\serror\soutput\sin\sthe\stest\sscripts\sso\sthat\sall\nerrors\scan\sbe\sconveniently\slocated\sin\slogs\sby\sdoing\s"grep\s'^\s'". +D 2015-11-12T21:42:40.423 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -931,7 +931,7 @@ F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 4ea119731c62d2f7d0aa86dd5b184cbb61ca411b F test/pragma.test a44253f911e7d50127d4a08f927f47c861a4c772 -F test/pragma2.test a8e11a7a38e2a5053fe4b807fc806c937d9a7469 +F test/pragma2.test 1a4cc20b0cd8fc6411bd2f828cdc3ea1bdd570b9 F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test 0b61566dd1c0f0b802f59dffa228c5dc5aa6b054 @@ -1060,7 +1060,7 @@ F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl 83cc29c89259490b25d2d7e47535d6f2ed5a57c7 +F test/tester.tcl 87a4d4533f55c586bc17bca5b96d381a7fe328e0 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1278,7 +1278,7 @@ F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test ea8778d5b0df200adef2ca7c00c3c37d4375f772 F test/wal.test dbfc482e10c7263298833bb1fc60b3ac9d6340a1 F test/wal2.test 1f841d2048080d32f552942e333fd99ce541dada -F test/wal3.test 2ab8e490afe0164bfc89b185c8b2572e0d821f23 +F test/wal3.test b1d425f68a1f61d12563f0fa1ee6fca7d5afabf4 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c F test/wal5.test 88b5d9a6a3d1532497ee9f4296f010d66f07e33c F test/wal6.test 4421cd5a2fa99d29cc91ef12fb23bed171ed3a4c @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f79d264db24a470d1a4571e15a99cd3d68b5166c -R 832ba4972d7900eed0d1e5716cf55baa -U dan -Z 957802b71a98a3fb9167ff96a716895f +P cab8126be9f63dd596719b12704ba77c128282bc +R 285b415177be5b2cab525b82d9f69ae9 +U drh +Z a7a38819a361f89adc4ae5f714679f1c diff --git a/manifest.uuid b/manifest.uuid index 2eb3af5615..093fb4fd1f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cab8126be9f63dd596719b12704ba77c128282bc \ No newline at end of file +9d532fb50d310df629ea65193f21dc9b3594ff5f \ No newline at end of file diff --git a/test/pragma2.test b/test/pragma2.test index 9cb31fa14f..c8d87663c1 100644 --- a/test/pragma2.test +++ b/test/pragma2.test @@ -135,6 +135,8 @@ 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 main.cache_size=2000; + PRAGMA temp.cache_size=2000; PRAGMA cache_spill; PRAGMA main.cache_spill; PRAGMA temp.cache_spill; diff --git a/test/tester.tcl b/test/tester.tcl index d7effc6038..647daa1f41 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -746,8 +746,8 @@ proc do_test {name cmd expected} { # if {![info exists ::testprefix] || $::testprefix eq ""} { # error "no test prefix" # } - output2_if_no_verbose -nonewline $name... - output2 "\nExpected: \[$expected\]\n Got: \[$result\]" + output1 "" + output2 " $name expected: \[$expected\]\n $name got: \[$result\]" fail_test $name } else { output1 " Ok" @@ -1047,7 +1047,7 @@ proc finalize_testing {} { foreach {rec} [lsort $omitList] { if {$rec==$prec} continue set prec $rec - output2 [format { %-12s %s} [lindex $rec 0] [lindex $rec 1]] + output2 [format {. %-12s %s} [lindex $rec 0] [lindex $rec 1]] } } if {$nErr>0 && ![working_64bit_int]} { diff --git a/test/wal3.test b/test/wal3.test index bd312b349c..9ee8a99458 100644 --- a/test/wal3.test +++ b/test/wal3.test @@ -275,9 +275,9 @@ proc lock_callback {method filename handle lock} { if {$lock == "1 7 lock exclusive"} { return SQLITE_BUSY } return SQLITE_OK } -puts " Warning: This next test case causes SQLite to call xSleep(1) 100 times." -puts " Normally this equates to a 100ms delay, but if SQLite is built on unix" -puts " without HAVE_USLEEP defined, it may be 100 seconds." +puts "# Warning: This next test case causes SQLite to call xSleep(1) 100 times." +puts "# Normally this equates to a 100ms delay, but if SQLite is built on unix" +puts "# without HAVE_USLEEP defined, it may be 100 seconds." do_test wal3-4.3 { db close set ::locks [list] @@ -285,7 +285,7 @@ do_test wal3-4.3 { catchsql { SELECT * FROM x } } {1 {locking protocol}} -puts " Warning: Same again!" +puts "# Warning: Same again!" proc lock_callback {method filename handle lock} { if {$lock == "0 1 lock exclusive"} { return SQLITE_BUSY } return SQLITE_OK From 8d4482da96cac095da7bae205ae4cf1136855951 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Nov 2015 22:15:18 +0000 Subject: [PATCH 26/55] Always parse the schema *before* running "PRAGMA cache_size", not after. FossilOrigin-Name: 12e7d9ec023db4dd837f76006c87defc5a3e9388 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/pragma.c | 2 -- src/pragma.h | 2 +- tool/mkpragmatab.tcl | 1 + 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 3af41656d6..e33255648a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sspace\sbefore\seach\sline\sof\serror\soutput\sin\sthe\stest\sscripts\sso\sthat\sall\nerrors\scan\sbe\sconveniently\slocated\sin\slogs\sby\sdoing\s"grep\s'^\s'". -D 2015-11-12T21:42:40.423 +C Always\sparse\sthe\sschema\s*before*\srunning\s"PRAGMA\scache_size",\snot\safter. +D 2015-11-12T22:15:18.738 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -332,8 +332,8 @@ F src/parse.y aad5cc866dc23719f361fe7e0b8eaec8ce4861a4 F src/pcache.c 73895411fa6b7bd6f0091212feabbe833b358d23 F src/pcache.h 1ff11adce609ba7de139b6abfabaf9a2bac947b5 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 -F src/pragma.c 56161e4aa4891a45b534f6516acb343df15a5120 -F src/pragma.h 31b110aaecb5603829c97747b99abfe491df5fa0 +F src/pragma.c f3e7147299ca05ef4304a36f1fd6e002729c72c6 +F src/pragma.h 3d94aebbebd2089899fecc01909bf2608b39507d F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 @@ -1365,7 +1365,7 @@ F tool/mkkeywordhash.c 37f9c2e62c31384b697ede8825e2d344e98db22c F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e -F tool/mkpragmatab.tcl 473b6a156bc018d36aac5288d8479a879d570b93 +F tool/mkpragmatab.tcl e94e55d247d4fe3be34f2a4f4edb03fdcd09ce5b F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 87240b09c20042999b41d5fabe091b7111287835 F tool/mksqlite3c.tcl b66b4170f693602cd6985aed15d9509fe2f18c84 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P cab8126be9f63dd596719b12704ba77c128282bc -R 285b415177be5b2cab525b82d9f69ae9 +P 9d532fb50d310df629ea65193f21dc9b3594ff5f +R c87ef7443677f3561dc0db07fe8b69b1 U drh -Z a7a38819a361f89adc4ae5f714679f1c +Z df246221f99363b8ea6311e003f21bb5 diff --git a/manifest.uuid b/manifest.uuid index 093fb4fd1f..e10ef9ff00 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d532fb50d310df629ea65193f21dc9b3594ff5f \ No newline at end of file +12e7d9ec023db4dd837f76006c87defc5a3e9388 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 792f4f7e32..0d48057d21 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -735,13 +735,11 @@ void sqlite3Pragma( case PragTyp_CACHE_SIZE: { assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( !zRight ){ - if( sqlite3ReadSchema(pParse) ) goto pragma_out; returnSingleInt(v, "cache_size", pDb->pSchema->cache_size); }else{ int size = sqlite3Atoi(zRight); pDb->pSchema->cache_size = size; sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); - if( sqlite3ReadSchema(pParse) ) goto pragma_out; } break; } diff --git a/src/pragma.h b/src/pragma.h index 1bb6691224..24a6c9d710 100644 --- a/src/pragma.h +++ b/src/pragma.h @@ -87,7 +87,7 @@ static const struct sPragmaNames { #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) { /* zName: */ "cache_size", /* ePragTyp: */ PragTyp_CACHE_SIZE, - /* ePragFlag: */ 0, + /* ePragFlag: */ PragFlag_NeedSchema, /* iArg: */ 0 }, #endif #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) diff --git a/tool/mkpragmatab.tcl b/tool/mkpragmatab.tcl index 9e0c7d5153..bcd3ed5d86 100644 --- a/tool/mkpragmatab.tcl +++ b/tool/mkpragmatab.tcl @@ -168,6 +168,7 @@ set pragma_def { IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) NAME: cache_size + FLAG: NeedSchema IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) NAME: mmap_size From 5e3cefe3d02dcb3bcbdda5ddce033acdf2226e06 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Nov 2015 23:48:08 +0000 Subject: [PATCH 27/55] Update the SQLLOG logic so that to builds in accordance with the instructions in the header comment. FossilOrigin-Name: ee6f2feec7d777a969ddba6dc00fb571d64e57f8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/main.c | 6 +++--- src/sqliteInt.h | 9 --------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index e33255648a..a3f6f74aa8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Always\sparse\sthe\sschema\s*before*\srunning\s"PRAGMA\scache_size",\snot\safter. -D 2015-11-12T22:15:18.738 +C Update\sthe\sSQLLOG\slogic\sso\sthat\sto\sbuilds\sin\saccordance\swith\sthe\sinstructions\nin\sthe\sheader\scomment. +D 2015-11-12T23:48:08.393 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -304,7 +304,7 @@ F src/insert.c 419a947f27ce2da18eebf440a5aa80cc825defae F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 -F src/main.c bf26fbebab82069cd7d15c41a58110be8075c87e +F src/main.c 91feb5c7e393ad8f0c434754114a3493c3b0617a F src/malloc.c 337bbe9c7d436ef9b7d06b5dd10bbfc8f3025972 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b @@ -344,7 +344,7 @@ F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h ebd88d3a2c03440f48145a47df51f0a502bbf24e +F src/sqliteInt.h 1b8c1b37f0bd2cec784c9f257e449f72096b37f8 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9d532fb50d310df629ea65193f21dc9b3594ff5f -R c87ef7443677f3561dc0db07fe8b69b1 +P 12e7d9ec023db4dd837f76006c87defc5a3e9388 +R 47faba2f3865e3275bebdbc040497572 U drh -Z df246221f99363b8ea6311e003f21bb5 +Z 57e0c9a039c091174e5c94cdc0c6298e diff --git a/manifest.uuid b/manifest.uuid index e10ef9ff00..ad235026db 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -12e7d9ec023db4dd837f76006c87defc5a3e9388 \ No newline at end of file +ee6f2feec7d777a969ddba6dc00fb571d64e57f8 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 138626746d..9078630892 100644 --- a/src/main.c +++ b/src/main.c @@ -220,10 +220,10 @@ int sqlite3_initialize(void){ if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); sqlite3GlobalConfig.inProgress = 1; -#ifdef SQLITE_INIT_SQLLOG +#ifdef SQLITE_ENABLE_SQLLOG { - extern void SQLITE_INIT_SQLLOG(void); - SQLITE_INIT_SQLLOG(); + extern void sqlite3_init_sqllog(void); + sqlite3_init_sqllog(); } #endif memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index fdd82f9915..0a1eb770f7 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -527,15 +527,6 @@ # define SQLITE_DEFAULT_PCACHE_INITSZ 100 #endif -/* -** If SQLITE_INIT_SQLLOG is defined, then SQLITE_ENABLE_SQLLOG is -** automatically defined as well. -*/ -#if defined(SQLITE_INIT_SQLLOG) && !defined(SQLITE_ENABLE_SQLLOG) -# define SQLITE_ENABLE_SQLLOG 1 -#endif - - /* ** GCC does not define the offsetof() macro so we'll have to do it ** ourselves. From 061d35c145b00288071b1a95a92062bf58e18527 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Nov 2015 00:03:14 +0000 Subject: [PATCH 28/55] Change the error messages so that they begin can be grepped using '^!' instead of '^ '. There are far too many extraneous outputs that being with a space. FossilOrigin-Name: 367ec0db49607559960d58891771113c205fd951 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/tester.tcl | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index a3f6f74aa8..58eb701cc2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sSQLLOG\slogic\sso\sthat\sto\sbuilds\sin\saccordance\swith\sthe\sinstructions\nin\sthe\sheader\scomment. -D 2015-11-12T23:48:08.393 +C Change\sthe\serror\smessages\sso\sthat\sthey\sbegin\scan\sbe\sgrepped\susing\s'^!'\sinstead\nof\s'^\s'.\s\sThere\sare\sfar\stoo\smany\sextraneous\soutputs\sthat\sbeing\swith\sa\sspace. +D 2015-11-13T00:03:14.576 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -1060,7 +1060,7 @@ F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl 87a4d4533f55c586bc17bca5b96d381a7fe328e0 +F test/tester.tcl 9df86ab273a0877ffb4ec26c255166dcdca4c278 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 12e7d9ec023db4dd837f76006c87defc5a3e9388 -R 47faba2f3865e3275bebdbc040497572 +P ee6f2feec7d777a969ddba6dc00fb571d64e57f8 +R 408d324b4f8f857ba19128e8367a34ed U drh -Z 57e0c9a039c091174e5c94cdc0c6298e +Z 9a6642a6fe3dd67383802a321d24cffd diff --git a/manifest.uuid b/manifest.uuid index ad235026db..ca4e35f2cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ee6f2feec7d777a969ddba6dc00fb571d64e57f8 \ No newline at end of file +367ec0db49607559960d58891771113c205fd951 \ No newline at end of file diff --git a/test/tester.tcl b/test/tester.tcl index 647daa1f41..4008a34491 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -747,7 +747,7 @@ proc do_test {name cmd expected} { # error "no test prefix" # } output1 "" - output2 " $name expected: \[$expected\]\n $name got: \[$result\]" + output2 "! $name expected: \[$expected\]\n! $name got: \[$result\]" fail_test $name } else { output1 " Ok" @@ -1031,7 +1031,7 @@ proc finalize_testing {} { output2 "$nErr errors out of $nTest tests" } if {$nErr>$nKnown} { - output2 -nonewline "Failures on these tests:" + output2 -nonewline "!Failures on these tests:" foreach x [set_test_counter fail_list] { if {![info exists known_error($x)]} {output2 -nonewline " $x"} } From 29fbdb731bf395f99876aedde8c839059462c1ff Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Nov 2015 12:32:01 +0000 Subject: [PATCH 29/55] Disable two PRAGMA cache_spill tests when MEMORY_MANAGEMENT is enabled. FossilOrigin-Name: ebda77aad4d964593606ded2fdb19259ef9ebb8e --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/pragma2.test | 42 ++++++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 58eb701cc2..85e6bda4c2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\serror\smessages\sso\sthat\sthey\sbegin\scan\sbe\sgrepped\susing\s'^!'\sinstead\nof\s'^\s'.\s\sThere\sare\sfar\stoo\smany\sextraneous\soutputs\sthat\sbeing\swith\sa\sspace. -D 2015-11-13T00:03:14.576 +C Disable\stwo\sPRAGMA\scache_spill\stests\swhen\sMEMORY_MANAGEMENT\sis\senabled. +D 2015-11-13T12:32:01.756 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -931,7 +931,7 @@ F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 4ea119731c62d2f7d0aa86dd5b184cbb61ca411b F test/pragma.test a44253f911e7d50127d4a08f927f47c861a4c772 -F test/pragma2.test 1a4cc20b0cd8fc6411bd2f828cdc3ea1bdd570b9 +F test/pragma2.test 00065068eeab2d15ea55465ec0f1e0a70e2c369e F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test 0b61566dd1c0f0b802f59dffa228c5dc5aa6b054 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ee6f2feec7d777a969ddba6dc00fb571d64e57f8 -R 408d324b4f8f857ba19128e8367a34ed +P 367ec0db49607559960d58891771113c205fd951 +R 9ab8fd3363ba53b73551ba52840dbe48 U drh -Z 9a6642a6fe3dd67383802a321d24cffd +Z d2f99c38ca17fe2dc0162f34e1b5cb9f diff --git a/manifest.uuid b/manifest.uuid index ca4e35f2cf..934b26d4d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -367ec0db49607559960d58891771113c205fd951 \ No newline at end of file +ebda77aad4d964593606ded2fdb19259ef9ebb8e \ No newline at end of file diff --git a/test/pragma2.test b/test/pragma2.test index c8d87663c1..64b396bd1f 100644 --- a/test/pragma2.test +++ b/test/pragma2.test @@ -200,26 +200,28 @@ do_test pragma2-4.5.2 { PRAGMA lock_status; } } {100000 main reserved temp unknown} ;# Big spill threshold -> no excl lock -do_test pragma2-4.5.3 { - db eval { - ROLLBACK; - PRAGMA cache_spill=25; - PRAGMA main.cache_spill; - BEGIN; - UPDATE t1 SET c=c+1; - PRAGMA lock_status; - } -} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock -do_test pragma2-4.5.4 { - db eval { - ROLLBACK; - PRAGMA cache_spill(-25); - PRAGMA main.cache_spill; - BEGIN; - UPDATE t1 SET c=c+1; - PRAGMA lock_status; - } -} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock +ifcapable !memorymanage { + do_test pragma2-4.5.3 { + db eval { + ROLLBACK; + PRAGMA cache_spill=25; + PRAGMA main.cache_spill; + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } + } {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock + do_test pragma2-4.5.4 { + db eval { + ROLLBACK; + PRAGMA cache_spill(-25); + PRAGMA main.cache_spill; + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } + } {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock +} # Verify that newly attached databases inherit the cache_spill=OFF From d63fbb71033ca228c2dd8c1dec113cd2289e0d37 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Nov 2015 12:52:34 +0000 Subject: [PATCH 30/55] Fix the releasetest-out.txt log output from releasetest.tcl so that it works when the --jobs option is used. FossilOrigin-Name: 6bb314a5022c8bae63f6cdb48652915e05c06a38 --- manifest | 12 ++++---- manifest.uuid | 2 +- test/releasetest.tcl | 65 ++++++++++++++++++++++++++++---------------- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index 85e6bda4c2..972db47b4f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\stwo\sPRAGMA\scache_spill\stests\swhen\sMEMORY_MANAGEMENT\sis\senabled. -D 2015-11-13T12:32:01.756 +C Fix\sthe\sreleasetest-out.txt\slog\soutput\sfrom\sreleasetest.tcl\sso\sthat\sit\sworks\nwhen\sthe\s--jobs\soption\sis\sused. +D 2015-11-13T12:52:34.131 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -949,7 +949,7 @@ F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 -F test/releasetest.tcl 2d000ceded3115758be96abb9c10a5669fb27862 +F test/releasetest.tcl 59a3682dbfddb141c86c7d0fc407155a5517a1db F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea F test/rollback2.test fc14cf6d1a2b250d2735ef16124b971bce152f14 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 367ec0db49607559960d58891771113c205fd951 -R 9ab8fd3363ba53b73551ba52840dbe48 +P ebda77aad4d964593606ded2fdb19259ef9ebb8e +R 0d2c22d081ef129ebfad482569c607ff U drh -Z d2f99c38ca17fe2dc0162f34e1b5cb9f +Z 0f5445a085b6cf791e190a6c97d0a451 diff --git a/manifest.uuid b/manifest.uuid index 934b26d4d5..d171197a9c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ebda77aad4d964593606ded2fdb19259ef9ebb8e \ No newline at end of file +6bb314a5022c8bae63f6cdb48652915e05c06a38 \ No newline at end of file diff --git a/test/releasetest.tcl b/test/releasetest.tcl index 2e67aabae2..f49d0b27bd 100644 --- a/test/releasetest.tcl +++ b/test/releasetest.tcl @@ -306,22 +306,39 @@ foreach {key value} [array get ::Platforms] { } } -# Output log +# Output log. Disabled for slave interpreters. # -set LOG [open releasetest-out.txt w] -proc PUTS {args} { - if {[llength $args]==2} { - puts [lindex $args 0] [lindex $args 1] - puts $::LOG [lindex $args 1] - } else { - puts [lindex $args 0] - puts $::LOG [lindex $args 0] +if {[lindex $argv end]!="--slave"} { + set LOG [open releasetest-out.txt w] + proc PUTS {txt} { + puts $txt + puts $::LOG $txt + flush $::LOG + } + proc PUTSNNL {txt} { + puts -nonewline $txt + puts -nonewline $::LOG $txt + flush $::LOG + } + proc PUTSERR {txt} { + puts stderr $txt + puts $::LOG $txt + flush $::LOG + } + puts $LOG "$argv0 $argv" + set tm0 [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S} -gmt 1] + puts $LOG "start-time: $tm0 UTC" +} else { + proc PUTS {txt} { + puts $txt + } + proc PUTSNNL {txt} { + puts -nonewline $txt + } + proc PUTSERR {txt} { + puts stderr $txt } - flush $::LOG } -puts $LOG "$argv0 $argv" -set tm0 [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S} -gmt 1] -puts $LOG "start-time: $tm0 UTC" # Open the file $logfile and look for a report on the number of errors # and the number of test cases run. Add these values to the global @@ -809,8 +826,8 @@ proc process_options {argv} { } default { - PUTS stderr "" - PUTS stderr [string trim $::USAGE_MESSAGE] + PUTSERR stderr "" + PUTSERR stderr [string trim $::USAGE_MESSAGE] exit -1 } } @@ -818,7 +835,7 @@ proc process_options {argv} { if {0==[info exists ::Platforms($platform)]} { PUTS "Unknown platform: $platform" - PUTS -nonewline "Set the -platform option to " + PUTSNNL "Set the -platform option to " set print [list] foreach p [array names ::Platforms] { lappend print "\"$p\"" @@ -844,16 +861,16 @@ proc process_options {argv} { } PUTS "Running the following test configurations for $platform:" PUTS " [string trim $::CONFIGLIST]" - PUTS -nonewline "Flags:" - if {$::PROGRESS_MSGS} {PUTS -nonewline " --progress"} - if {$::DRYRUN} {PUTS -nonewline " --dryrun"} - if {$::BUILDONLY} {PUTS -nonewline " --buildonly"} - if {$::MSVC} {PUTS -nonewline " --msvc"} + PUTSNNL "Flags:" + if {$::PROGRESS_MSGS} {PUTSNNL " --progress"} + if {$::DRYRUN} {PUTSNNL " --dryrun"} + if {$::BUILDONLY} {PUTSNNL " --buildonly"} + if {$::MSVC} {PUTSNNL " --msvc"} switch -- $::QUICK { - 1 {PUTS -nonewline " --quick"} - 2 {PUTS -nonewline " --veryquick"} + 1 {PUTSNNL " --quick"} + 2 {PUTSNNL " --veryquick"} } - if {$::JOBS>1} {PUTS -nonewline " --jobs $::JOBS"} + if {$::JOBS>1} {PUTSNNL " --jobs $::JOBS"} PUTS "" } From 05d4ebf6c3652eda096ceddd755db37d89ebca41 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Nov 2015 13:15:42 +0000 Subject: [PATCH 31/55] Add the --transaction option to the sqldiff tool. FossilOrigin-Name: 8882d1f3ef0fc53d7c19918c3af43c5bdd79e88f --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/sqldiff.c | 10 ++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 972db47b4f..ddb0e9ebc3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sreleasetest-out.txt\slog\soutput\sfrom\sreleasetest.tcl\sso\sthat\sit\sworks\nwhen\sthe\s--jobs\soption\sis\sused. -D 2015-11-13T12:52:34.131 +C Add\sthe\s--transaction\soption\sto\sthe\ssqldiff\stool. +D 2015-11-13T13:15:42.017 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -1392,7 +1392,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 40e3458f0015290be8ecb6e03f9dbf1bb1e264c0 +F tool/sqldiff.c db1232df457fdd4cbf2a919a497fc44bb18fb933 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ebda77aad4d964593606ded2fdb19259ef9ebb8e -R 0d2c22d081ef129ebfad482569c607ff +P 6bb314a5022c8bae63f6cdb48652915e05c06a38 +R 935905eff9b6be5b31cdb25ab8246ccb U drh -Z 0f5445a085b6cf791e190a6c97d0a451 +Z 6be4f9e3d294b71573d3af5237a10dc6 diff --git a/manifest.uuid b/manifest.uuid index d171197a9c..e84e61c770 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6bb314a5022c8bae63f6cdb48652915e05c06a38 \ No newline at end of file +8882d1f3ef0fc53d7c19918c3af43c5bdd79e88f \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 90a53fe16a..0f406d8a03 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -1741,6 +1741,7 @@ static void showHelp(void){ " --schema Show only differences in the schema\n" " --summary Show only a summary of the differences\n" " --table TAB Show only differences in table TAB\n" +" --transaction Show SQL output inside a transaction\n" ); } @@ -1757,6 +1758,8 @@ int main(int argc, char **argv){ void (*xDiff)(const char*,FILE*) = diff_one_table; int nExt = 0; char **azExt = 0; + int useTransaction = 0; + int neverUseTransaction = 0; g.zArgv0 = argv[0]; sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); @@ -1770,6 +1773,7 @@ int main(int argc, char **argv){ out = fopen(argv[++i], "wb"); if( out==0 ) cmdlineError("cannot open: %s", argv[i]); xDiff = changeset_one_table; + neverUseTransaction = 1; }else if( strcmp(z,"debug")==0 ){ if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]); @@ -1803,6 +1807,9 @@ int main(int argc, char **argv){ if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]); zTab = argv[++i]; }else + if( strcmp(z,"transaction")==0 ){ + useTransaction = 1; + }else { cmdlineError("unknown option: %s", argv[i]); } @@ -1845,6 +1852,8 @@ int main(int argc, char **argv){ cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb2); } + if( neverUseTransaction ) useTransaction = 0; + if( useTransaction ) printf("BEGIN TRANSACTION;\n"); if( zTab ){ xDiff(zTab, out); }else{ @@ -1862,6 +1871,7 @@ int main(int argc, char **argv){ } sqlite3_finalize(pStmt); } + if( useTransaction ) printf("COMMIT;\n"); /* TBD: Handle trigger differences */ /* TBD: Handle view differences */ From ce6cbf9ff45002a4b2e5c5a974e55d3244a6448c Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 13 Nov 2015 16:59:00 +0000 Subject: [PATCH 32/55] Add the "--enable-static-shell" option to the amalgamation autoconf script. If set (the default) the compiled shell tool is statically linked against sqlite3.o. Otherwise, it is linked against libsqlite3.so. FossilOrigin-Name: 499a02a34316cada9e197ef1d2e77c4cd75c41be --- autoconf/Makefile.am | 6 ++++-- autoconf/configure.ac | 17 +++++++++++++++++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/autoconf/Makefile.am b/autoconf/Makefile.am index 5b7c4a090a..eed3ba41cb 100644 --- a/autoconf/Makefile.am +++ b/autoconf/Makefile.am @@ -6,8 +6,10 @@ libsqlite3_la_SOURCES = sqlite3.c libsqlite3_la_LDFLAGS = -no-undefined -version-info 8:6:8 bin_PROGRAMS = sqlite3 -sqlite3_SOURCES = shell.c sqlite3.c sqlite3.h -sqlite3_LDADD = @READLINE_LIBS@ +sqlite3_SOURCES = shell.c sqlite3.h +EXTRA_sqlite3_SOURCES = sqlite3.c +sqlite3_LDADD = @EXTRA_SHELL_OBJ@ @READLINE_LIBS@ +sqlite3_DEPENDENCIES = @EXTRA_SHELL_OBJ@ sqlite3_CFLAGS = $(AM_CFLAGS) include_HEADERS = sqlite3.h sqlite3ext.h diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 7812927557..e03dfe289b 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -4,6 +4,8 @@ # # --enable-threadsafe # --enable-readline +# --enable-editline +# --enable-static-shell # --enable-dynamic-extensions # @@ -117,6 +119,21 @@ fi AC_SUBST(JSON1_FLAGS) #----------------------------------------------------------------------- +#----------------------------------------------------------------------- +# --enable-static-shell +# +AC_ARG_ENABLE(static-shell, [AS_HELP_STRING( + [--enable-static-shell], + [statically link libsqlite3 into shell tool [default=yes]])], + [], [enable_static_shell=yes]) +if test x"$enable_static_shell" == "xyes"; then + EXTRA_SHELL_OBJ=sqlite3.$OBJEXT +else + EXTRA_SHELL_OBJ=libsqlite3.la +fi +AC_SUBST(EXTRA_SHELL_OBJ) +#----------------------------------------------------------------------- + AC_CHECK_FUNCS(posix_fallocate) #----------------------------------------------------------------------- diff --git a/manifest b/manifest index ddb0e9ebc3..aba2e0b07c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--transaction\soption\sto\sthe\ssqldiff\stool. -D 2015-11-13T13:15:42.017 +C Add\sthe\s"--enable-static-shell"\soption\sto\sthe\samalgamation\sautoconf\sscript.\sIf\sset\s(the\sdefault)\sthe\scompiled\sshell\stool\sis\sstatically\slinked\sagainst\ssqlite3.o.\sOtherwise,\sit\sis\slinked\sagainst\slibsqlite3.so. +D 2015-11-13T16:59:00.913 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -10,12 +10,12 @@ F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 -F autoconf/Makefile.am bd4a90972aa87f079af6624ddea3df3d58f26d2f +F autoconf/Makefile.am 089e5ecdb5761e64ea1013ded02feb4d8b29927d F autoconf/README 14458f1046c118efa721aadec5f227e876d3cd38 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/config.guess 94cc57e2a3fdb9c235b362ace86d77e89d188cad x F autoconf/config.sub 1efb390a8fb4bfafd74783a15a8fb5311c84300e x -F autoconf/configure.ac bec3caf78cf1bdbaad903dcd5c6029292eda3d2d +F autoconf/configure.ac 9a65da17e440466f9842288163f16f9b21298129 F autoconf/depcomp 0b26f101e3bc9fd1ff0be1da9fb4a82371142f92 x F autoconf/install-sh 06ee6336e63bb845c8439d777c32eb2eccc4fbf1 x F autoconf/ltmain.sh 7a658a24028f02331c1d2446562758083c5eadd1 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6bb314a5022c8bae63f6cdb48652915e05c06a38 -R 935905eff9b6be5b31cdb25ab8246ccb -U drh -Z 6be4f9e3d294b71573d3af5237a10dc6 +P 8882d1f3ef0fc53d7c19918c3af43c5bdd79e88f +R 2523a6a90a9922264d529f15493b3cc7 +U dan +Z 7b17a89a058e0f8db79be4630f564198 diff --git a/manifest.uuid b/manifest.uuid index e84e61c770..0e0c8ed1e1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8882d1f3ef0fc53d7c19918c3af43c5bdd79e88f \ No newline at end of file +499a02a34316cada9e197ef1d2e77c4cd75c41be \ No newline at end of file From 6653fbe91f1d91cae3891ba63bcc2afe6069417d Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Nov 2015 20:52:49 +0000 Subject: [PATCH 33/55] Fix a memory leak in the fuzzcheck utility. FossilOrigin-Name: dfd6d9f4fbe902086f9158dfa5f37e781765a683 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/fuzzcheck.c | 3 ++- test/releasetest.tcl | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index aba2e0b07c..0f09161c51 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"--enable-static-shell"\soption\sto\sthe\samalgamation\sautoconf\sscript.\sIf\sset\s(the\sdefault)\sthe\scompiled\sshell\stool\sis\sstatically\slinked\sagainst\ssqlite3.o.\sOtherwise,\sit\sis\slinked\sagainst\slibsqlite3.so. -D 2015-11-13T16:59:00.913 +C Fix\sa\smemory\sleak\sin\sthe\sfuzzcheck\sutility. +D 2015-11-13T20:52:49.277 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -753,7 +753,7 @@ F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 F test/fuzz3.test 53fabcd5f0f430f8b221282f6c12c4d0903c21eb F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 -F test/fuzzcheck.c ee926f1d4090d053ed542899720d4e4d30811bcc +F test/fuzzcheck.c 7c61352f20a28429b221f406f3854cf9c912f63b F test/fuzzdata1.db 7ee3227bad0e7ccdeb08a9e6822916777073c664 F test/fuzzdata2.db f03a420d3b822cc82e4f894ca957618fbe9c4973 F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -949,7 +949,7 @@ F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 -F test/releasetest.tcl 59a3682dbfddb141c86c7d0fc407155a5517a1db +F test/releasetest.tcl 30cf0851a6fb0343b65f27dc89ab7bed3c3cc77d F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea F test/rollback2.test fc14cf6d1a2b250d2735ef16124b971bce152f14 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8882d1f3ef0fc53d7c19918c3af43c5bdd79e88f -R 2523a6a90a9922264d529f15493b3cc7 -U dan -Z 7b17a89a058e0f8db79be4630f564198 +P 499a02a34316cada9e197ef1d2e77c4cd75c41be +R ffa98089b86396d49df8e3ddc3e3caf3 +U drh +Z 93ac31c4a1bdc9cbd2a68f004b288c50 diff --git a/manifest.uuid b/manifest.uuid index 0e0c8ed1e1..ca109b544c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -499a02a34316cada9e197ef1d2e77c4cd75c41be \ No newline at end of file +dfd6d9f4fbe902086f9158dfa5f37e781765a683 \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index 19995684e4..32690dc466 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -838,6 +838,7 @@ int main(int argc, char **argv){ int nMem = 0; /* Memory limit */ char *zExpDb = 0; /* Write Databases to files in this directory */ char *zExpSql = 0; /* Write SQL to files in this directory */ + void *pHeap = 0; /* Heap for use by SQLite */ iBegin = timeOfDay(); #ifdef __unix__ @@ -1085,7 +1086,6 @@ int main(int argc, char **argv){ /* Limit available memory, if requested */ if( nMem>0 ){ - void *pHeap; sqlite3_shutdown(); pHeap = malloc(nMem); if( pHeap==0 ){ @@ -1184,5 +1184,6 @@ int main(int argc, char **argv){ sqlite3_libversion(), sqlite3_sourceid()); } free(azSrcDb); + free(pHeap); return 0; } diff --git a/test/releasetest.tcl b/test/releasetest.tcl index f49d0b27bd..f9c4406d40 100644 --- a/test/releasetest.tcl +++ b/test/releasetest.tcl @@ -439,6 +439,7 @@ proc run_slave_test {} { foreach {title dir configOpts testtarget makeOpts cflags opts} $T {} # Create and switch to the test directory. + set ::env(SQLITE_TMPDIR) [file normalize $dir] trace_cmd file mkdir $dir trace_cmd cd $dir catch {file delete core} From ebed3fa3e1193352caa581181332c9b26c007004 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 14 Nov 2015 16:47:23 +0000 Subject: [PATCH 34/55] Use randomness to prevent showness in the generated-column-name uniqueness checking. FossilOrigin-Name: 6266712968a2cdcd6f5a3007d60c2cf1b3faf912 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 0f09161c51..abc88a6886 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sleak\sin\sthe\sfuzzcheck\sutility. -D 2015-11-13T20:52:49.277 +C Use\srandomness\sto\sprevent\sshowness\sin\sthe\sgenerated-column-name\suniqueness\nchecking. +D 2015-11-14T16:47:23.463 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -339,7 +339,7 @@ F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 00a2a10d4298a685d0eeb05b09ef018a2bd81bf8 +F src/select.c 7ef4a946893f171920843d4d8c30c2544a060fbe F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 499a02a34316cada9e197ef1d2e77c4cd75c41be -R ffa98089b86396d49df8e3ddc3e3caf3 +P dfd6d9f4fbe902086f9158dfa5f37e781765a683 +R f75d239f0c3cc028f9c3bdc5405581af U drh -Z 93ac31c4a1bdc9cbd2a68f004b288c50 +Z df73d438cc87e48519d39f020060cfa5 diff --git a/manifest.uuid b/manifest.uuid index ca109b544c..ea0fe67b11 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dfd6d9f4fbe902086f9158dfa5f37e781765a683 \ No newline at end of file +6266712968a2cdcd6f5a3007d60c2cf1b3faf912 \ No newline at end of file diff --git a/src/select.c b/src/select.c index bd732e5bc8..afebf87ba4 100644 --- a/src/select.c +++ b/src/select.c @@ -1596,7 +1596,7 @@ int sqlite3ColumnsFromExprList( ){ sqlite3 *db = pParse->db; /* Database connection */ int i, j; /* Loop counters */ - int cnt; /* Index added to make the name unique */ + u32 cnt; /* Index added to make the name unique */ Column *aCol, *pCol; /* For looping over result columns */ int nCol; /* Number of columns in the result set */ Expr *p; /* Expression for a single result column */ @@ -1659,11 +1659,12 @@ int sqlite3ColumnsFromExprList( for(k=nName-1; k>1 && sqlite3Isdigit(zName[k]); k--){} if( k>=0 && zName[k]==':' ) nName = k; zName[nName] = 0; - zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt); + zNewName = sqlite3MPrintf(db, "%s:%u", zName, ++cnt); sqlite3DbFree(db, zName); zName = zNewName; j = -1; if( zName==0 ) break; + if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } } pCol->zName = zName; From 0315e3cc140683a814f9d0069d6972669332388c Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 14 Nov 2015 20:52:43 +0000 Subject: [PATCH 35/55] Use a hash table to improve the preformance of column name uniqueness checking. FossilOrigin-Name: 5b08f29f458c600401860c7d70d8174cf61e69f8 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 38 ++++++++++++++++++-------------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index abc88a6886..201d4ffc8c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\srandomness\sto\sprevent\sshowness\sin\sthe\sgenerated-column-name\suniqueness\nchecking. -D 2015-11-14T16:47:23.463 +C Use\sa\shash\stable\sto\simprove\sthe\spreformance\sof\scolumn\sname\suniqueness\schecking. +D 2015-11-14T20:52:43.849 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -339,7 +339,7 @@ F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 7ef4a946893f171920843d4d8c30c2544a060fbe +F src/select.c d5878c33d9bb66c82b2b7773731bf290248763bb F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P dfd6d9f4fbe902086f9158dfa5f37e781765a683 -R f75d239f0c3cc028f9c3bdc5405581af +P 6266712968a2cdcd6f5a3007d60c2cf1b3faf912 +R 7d9535e63307ca117e4aa92e0ee4dc2c U drh -Z df73d438cc87e48519d39f020060cfa5 +Z d8b237007fcc1a03b5ce77808531ddb1 diff --git a/manifest.uuid b/manifest.uuid index ea0fe67b11..8463d0d8ec 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6266712968a2cdcd6f5a3007d60c2cf1b3faf912 \ No newline at end of file +5b08f29f458c600401860c7d70d8174cf61e69f8 \ No newline at end of file diff --git a/src/select.c b/src/select.c index afebf87ba4..802e75eeca 100644 --- a/src/select.c +++ b/src/select.c @@ -1602,7 +1602,9 @@ int sqlite3ColumnsFromExprList( Expr *p; /* Expression for a single result column */ char *zName; /* Column name */ int nName; /* Size of name in zName[] */ + Hash ht; /* Hash table of column names */ + sqlite3HashInit(&ht); if( pEList ){ nCol = pEList->nExpr; aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol); @@ -1614,7 +1616,7 @@ int sqlite3ColumnsFromExprList( *pnCol = nCol; *paCol = aCol; - for(i=0, pCol=aCol; imallocFailed; i++, pCol++){ /* Get an appropriate name for the column */ p = sqlite3ExprSkipCollate(pEList->a[i].pExpr); @@ -1643,32 +1645,28 @@ int sqlite3ColumnsFromExprList( zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan); } } - if( db->mallocFailed ){ - sqlite3DbFree(db, zName); - break; - } /* Make sure the column name is unique. If the name is not unique, ** append an integer to the name so that it becomes unique. */ - nName = sqlite3Strlen30(zName); - for(j=cnt=0; j1 && sqlite3Isdigit(zName[k]); k--){} - if( k>=0 && zName[k]==':' ) nName = k; - zName[nName] = 0; - zNewName = sqlite3MPrintf(db, "%s:%u", zName, ++cnt); - sqlite3DbFree(db, zName); - zName = zNewName; - j = -1; - if( zName==0 ) break; - if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); - } + cnt = 0; + while( zName && sqlite3HashFind(&ht, zName)!=0 ){ + char *zNewName; + nName = sqlite3Strlen30(zName); + for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} + if( zName[j]==':' ) nName = j; + zName[nName] = 0; + zNewName = sqlite3MPrintf(db, "%s:%u", zName, ++cnt); + sqlite3DbFree(db, zName); + zName = zNewName; + if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; + if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ + db->mallocFailed = 1; + } } + sqlite3HashClear(&ht); if( db->mallocFailed ){ for(j=0; j Date: Sat, 14 Nov 2015 22:04:22 +0000 Subject: [PATCH 36/55] Code simplification in sqlite3ColumnsFromExprList(). Update the %z format code so that it works with buffers obtained from sqlite3DbMalloc(). Add a testcase for the slow column name uniquifier. FossilOrigin-Name: 9272426057b6cb2d913519ff4c97aa6e211f7d51 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/printf.c | 2 +- src/select.c | 15 +++++---------- test/misc1.test | 9 +++++++++ 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 201d4ffc8c..8371747542 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sa\shash\stable\sto\simprove\sthe\spreformance\sof\scolumn\sname\suniqueness\schecking. -D 2015-11-14T20:52:43.849 +C Code\ssimplification\sin\ssqlite3ColumnsFromExprList().\s\sUpdate\sthe\s%z\sformat\ncode\sso\sthat\sit\sworks\swith\sbuffers\sobtained\sfrom\ssqlite3DbMalloc().\s\sAdd\sa\ntestcase\sfor\sthe\sslow\scolumn\sname\suniquifier. +D 2015-11-14T22:04:22.826 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -335,11 +335,11 @@ F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 F src/pragma.c f3e7147299ca05ef4304a36f1fd6e002729c72c6 F src/pragma.h 3d94aebbebd2089899fecc01909bf2608b39507d F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 -F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a +F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c d5878c33d9bb66c82b2b7773731bf290248763bb +F src/select.c 1854c85ba100a9f76bf8cf47d4ae59a2ae799ef0 F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -875,7 +875,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 3f1c479c5a093a6280f378c0fbff1c2701486660 +F test/misc1.test d614a334b777b1aded6873d76a3560329b819fea F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 0d8be3466adf123a7791a66ba2bc8e8d229e87f3 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6266712968a2cdcd6f5a3007d60c2cf1b3faf912 -R 7d9535e63307ca117e4aa92e0ee4dc2c +P 5b08f29f458c600401860c7d70d8174cf61e69f8 +R 4914cc3a8ed45c6aa86aea7a39b8ba36 U drh -Z d8b237007fcc1a03b5ce77808531ddb1 +Z 01b4ba6f26cc34a60c8e736ca788d377 diff --git a/manifest.uuid b/manifest.uuid index 8463d0d8ec..2212eca514 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5b08f29f458c600401860c7d70d8174cf61e69f8 \ No newline at end of file +9272426057b6cb2d913519ff4c97aa6e211f7d51 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index dba928d102..9caeef8ff7 100644 --- a/src/printf.c +++ b/src/printf.c @@ -726,7 +726,7 @@ void sqlite3VXPrintf( if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); if( zExtra ){ - sqlite3_free(zExtra); + sqlite3DbFree(pAccum->db, zExtra); zExtra = 0; } }/* End for loop over the format string */ diff --git a/src/select.c b/src/select.c index 802e75eeca..2265d4c9f9 100644 --- a/src/select.c +++ b/src/select.c @@ -1622,7 +1622,6 @@ int sqlite3ColumnsFromExprList( p = sqlite3ExprSkipCollate(pEList->a[i].pExpr); if( (zName = pEList->a[i].zName)!=0 ){ /* If the column contains an "AS " phrase, use as the name */ - zName = sqlite3DbStrDup(db, zName); }else{ Expr *pColExpr = p; /* The expression that is the result column name */ Table *pTab; /* Table associated with this expression */ @@ -1635,30 +1634,26 @@ int sqlite3ColumnsFromExprList( int iCol = pColExpr->iColumn; pTab = pColExpr->pTab; if( iCol<0 ) iCol = pTab->iPKey; - zName = sqlite3MPrintf(db, "%s", - iCol>=0 ? pTab->aCol[iCol].zName : "rowid"); + zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid"; }else if( pColExpr->op==TK_ID ){ assert( !ExprHasProperty(pColExpr, EP_IntValue) ); - zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken); + zName = pColExpr->u.zToken; }else{ /* Use the original text of the column expression as its name */ - zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan); + zName = pEList->a[i].zSpan; } } + zName = sqlite3MPrintf(db, "%s", zName); /* Make sure the column name is unique. If the name is not unique, ** append an integer to the name so that it becomes unique. */ cnt = 0; while( zName && sqlite3HashFind(&ht, zName)!=0 ){ - char *zNewName; nName = sqlite3Strlen30(zName); for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} if( zName[j]==':' ) nName = j; - zName[nName] = 0; - zNewName = sqlite3MPrintf(db, "%s:%u", zName, ++cnt); - sqlite3DbFree(db, zName); - zName = zNewName; + zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; diff --git a/test/misc1.test b/test/misc1.test index 25e9bd813e..6e0abcd108 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -701,4 +701,13 @@ do_test misc1-24.0 { list [catch { sqlite3_prepare_v2 db ! -1 dummy } msg] $msg } {1 {(1) unrecognized token: "!}} +# The following query (provided by Kostya Serebryany) used to take 25 +# minutes to prepare. This has been speeded up to about 250 milliseconds. +# +do_catchsql_test misc1-25.0 { +SELECT-1 UNION SELECT 5 UNION SELECT 0 UNION SElECT*from(SELECT-5) UNION SELECT*from(SELECT-0) UNION SELECT:SELECT-0 UNION SELECT-1 UNION SELECT 1 UNION SELECT 1 ORDER BY S in(WITH K AS(WITH K AS(select'CREINDERcharREADEVIRTUL5TABLECONFLICT !1 USIN'' MFtOR(b38q,eWITH K AS(selectCREATe TABLE t0(a,b,c,d,e, PRIMARY KEY(a,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,b,c,d,c,a,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d'CEIl,k'',ab, g, a,b,o11b, i'nEX/charREDE IVT LR!VABLt5SG',N ,N in rement,l_vacuum,M&U,'te3(''5l' a,bB,b,l*e)SELECT:SELECT, *,*,*from(( SELECT +$group,:conc ap0,1)fro,(select"",:PBAG,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,c,d,c,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d, foreign_keysc,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,c,d,c,a,b,d,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,c,a,b,b,c,d,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,d,c,e,d,d,c,a,b,b,c,c,a,b,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,bb,b,E,d,c,d,c,b,c,d,c,d,c,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,a,b,c,e,d,d,c,a,b,b,c,d,d,c,a,b,c,e,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,c,d,c,a,b,d,d,c,a,a,b,d,d,c,a,b,b,c,d,c,a,b,e,e,d,b,c,d,c,a,b,b,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,c,a,b,c,e,d,d,c,a,b,b,c,d,c,d,c,a,b,c,e,c,d,c,a,b,b,c,d,MAato_aecSELEC,+?b," "O,"i","a",""b ,5 ))KEY)SELECT*FROM((k()reaC,k,K) eA,k '' )t ,K M); +} {1 {too many columns in result set}} + + finish_test From f7ee8965a5f36fd6dbd9469784ab6e539cea950d Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 15 Nov 2015 11:13:49 +0000 Subject: [PATCH 37/55] Fix the column name uniquifier so that it works with zero-length column names. FossilOrigin-Name: 791761ebac26c82ab67bdf867117ec5b5d8b20b0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8371747542..7784ab59fa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Code\ssimplification\sin\ssqlite3ColumnsFromExprList().\s\sUpdate\sthe\s%z\sformat\ncode\sso\sthat\sit\sworks\swith\sbuffers\sobtained\sfrom\ssqlite3DbMalloc().\s\sAdd\sa\ntestcase\sfor\sthe\sslow\scolumn\sname\suniquifier. -D 2015-11-14T22:04:22.826 +C Fix\sthe\scolumn\sname\suniquifier\sso\sthat\sit\sworks\swith\szero-length\scolumn\snames. +D 2015-11-15T11:13:49.647 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -339,7 +339,7 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 1854c85ba100a9f76bf8cf47d4ae59a2ae799ef0 +F src/select.c 4c58ae319df6862e5ea237e757b5d317c4491798 F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5b08f29f458c600401860c7d70d8174cf61e69f8 -R 4914cc3a8ed45c6aa86aea7a39b8ba36 +P 9272426057b6cb2d913519ff4c97aa6e211f7d51 +R a974c67769be53d36ddc37d671cc0607 U drh -Z 01b4ba6f26cc34a60c8e736ca788d377 +Z f40155003991429935f69f917db4e724 diff --git a/manifest.uuid b/manifest.uuid index 2212eca514..571a15823a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9272426057b6cb2d913519ff4c97aa6e211f7d51 \ No newline at end of file +791761ebac26c82ab67bdf867117ec5b5d8b20b0 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 2265d4c9f9..126d4cc282 100644 --- a/src/select.c +++ b/src/select.c @@ -1651,8 +1651,10 @@ int sqlite3ColumnsFromExprList( cnt = 0; while( zName && sqlite3HashFind(&ht, zName)!=0 ){ nName = sqlite3Strlen30(zName); - for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} - if( zName[j]==':' ) nName = j; + if( nName>0 ){ + for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} + if( zName[j]==':' ) nName = j; + } zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } From 3fd415b2bf46be65360579d1b84d4dd20b2dbbf7 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 16 Nov 2015 08:54:10 +0000 Subject: [PATCH 38/55] In the shell tool, avoid testing if (sqlite3_vfs.xGetCurrentInt64) is NULL for a version 1 VFS. This field is only defined for version 2 and greater. FossilOrigin-Name: ad5fcaa583ef743d143b6c030e0d78019709fe71 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 7784ab59fa..fb4d5c08eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scolumn\sname\suniquifier\sso\sthat\sit\sworks\swith\szero-length\scolumn\snames. -D 2015-11-15T11:13:49.647 +C In\sthe\sshell\stool,\savoid\stesting\sif\s(sqlite3_vfs.xGetCurrentInt64)\sis\sNULL\sfor\sa\sversion\s1\sVFS.\sThis\sfield\sis\sonly\sdefined\sfor\sversion\s2\sand\sgreater. +D 2015-11-16T08:54:10.841 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -340,7 +340,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 4c58ae319df6862e5ea237e757b5d317c4491798 -F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830 +F src/shell.c 0092cd4e1da5322b7bc35bedbec1f0dea627451e F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9272426057b6cb2d913519ff4c97aa6e211f7d51 -R a974c67769be53d36ddc37d671cc0607 -U drh -Z f40155003991429935f69f917db4e724 +P 791761ebac26c82ab67bdf867117ec5b5d8b20b0 +R a635725b446415a63ce3c96185f06f0a +U dan +Z ecc9df21b64c8edc0682f60d01379dbf diff --git a/manifest.uuid b/manifest.uuid index 571a15823a..19652556ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -791761ebac26c82ab67bdf867117ec5b5d8b20b0 \ No newline at end of file +ad5fcaa583ef743d143b6c030e0d78019709fe71 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 7c53995799..84f693300f 100644 --- a/src/shell.c +++ b/src/shell.c @@ -165,7 +165,7 @@ static sqlite3_int64 timeOfDay(void){ static sqlite3_vfs *clockVfs = 0; sqlite3_int64 t; if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); - if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){ + if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ clockVfs->xCurrentTimeInt64(clockVfs, &t); }else{ double r; From e4e416e87ea95696a8630e37d09836e2adf7753c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 16 Nov 2015 15:28:54 +0000 Subject: [PATCH 39/55] Add testfixture command "vfs_current_time_int64". Returns the value returned by the xCurrentTimeInt64 method of the default VFS. FossilOrigin-Name: f79d5b1853b3d4316ea08de8206ffca33e44c395 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/test1.c | 25 +++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index fb4d5c08eb..331799161e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sshell\stool,\savoid\stesting\sif\s(sqlite3_vfs.xGetCurrentInt64)\sis\sNULL\sfor\sa\sversion\s1\sVFS.\sThis\sfield\sis\sonly\sdefined\sfor\sversion\s2\sand\sgreater. -D 2015-11-16T08:54:10.841 +C Add\stestfixture\scommand\s"vfs_current_time_int64".\sReturns\sthe\svalue\sreturned\sby\sthe\sxCurrentTimeInt64\smethod\sof\sthe\sdefault\sVFS. +D 2015-11-16T15:28:54.851 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -349,7 +349,7 @@ F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e F src/tclsqlite.c d9439b6a910985b7fff43ba6756bcef00de22649 -F src/test1.c 05df2a9e4f483b2fb642162209e3aeb11c24b44f +F src/test1.c 4004bcc1b3b361a9137acd1d875599ecbdd6f961 F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b F src/test3.c a8887dabbbee3059af338f20d290084a63ed1b0f F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 791761ebac26c82ab67bdf867117ec5b5d8b20b0 -R a635725b446415a63ce3c96185f06f0a +P ad5fcaa583ef743d143b6c030e0d78019709fe71 +R bad7a2932fd1612d76a527d68176f4b8 U dan -Z ecc9df21b64c8edc0682f60d01379dbf +Z d6f5979512fe258a491a417c706992f9 diff --git a/manifest.uuid b/manifest.uuid index 19652556ca..6762a846fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad5fcaa583ef743d143b6c030e0d78019709fe71 \ No newline at end of file +f79d5b1853b3d4316ea08de8206ffca33e44c395 \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index 43feb2dc2d..186e4e4684 100644 --- a/src/test1.c +++ b/src/test1.c @@ -2238,7 +2238,6 @@ static int test_config_sqllog( int objc, Tcl_Obj *CONST objv[] ){ - sqlite3_stmt *pStmt; /* First argument */ if( objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, ""); return TCL_ERROR; @@ -2248,6 +2247,28 @@ static int test_config_sqllog( } #endif +/* +** Usage: vfs_current_time_int64 +** +** Return the value returned by the default VFS's xCurrentTimeInt64 method. +*/ +static int vfsCurrentTimeInt64( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + i64 t; + sqlite3_vfs *pVfs = sqlite3_vfs_find(0); + if( objc!=1 ){ + Tcl_WrongNumArgs(interp, 1, objv, ""); + return TCL_ERROR; + } + pVfs->xCurrentTimeInt64(pVfs, &t); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(t)); + return TCL_OK; +} + /* ** Usage: sqlite3_next_stmt DB STMT ** @@ -7061,7 +7082,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ #ifdef SQLITE_ENABLE_SQLLOG { "sqlite3_config_sqllog", test_config_sqllog, 0 }, #endif - + { "vfs_current_time_int64", vfsCurrentTimeInt64, 0 }, }; static int bitmask_size = sizeof(Bitmask)*8; static int longdouble_size = sizeof(LONGDOUBLE_TYPE); From 81c7811fe7b7a3650f57c75b4357c2e4e225d07f Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 17 Nov 2015 19:16:39 +0000 Subject: [PATCH 40/55] Fix harmless compiler warning. FossilOrigin-Name: eea26b6caea37422c9b46a7a3a538b0c9575f392 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/mkkeywordhash.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 331799161e..925e6dad3c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stestfixture\scommand\s"vfs_current_time_int64".\sReturns\sthe\svalue\sreturned\sby\sthe\sxCurrentTimeInt64\smethod\sof\sthe\sdefault\sVFS. -D 2015-11-16T15:28:54.851 +C Fix\sharmless\scompiler\swarning. +D 2015-11-17T19:16:39.306 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -1361,7 +1361,7 @@ F tool/lempar.c 3ec1463a034b37d87d782be5f6b8b10a3b1ecbe7 F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862 F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6 F tool/mkautoconfamal.sh 4bdf61548a143e5977bd86ab93d68b694d10c8fa -F tool/mkkeywordhash.c 37f9c2e62c31384b697ede8825e2d344e98db22c +F tool/mkkeywordhash.c 06ec0b78bd4fa68c12d90ef2bdfe76b039133ff8 F tool/mkopcodec.tcl edde8adc42621b5e598127f8cdc6d52cfe21f52b F tool/mkopcodeh.tcl e04177031532b7aa9379ded50e820231ac4abd6e F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ad5fcaa583ef743d143b6c030e0d78019709fe71 -R bad7a2932fd1612d76a527d68176f4b8 -U dan -Z d6f5979512fe258a491a417c706992f9 +P f79d5b1853b3d4316ea08de8206ffca33e44c395 +R 2de2a0c3dc7ccab5c10590e17dcb5ba5 +U mistachkin +Z 23c5ff0945aadd15158110acb76ae975 diff --git a/manifest.uuid b/manifest.uuid index 6762a846fd..d48bc97cdb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f79d5b1853b3d4316ea08de8206ffca33e44c395 \ No newline at end of file +eea26b6caea37422c9b46a7a3a538b0c9575f392 \ No newline at end of file diff --git a/tool/mkkeywordhash.c b/tool/mkkeywordhash.c index e4d393e3fa..003ed7d66e 100644 --- a/tool/mkkeywordhash.c +++ b/tool/mkkeywordhash.c @@ -328,7 +328,7 @@ static Keyword *findById(int id){ ** output. */ int main(int argc, char **argv){ - int i, j, k, h, m; + int i, j, k, h; int bestSize, bestCount; int count; int nChar; From bfe8bd5a5ed89205b0174e6d5174795002c55fab Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 17 Nov 2015 19:17:14 +0000 Subject: [PATCH 41/55] Fix uninitialized variable in the command line shell. FossilOrigin-Name: dc2ac024d31a898bbc3e7fc824d806e63e993234 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 925e6dad3c..cf927a2229 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarning. -D 2015-11-17T19:16:39.306 +C Fix\suninitialized\svariable\sin\sthe\scommand\sline\sshell. +D 2015-11-17T19:17:14.024 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -340,7 +340,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 4c58ae319df6862e5ea237e757b5d317c4491798 -F src/shell.c 0092cd4e1da5322b7bc35bedbec1f0dea627451e +F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f79d5b1853b3d4316ea08de8206ffca33e44c395 -R 2de2a0c3dc7ccab5c10590e17dcb5ba5 +P eea26b6caea37422c9b46a7a3a538b0c9575f392 +R cc64f84be685bae79d5a153d40e5e973 U mistachkin -Z 23c5ff0945aadd15158110acb76ae975 +Z 3d10a1734b384a6c71eab8ba5f61ca6f diff --git a/manifest.uuid b/manifest.uuid index d48bc97cdb..b83646e075 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eea26b6caea37422c9b46a7a3a538b0c9575f392 \ No newline at end of file +dc2ac024d31a898bbc3e7fc824d806e63e993234 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 84f693300f..d2f9ca500a 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2560,7 +2560,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ { "schema size:", "SELECT total(length(sql)) FROM %s" }, }; - sqlite3_file *pFile; + sqlite3_file *pFile = 0; int i; char *zSchemaTab; char *zDb = nArg>=2 ? azArg[1] : "main"; From fe33e39ba6236cab021c6615edc14ca113b26b20 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 17 Nov 2015 20:56:06 +0000 Subject: [PATCH 42/55] When using mmap mode on unix, use a read-only mapping by default. Write to the database file using write(). Unless SQLITE_MMAP_READWRITE is defined, in which case use a read/write mapping and write into the file using memcpy(). FossilOrigin-Name: 67c5d3c646c8198c8637069140aca952b802df25 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index cf927a2229..41d7945788 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\suninitialized\svariable\sin\sthe\scommand\sline\sshell. -D 2015-11-17T19:17:14.024 +C When\susing\smmap\smode\son\sunix,\suse\sa\sread-only\smapping\sby\sdefault.\sWrite\sto\sthe\sdatabase\sfile\susing\swrite().\sUnless\sSQLITE_MMAP_READWRITE\sis\sdefined,\sin\swhich\scase\suse\sa\sread/write\smapping\sand\swrite\sinto\sthe\sfile\susing\smemcpy(). +D 2015-11-17T20:56:06.787 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -323,7 +323,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c cf72e06e15839ebe7121e01d3eebf256c039b0ca +F src/os_unix.c eb24e0340fbe3cfd0eabfb15a71476953e54fa73 F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P eea26b6caea37422c9b46a7a3a538b0c9575f392 -R cc64f84be685bae79d5a153d40e5e973 -U mistachkin -Z 3d10a1734b384a6c71eab8ba5f61ca6f +P dc2ac024d31a898bbc3e7fc824d806e63e993234 +R 84fe0eec79106a76020c4d6d9eb9fda8 +U dan +Z e25a64e1e3c268c6ee1a9c7b42e3911f diff --git a/manifest.uuid b/manifest.uuid index b83646e075..e65363fd12 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc2ac024d31a898bbc3e7fc824d806e63e993234 \ No newline at end of file +67c5d3c646c8198c8637069140aca952b802df25 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index b322d238e8..3d4524296b 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3349,7 +3349,7 @@ static int unixWrite( } #endif -#if SQLITE_MAX_MMAP_SIZE>0 +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 /* Deal with as much of this write request as possible by transfering ** data from the memory mapping using memcpy(). */ if( offsetmmapSize ){ @@ -4774,7 +4774,9 @@ static void unixRemapfile( assert( pFd->mmapSizeActual>=pFd->mmapSize ); assert( MAP_FAILED!=0 ); +#ifdef SQLITE_MMAP_READWRITE if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; +#endif if( pOrig ){ #if HAVE_MREMAP From c88cd1375358a4adbc52f45a8c81d20008c8622a Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 17 Nov 2015 21:42:32 +0000 Subject: [PATCH 43/55] When using mmap mode on Win32, use a read-only mapping by default. Write to the database file using WriteFile(). Unless SQLITE_MMAP_READWRITE is defined, in which case use a read/write mapping and write into the file using memcpy(). FossilOrigin-Name: 4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_win.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 41d7945788..3977bc21ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\susing\smmap\smode\son\sunix,\suse\sa\sread-only\smapping\sby\sdefault.\sWrite\sto\sthe\sdatabase\sfile\susing\swrite().\sUnless\sSQLITE_MMAP_READWRITE\sis\sdefined,\sin\swhich\scase\suse\sa\sread/write\smapping\sand\swrite\sinto\sthe\sfile\susing\smemcpy(). -D 2015-11-17T20:56:06.787 +C When\susing\smmap\smode\son\sWin32,\suse\sa\sread-only\smapping\sby\sdefault.\sWrite\sto\sthe\sdatabase\sfile\susing\sWriteFile().\sUnless\sSQLITE_MMAP_READWRITE\sis\sdefined,\sin\swhich\scase\suse\sa\sread/write\smapping\sand\swrite\sinto\sthe\sfile\susing\smemcpy(). +D 2015-11-17T21:42:32.347 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -324,7 +324,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c eb24e0340fbe3cfd0eabfb15a71476953e54fa73 -F src/os_win.c 1716291e5ec2dbfc5a1fe0b32182030f1f7d8acf +F src/os_win.c 2d77dab5c555a18c0aff379c6a692fc3499044d9 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e F src/pager.h 87c4118a71ba3965184148b379a6d93179071091 @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P dc2ac024d31a898bbc3e7fc824d806e63e993234 -R 84fe0eec79106a76020c4d6d9eb9fda8 -U dan -Z e25a64e1e3c268c6ee1a9c7b42e3911f +P 67c5d3c646c8198c8637069140aca952b802df25 +R d582abf646ba97a05dcf7955b3e63a88 +U mistachkin +Z 3d22a16f35aefddddac7e9c38e41c6d4 diff --git a/manifest.uuid b/manifest.uuid index e65363fd12..f18cecb173 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -67c5d3c646c8198c8637069140aca952b802df25 \ No newline at end of file +4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 251107528b..9ae40e22af 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2602,7 +2602,7 @@ static int winWrite( "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, pFile->h, pBuf, amt, offset, pFile->locktype)); -#if SQLITE_MAX_MMAP_SIZE>0 +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 /* Deal with as much of this write request as possible by transfering ** data from the memory mapping using memcpy(). */ if( offsetmmapSize ){ @@ -4096,10 +4096,12 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){ DWORD flags = FILE_MAP_READ; winUnmapfile(pFd); +#ifdef SQLITE_MMAP_READWRITE if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ protect = PAGE_READWRITE; flags |= FILE_MAP_WRITE; } +#endif #if SQLITE_OS_WINRT pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); #elif defined(SQLITE_WIN32_HAS_WIDE) From f0c9145a3609c17ba53aed561657c53be343e2e8 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 18 Nov 2015 18:43:15 +0000 Subject: [PATCH 44/55] If a table column name begins with "__hidden__" then do not include that column in "*" expansions in SELECT statements, nor fill in that column in an INSERT INTO that omits the column list. This branch is a proof-of-concept only and is not intended to ever be merged into trunk. FossilOrigin-Name: 2dbffb3a3b20dba7d7d86c8ad2e34633f616c78a --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/build.c | 3 +++ src/insert.c | 9 ++++----- src/select.c | 3 ++- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 3977bc21ce..067b1c8ee5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\susing\smmap\smode\son\sWin32,\suse\sa\sread-only\smapping\sby\sdefault.\sWrite\sto\sthe\sdatabase\sfile\susing\sWriteFile().\sUnless\sSQLITE_MMAP_READWRITE\sis\sdefined,\sin\swhich\scase\suse\sa\sread/write\smapping\sand\swrite\sinto\sthe\sfile\susing\smemcpy(). -D 2015-11-17T21:42:32.347 +C If\sa\stable\scolumn\sname\sbegins\swith\s"__hidden__"\sthen\sdo\snot\sinclude\sthat\ncolumn\sin\s"*"\sexpansions\sin\sSELECT\sstatements,\snor\sfill\sin\sthat\scolumn\sin\nan\sINSERT\sINTO\sthat\somits\sthe\scolumn\slist.\s\sThis\sbranch\sis\sa\s\nproof-of-concept\sonly\sand\sis\snot\sintended\sto\sever\sbe\smerged\sinto\strunk. +D 2015-11-18T18:43:15.107 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -285,7 +285,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c d3bdd8462a86492e2ebc9aca4a0168429017de25 F src/btree.h 2d76dee44704c47eed323356a758662724b674a0 F src/btreeInt.h 3ab435ed27adea54d040584b0bcc488ee7db1e38 -F src/build.c ca574d33ffb1763cfd2979383f4d507095bfbe19 +F src/build.c a62cef335439eca53f8b0b12fae4b6925ff5b980 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a @@ -300,7 +300,7 @@ F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 419a947f27ce2da18eebf440a5aa80cc825defae +F src/insert.c 0b376795f688aafd264ff0c5a6538e5a4cc6c213 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 @@ -339,7 +339,7 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 4c58ae319df6862e5ea237e757b5d317c4491798 +F src/select.c 2fa981f5bc793fb6b48f013c82662bcc969e3af5 F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1403,7 +1403,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 67c5d3c646c8198c8637069140aca952b802df25 -R d582abf646ba97a05dcf7955b3e63a88 -U mistachkin -Z 3d22a16f35aefddddac7e9c38e41c6d4 +P 4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 +R 935d388c6bd4428c029b70918e7ca51f +T *branch * hidden-columns-in-tables +T *sym-hidden-columns-in-tables * +T -sym-trunk * +U drh +Z 5682a263851a58e238bd47d4c8fd6809 diff --git a/manifest.uuid b/manifest.uuid index f18cecb173..57644a3da5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 \ No newline at end of file +2dbffb3a3b20dba7d7d86c8ad2e34633f616c78a \ No newline at end of file diff --git a/src/build.c b/src/build.c index 8cb2d44ac7..9a4a0cc8d4 100644 --- a/src/build.c +++ b/src/build.c @@ -1104,6 +1104,9 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){ pCol = &p->aCol[p->nCol]; memset(pCol, 0, sizeof(p->aCol[0])); pCol->zName = z; + if( sqlite3_strnicmp(z, "__hidden__", 10)==0 ){ + pCol->colFlags |= COLFLAG_HIDDEN; + } /* If there is no type specified, columns have the default affinity ** 'BLOB'. If there is a type specified, then sqlite3AddColumnType() will diff --git a/src/insert.c b/src/insert.c index 3d213a8d37..2c159fd2bc 100644 --- a/src/insert.c +++ b/src/insert.c @@ -736,10 +736,8 @@ void sqlite3Insert( /* Make sure the number of columns in the source data matches the number ** of columns to be inserted into the table. */ - if( IsVirtual(pTab) ){ - for(i=0; inCol; i++){ - nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0); - } + for(i=0; inCol; i++){ + nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0); } if( pColumn==0 && nColumn && nColumn!=(pTab->nCol-nHidden) ){ sqlite3ErrorMsg(pParse, @@ -934,7 +932,8 @@ void sqlite3Insert( } if( pColumn==0 ){ if( IsHiddenColumn(&pTab->aCol[i]) ){ - assert( IsVirtual(pTab) ); + assert( IsVirtual(pTab) + || sqlite3_strnicmp(pTab->aCol[i].zName,"__hidden__",10)==0 ); j = -1; nHidden++; }else{ diff --git a/src/select.c b/src/select.c index 126d4cc282..41a3c50a58 100644 --- a/src/select.c +++ b/src/select.c @@ -4365,7 +4365,8 @@ static int selectExpander(Walker *pWalker, Select *p){ ** result-set list. */ if( IsHiddenColumn(&pTab->aCol[j]) ){ - assert(IsVirtual(pTab)); + assert( IsVirtual(pTab) + || sqlite3_strnicmp(pTab->aCol[j].zName,"__hidden__", 10)==0 ); continue; } tableSeen = 1; From d1ce65fc76027689e7627869e70afcb7c377df77 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 18 Nov 2015 20:07:12 +0000 Subject: [PATCH 45/55] Add a test for the __hidden__ hack on this branch. FossilOrigin-Name: ebf4bbffec58111a670c46a9eb469bfd2440b0b1 --- manifest | 16 +++++++-------- manifest.uuid | 2 +- test/hidden.test | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 test/hidden.test diff --git a/manifest b/manifest index 067b1c8ee5..a66f8fa512 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sa\stable\scolumn\sname\sbegins\swith\s"__hidden__"\sthen\sdo\snot\sinclude\sthat\ncolumn\sin\s"*"\sexpansions\sin\sSELECT\sstatements,\snor\sfill\sin\sthat\scolumn\sin\nan\sINSERT\sINTO\sthat\somits\sthe\scolumn\slist.\s\sThis\sbranch\sis\sa\s\nproof-of-concept\sonly\sand\sis\snot\sintended\sto\sever\sbe\smerged\sinto\strunk. -D 2015-11-18T18:43:15.107 +C Add\sa\stest\sfor\sthe\s__hidden__\shack\son\sthis\sbranch. +D 2015-11-18T20:07:12.847 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -762,6 +762,7 @@ F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 +F test/hidden.test b48497a68ad5fc428533e08df7f3743ef919e168 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/ieee754.test 118b665a97a8df0e8f2fbdb07d113e596f4a6b53 @@ -1403,10 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 -R 935d388c6bd4428c029b70918e7ca51f -T *branch * hidden-columns-in-tables -T *sym-hidden-columns-in-tables * -T -sym-trunk * -U drh -Z 5682a263851a58e238bd47d4c8fd6809 +P 2dbffb3a3b20dba7d7d86c8ad2e34633f616c78a +R 83cf7865dae52d6bb8a186c1aa991823 +U dan +Z 1a0e4ed515d3bb3eb2db7f71110d453e diff --git a/manifest.uuid b/manifest.uuid index 57644a3da5..433cf093a2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2dbffb3a3b20dba7d7d86c8ad2e34633f616c78a \ No newline at end of file +ebf4bbffec58111a670c46a9eb469bfd2440b0b1 \ No newline at end of file diff --git a/test/hidden.test b/test/hidden.test new file mode 100644 index 0000000000..2bc253c903 --- /dev/null +++ b/test/hidden.test @@ -0,0 +1,51 @@ +# 2015 November 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test the __hidden__ hack. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix hidden + +do_execsql_test 1.1 { + CREATE TABLE t1(__hidden__a, b); + INSERT INTO t1 VALUES('1'); + INSERT INTO t1(__hidden__a, b) VALUES('x', 'y'); +} {} + +do_execsql_test 1.2 { + SELECT * FROM t1; +} {1 y} + +do_execsql_test 1.3 { + SELECT __hidden__a, * FROM t1; +} {{} 1 x y} + +#do_execsql_test 2.1 { + #CREATE TABLE x1(a, b, c); + #INSERT INTO x1 VALUES(1, 2, 3); + #CREATE VIEW v1(a, b, __hidden__c) AS SELECT a, b, c FROM x1; + #SELECT * FROM v1; +#} {1 2} + +do_execsql_test 2.2 { + PRAGMA table_info(v1); +} { +0 a {} 0 {} 0 +1 b {} 0 {} 0 +2 __hidden__c {} 0 {} 0 +} + + + + +finish_test From 6aed239acce616ddcf9c365cb8c67c7cce2bc56c Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 18 Nov 2015 20:57:50 +0000 Subject: [PATCH 46/55] Honor the "__hidden__" prefix on the columns of views. FossilOrigin-Name: 3071ba2bdbda7018d0a285eceb04b8527209ec1e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 8 ++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index a66f8fa512..34c001b3c7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\sfor\sthe\s__hidden__\shack\son\sthis\sbranch. -D 2015-11-18T20:07:12.847 +C Honor\sthe\s"__hidden__"\sprefix\son\sthe\scolumns\sof\sviews. +D 2015-11-18T20:57:50.853 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -339,7 +339,7 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 2fa981f5bc793fb6b48f013c82662bcc969e3af5 +F src/select.c 7996cf4b5730e80dd44a080019736e70eaef4377 F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2dbffb3a3b20dba7d7d86c8ad2e34633f616c78a -R 83cf7865dae52d6bb8a186c1aa991823 -U dan -Z 1a0e4ed515d3bb3eb2db7f71110d453e +P ebf4bbffec58111a670c46a9eb469bfd2440b0b1 +R 573da8ac7642b42a39f669032b202b69 +U drh +Z f6d6ca2e7f0fda6cda94eef3aaa048a9 diff --git a/manifest.uuid b/manifest.uuid index 433cf093a2..579d6c185f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ebf4bbffec58111a670c46a9eb469bfd2440b0b1 \ No newline at end of file +3071ba2bdbda7018d0a285eceb04b8527209ec1e \ No newline at end of file diff --git a/src/select.c b/src/select.c index 41a3c50a58..f2ea26eaf2 100644 --- a/src/select.c +++ b/src/select.c @@ -1659,8 +1659,12 @@ int sqlite3ColumnsFromExprList( if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; - if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ - db->mallocFailed = 1; + if( zName ){ + if( sqlite3HashInsert(&ht, zName, pCol)==pCol ){ + db->mallocFailed = 1; + }else if( sqlite3_strnicmp(zName, "__hidden__", 10)==0 ){ + pCol->colFlags |= COLFLAG_HIDDEN; + } } } sqlite3HashClear(&ht); From ab5a8ee3e4087c3169e1dd540208f2b6a2a6b01f Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 18 Nov 2015 20:59:47 +0000 Subject: [PATCH 47/55] Add tests for views to hidden.test. FossilOrigin-Name: 27d4b6f5756c7b19c00c95d46a77280c8b6f03a4 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/hidden.test | 46 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 34c001b3c7..e36c1904ee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Honor\sthe\s"__hidden__"\sprefix\son\sthe\scolumns\sof\sviews. -D 2015-11-18T20:57:50.853 +C Add\stests\sfor\sviews\sto\shidden.test. +D 2015-11-18T20:59:47.725 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -762,7 +762,7 @@ F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 -F test/hidden.test b48497a68ad5fc428533e08df7f3743ef919e168 +F test/hidden.test e8c7623994991db181310fc876e16a0c27156a3d F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/ieee754.test 118b665a97a8df0e8f2fbdb07d113e596f4a6b53 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ebf4bbffec58111a670c46a9eb469bfd2440b0b1 -R 573da8ac7642b42a39f669032b202b69 -U drh -Z f6d6ca2e7f0fda6cda94eef3aaa048a9 +P 3071ba2bdbda7018d0a285eceb04b8527209ec1e +R 2baa1dc83be9c7315702795a7e6fe14b +U dan +Z 4e931d86c42c505d1f09dcba4c9d7ade diff --git a/manifest.uuid b/manifest.uuid index 579d6c185f..38e76f7114 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3071ba2bdbda7018d0a285eceb04b8527209ec1e \ No newline at end of file +27d4b6f5756c7b19c00c95d46a77280c8b6f03a4 \ No newline at end of file diff --git a/test/hidden.test b/test/hidden.test index 2bc253c903..a9664f0e49 100644 --- a/test/hidden.test +++ b/test/hidden.test @@ -30,22 +30,44 @@ do_execsql_test 1.3 { SELECT __hidden__a, * FROM t1; } {{} 1 x y} -#do_execsql_test 2.1 { - #CREATE TABLE x1(a, b, c); - #INSERT INTO x1 VALUES(1, 2, 3); - #CREATE VIEW v1(a, b, __hidden__c) AS SELECT a, b, c FROM x1; - #SELECT * FROM v1; -#} {1 2} - -do_execsql_test 2.2 { - PRAGMA table_info(v1); +foreach {tn view} { + 1 { CREATE VIEW v1(a, b, __hidden__c) AS SELECT a, b, c FROM x1 } + 2 { CREATE VIEW v1 AS SELECT a, b, c AS __hidden__c FROM x1 } } { -0 a {} 0 {} 0 -1 b {} 0 {} 0 -2 __hidden__c {} 0 {} 0 + do_execsql_test 2.$tn.1 { + DROP TABLE IF EXISTS x1; + CREATE TABLE x1(a, b, c); + INSERT INTO x1 VALUES(1, 2, 3); + } + + catchsql { DROP VIEW v1 } + execsql $view + + do_execsql_test 2.$tn.2 { + SELECT a, b, __hidden__c FROM v1; + } {1 2 3} + + do_execsql_test 2.$tn.3 { + SELECT * FROM v1; + } {1 2} + + do_execsql_test 2.$tn.4 { + CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN + INSERT INTO x1 VALUES(new.a, new.b, new.__hidden__c); + END; + + INSERT INTO v1 VALUES(4, 5); + SELECT * FROM x1; + } {1 2 3 4 5 {}} + + do_execsql_test 2.$tn.5 { + INSERT INTO v1(a, b, __hidden__c) VALUES(7, 8, 9); + SELECT * FROM x1; + } {1 2 3 4 5 {} 7 8 9} } + finish_test From b1daa3f469cd138dbc387d3ed91b2ba183c19d4d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 18 Nov 2015 21:22:02 +0000 Subject: [PATCH 48/55] Get the __hidden__ column mechanism working on views with INSTEAD OF triggers. FossilOrigin-Name: 20c1e9ce75cc0b5f7456379f35a4fe24edd98088 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/insert.c | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index e36c1904ee..856258b350 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sfor\sviews\sto\shidden.test. -D 2015-11-18T20:59:47.725 +C Get\sthe\s__hidden__\scolumn\smechanism\sworking\son\sviews\swith\sINSTEAD\sOF\striggers. +D 2015-11-18T21:22:02.852 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -300,7 +300,7 @@ F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 0b376795f688aafd264ff0c5a6538e5a4cc6c213 +F src/insert.c 0cf9a847a0a03b4fe932f1adfa69165802d5250b F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3071ba2bdbda7018d0a285eceb04b8527209ec1e -R 2baa1dc83be9c7315702795a7e6fe14b -U dan -Z 4e931d86c42c505d1f09dcba4c9d7ade +P 27d4b6f5756c7b19c00c95d46a77280c8b6f03a4 +R d79a926a0045cbb3f30ec72ca51f379c +U drh +Z c4fa45b9d058451cddc1ea846764a52e diff --git a/manifest.uuid b/manifest.uuid index 38e76f7114..f5b8db47ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -27d4b6f5756c7b19c00c95d46a77280c8b6f03a4 \ No newline at end of file +20c1e9ce75cc0b5f7456379f35a4fe24edd98088 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 2c159fd2bc..aa3eb91114 100644 --- a/src/insert.c +++ b/src/insert.c @@ -833,15 +833,14 @@ void sqlite3Insert( /* Create the new column data */ - for(i=0; inCol; i++){ - if( pColumn==0 ){ - j = i; - }else{ + for(i=j=0; inCol; i++){ + if( pColumn ){ for(j=0; jnId; j++){ if( pColumn->a[j].idx==i ) break; } } - if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){ + if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) + || (pColumn==0 && IsHiddenColumn(&pTab->aCol[i])) ){ sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1); }else if( useTempTable ){ sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1); @@ -849,6 +848,7 @@ void sqlite3Insert( assert( pSelect==0 ); /* Otherwise useTempTable is true */ sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1); } + if( pColumn==0 && !IsHiddenColumn(&pTab->aCol[i]) ) j++; } /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger, From a6f88ffd3ae12f8b6b38b8ece8d9ffe5608a87a0 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Nov 2015 13:21:31 +0000 Subject: [PATCH 49/55] Fix a 10-year-old misguided attempt at parser performance improvement that actually made parsing slightly slower. FossilOrigin-Name: 3833cbac0706ecac9a641d70b786d26f7e1a42b1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/build.c | 15 +-------------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index 3977bc21ce..7b6fa36f04 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\susing\smmap\smode\son\sWin32,\suse\sa\sread-only\smapping\sby\sdefault.\sWrite\sto\sthe\sdatabase\sfile\susing\sWriteFile().\sUnless\sSQLITE_MMAP_READWRITE\sis\sdefined,\sin\swhich\scase\suse\sa\sread/write\smapping\sand\swrite\sinto\sthe\sfile\susing\smemcpy(). -D 2015-11-17T21:42:32.347 +C Fix\sa\s10-year-old\smisguided\sattempt\sat\sparser\sperformance\simprovement\sthat\nactually\smade\sparsing\sslightly\sslower. +D 2015-11-19T13:21:31.911 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -285,7 +285,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c d3bdd8462a86492e2ebc9aca4a0168429017de25 F src/btree.h 2d76dee44704c47eed323356a758662724b674a0 F src/btreeInt.h 3ab435ed27adea54d040584b0bcc488ee7db1e38 -F src/build.c ca574d33ffb1763cfd2979383f4d507095bfbe19 +F src/build.c baee971344208e212573c08f6bd5579023cc5d14 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a @@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 67c5d3c646c8198c8637069140aca952b802df25 -R d582abf646ba97a05dcf7955b3e63a88 -U mistachkin -Z 3d22a16f35aefddddac7e9c38e41c6d4 +P 4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 +R cfcad521008e112c6b761003fe8dc627 +U drh +Z 7e2a0f5e909f9722ed5527dda015ff6e diff --git a/manifest.uuid b/manifest.uuid index f18cecb173..25fa29f661 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4f521b5bb36a1117db324e92dcf80abd2f1a5bc1 \ No newline at end of file +3833cbac0706ecac9a641d70b786d26f7e1a42b1 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 8cb2d44ac7..a46bb58520 100644 --- a/src/build.c +++ b/src/build.c @@ -1049,19 +1049,6 @@ begin_table_error: return; } -/* -** This macro is used to compare two strings in a case-insensitive manner. -** It is slightly faster than calling sqlite3StrICmp() directly, but -** produces larger code. -** -** WARNING: This macro is not compatible with the strcmp() family. It -** returns true if the two strings are equal, otherwise false. -*/ -#define STRICMP(x, y) (\ -sqlite3UpperToLower[*(unsigned char *)(x)]== \ -sqlite3UpperToLower[*(unsigned char *)(y)] \ -&& sqlite3StrICmp((x)+1,(y)+1)==0 ) - /* ** Add a new column to the table currently being constructed. ** @@ -1086,7 +1073,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){ z = sqlite3NameFromToken(db, pName); if( z==0 ) return; for(i=0; inCol; i++){ - if( STRICMP(z, p->aCol[i].zName) ){ + if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); sqlite3DbFree(db, z); return; From 03d69a682696fd6bfcb948b43e252f1126928cfb Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Nov 2015 13:53:57 +0000 Subject: [PATCH 50/55] Only support the magic "__hidden__" column name prefix interpretation when compiled with SQLITE_ENABLE_HIDDEN_COLUMNS. FossilOrigin-Name: 5490646b2eb74ea8bd5ab2690f69b9c707a0165f --- manifest | 24 ++++++++++++------------ manifest.uuid | 2 +- src/build.c | 16 +++++++++++++--- src/insert.c | 6 ++---- src/select.c | 16 +++++----------- src/sqliteInt.h | 20 +++++++++++++++++++- src/test_config.c | 6 ++++++ test/hidden.test | 9 +++++---- test/releasetest.tcl | 3 +++ 9 files changed, 66 insertions(+), 36 deletions(-) diff --git a/manifest b/manifest index 856258b350..8fd60806d4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Get\sthe\s__hidden__\scolumn\smechanism\sworking\son\sviews\swith\sINSTEAD\sOF\striggers. -D 2015-11-18T21:22:02.852 +C Only\ssupport\sthe\smagic\s"__hidden__"\scolumn\sname\sprefix\sinterpretation\swhen\ncompiled\swith\sSQLITE_ENABLE_HIDDEN_COLUMNS. +D 2015-11-19T13:53:57.338 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -285,7 +285,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c d3bdd8462a86492e2ebc9aca4a0168429017de25 F src/btree.h 2d76dee44704c47eed323356a758662724b674a0 F src/btreeInt.h 3ab435ed27adea54d040584b0bcc488ee7db1e38 -F src/build.c a62cef335439eca53f8b0b12fae4b6925ff5b980 +F src/build.c c67e12bdafb58983175b22c889610ee32c187115 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a @@ -300,7 +300,7 @@ F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 0cf9a847a0a03b4fe932f1adfa69165802d5250b +F src/insert.c 6677454f256e7992c68a6460b0224a7ec60ef5ed F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 @@ -339,12 +339,12 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 7996cf4b5730e80dd44a080019736e70eaef4377 +F src/select.c ac980e5b70478aab235d12b4565a745814453858 F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h 1b8c1b37f0bd2cec784c9f257e449f72096b37f8 +F src/sqliteInt.h 339067553cebac9ba7ec0c616b135db7905c20c9 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -363,7 +363,7 @@ F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 F src/test_backup.c 2e6e6a081870150f20c526a2e9d0d29cda47d803 F src/test_blob.c e5a7a81d61a780da79101aeb1e60d300af169e07 F src/test_btree.c 2e9978eca99a9a4bfa8cae949efb00886860a64f -F src/test_config.c 7523f8bd7604aec88a9d1c303d93c925bcfcc9f9 +F src/test_config.c f2824de39f59d8d621e2d6ec5cc67006d000b2eb F src/test_demovfs.c 0de72c2c89551629f58486fde5734b7d90758852 F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f @@ -762,7 +762,7 @@ F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 -F test/hidden.test e8c7623994991db181310fc876e16a0c27156a3d +F test/hidden.test 9de6b1631ac23b27801868abaccd1a7f3e96a6f2 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/ieee754.test 118b665a97a8df0e8f2fbdb07d113e596f4a6b53 @@ -950,7 +950,7 @@ F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 -F test/releasetest.tcl 30cf0851a6fb0343b65f27dc89ab7bed3c3cc77d +F test/releasetest.tcl 622f2381b217facdf429584a5c292cc1fc47e7c0 F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea F test/rollback2.test fc14cf6d1a2b250d2735ef16124b971bce152f14 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 27d4b6f5756c7b19c00c95d46a77280c8b6f03a4 -R d79a926a0045cbb3f30ec72ca51f379c +P 20c1e9ce75cc0b5f7456379f35a4fe24edd98088 +R b681b2e3a18e987eaa1eccff39189bf0 U drh -Z c4fa45b9d058451cddc1ea846764a52e +Z 0c3369445e405737c5be7849ea75e5f3 diff --git a/manifest.uuid b/manifest.uuid index f5b8db47ca..0201a434ee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -20c1e9ce75cc0b5f7456379f35a4fe24edd98088 \ No newline at end of file +5490646b2eb74ea8bd5ab2690f69b9c707a0165f \ No newline at end of file diff --git a/src/build.c b/src/build.c index 9a4a0cc8d4..65f94d2348 100644 --- a/src/build.c +++ b/src/build.c @@ -1049,6 +1049,18 @@ begin_table_error: return; } +/* Set properties of a table column based on the (magical) +** name of the column. +*/ +void sqlite3ColumnPropertiesFromName(Column *pCol){ +#if SQLITE_ENABLE_HIDDEN_COLUMNS + if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){ + pCol->colFlags |= COLFLAG_HIDDEN; + } +#endif +} + + /* ** This macro is used to compare two strings in a case-insensitive manner. ** It is slightly faster than calling sqlite3StrICmp() directly, but @@ -1104,9 +1116,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){ pCol = &p->aCol[p->nCol]; memset(pCol, 0, sizeof(p->aCol[0])); pCol->zName = z; - if( sqlite3_strnicmp(z, "__hidden__", 10)==0 ){ - pCol->colFlags |= COLFLAG_HIDDEN; - } + sqlite3ColumnPropertiesFromName(pCol); /* If there is no type specified, columns have the default affinity ** 'BLOB'. If there is a type specified, then sqlite3AddColumnType() will diff --git a/src/insert.c b/src/insert.c index aa3eb91114..d1226ee276 100644 --- a/src/insert.c +++ b/src/insert.c @@ -840,7 +840,7 @@ void sqlite3Insert( } } if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) - || (pColumn==0 && IsHiddenColumn(&pTab->aCol[i])) ){ + || (pColumn==0 && IsOrdinaryHiddenColumn(&pTab->aCol[i])) ){ sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1); }else if( useTempTable ){ sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1); @@ -848,7 +848,7 @@ void sqlite3Insert( assert( pSelect==0 ); /* Otherwise useTempTable is true */ sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1); } - if( pColumn==0 && !IsHiddenColumn(&pTab->aCol[i]) ) j++; + if( pColumn==0 && !IsOrdinaryHiddenColumn(&pTab->aCol[i]) ) j++; } /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger, @@ -932,8 +932,6 @@ void sqlite3Insert( } if( pColumn==0 ){ if( IsHiddenColumn(&pTab->aCol[i]) ){ - assert( IsVirtual(pTab) - || sqlite3_strnicmp(pTab->aCol[i].zName,"__hidden__",10)==0 ); j = -1; nHidden++; }else{ diff --git a/src/select.c b/src/select.c index f2ea26eaf2..793171f93c 100644 --- a/src/select.c +++ b/src/select.c @@ -1659,12 +1659,9 @@ int sqlite3ColumnsFromExprList( if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; - if( zName ){ - if( sqlite3HashInsert(&ht, zName, pCol)==pCol ){ - db->mallocFailed = 1; - }else if( sqlite3_strnicmp(zName, "__hidden__", 10)==0 ){ - pCol->colFlags |= COLFLAG_HIDDEN; - } + sqlite3ColumnPropertiesFromName(pCol); + if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ + db->mallocFailed = 1; } } sqlite3HashClear(&ht); @@ -4364,13 +4361,10 @@ static int selectExpander(Walker *pWalker, Select *p){ continue; } - /* If a column is marked as 'hidden' (currently only possible - ** for virtual tables), do not include it in the expanded - ** result-set list. + /* If a column is marked as 'hidden', do not include it in + ** the expanded result-set list. */ if( IsHiddenColumn(&pTab->aCol[j]) ){ - assert( IsVirtual(pTab) - || sqlite3_strnicmp(pTab->aCol[j].zName,"__hidden__", 10)==0 ); continue; } tableSeen = 1; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0a1eb770f7..788b348fbd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1696,12 +1696,29 @@ struct Table { */ #ifndef SQLITE_OMIT_VIRTUALTABLE # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) -# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) #else # define IsVirtual(X) 0 # define IsHiddenColumn(X) 0 #endif +/* +** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() +** only works for non-virtual tables (ordinary tables and views) and is +** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The +** IsHiddenColumn() macro is general purpose. +*/ +#if defined(SQLITE_ENABLE_HIDDEN_COLUMNS) +# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) +# define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) +#elif !defined(SQLITE_OMIT_VIRTUAL) +# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) +# define IsOrdinaryHiddenColumn(X) 0 +#else +# define IsHiddenColumn(X) 0 +# define IsOrdinaryHiddenColumn(X) 0 +#endif + + /* Does the table have a rowid */ #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0) #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0) @@ -3314,6 +3331,7 @@ void sqlite3OpenMasterTable(Parse *, int); Index *sqlite3PrimaryKeyIndex(Table*); i16 sqlite3ColumnOfIndex(Index*, i16); void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); +void sqlite3ColumnPropertiesFromName(Column*); void sqlite3AddColumn(Parse*,Token*); void sqlite3AddNotNull(Parse*, int); void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); diff --git a/src/test_config.c b/src/test_config.c index 4cb5c0057a..b84424bbdc 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -125,6 +125,12 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "cursorhints", "0", TCL_GLOBAL_ONLY); #endif +#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS + Tcl_SetVar2(interp, "sqlite_options", "hiddencolumns", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "hiddencolumns", "0", TCL_GLOBAL_ONLY); +#endif + #ifdef SQLITE_ENABLE_MEMSYS3 Tcl_SetVar2(interp, "sqlite_options", "mem3", "1", TCL_GLOBAL_ONLY); #else diff --git a/test/hidden.test b/test/hidden.test index a9664f0e49..07a370c4a5 100644 --- a/test/hidden.test +++ b/test/hidden.test @@ -16,6 +16,11 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix hidden +ifcapable !hiddencolumns { + finish_test + return +} + do_execsql_test 1.1 { CREATE TABLE t1(__hidden__a, b); INSERT INTO t1 VALUES('1'); @@ -65,9 +70,5 @@ foreach {tn view} { SELECT * FROM x1; } {1 2 3 4 5 {} 7 8 9} } - - - - finish_test diff --git a/test/releasetest.tcl b/test/releasetest.tcl index f9c4406d40..7f53fd1523 100644 --- a/test/releasetest.tcl +++ b/test/releasetest.tcl @@ -119,6 +119,7 @@ array set ::Configs [strip_comments { -DSQLITE_ENABLE_MEMSYS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_STAT4 + -DSQLITE_ENABLE_HIDDEN_COLUMNS -DSQLITE_MAX_ATTACHED=125 } "Fast-One" { @@ -145,6 +146,7 @@ array set ::Configs [strip_comments { -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_OMIT_PROGRESS_CALLBACK=1 -DSQLITE_OMIT_VIRTUALTABLE=1 + -DSQLITE_ENABLE_HIDDEN_COLUMNS -DSQLITE_TEMP_STORE=3 --enable-json1 } @@ -213,6 +215,7 @@ array set ::Configs [strip_comments { -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE + -DSQLITE_ENABLE_HIDDEN_COLUMNS --enable-json1 } From 1a1d3cd2f3b9d9dadf50fe84c839e7d7c8b00488 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Nov 2015 16:33:31 +0000 Subject: [PATCH 51/55] Create the new TK_ASTERISK token to represent the "*" in "SELECT *". Formerly that operator was TK_ALL, which was also used for UNION ALL. Less confusion if they operator symbols are distinct. FossilOrigin-Name: 201ac6d449431dadc6b29faecd68b559bd64bc9f --- manifest | 19 +++++++++---------- manifest.uuid | 2 +- src/insert.c | 2 +- src/parse.y | 6 +++--- src/select.c | 19 +++++++++++-------- tool/addopcodes.tcl | 1 + 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 10477abd8d..e87f64889b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\scompiled\swith\sSQLITE_ENABLE_HIDDEN_COLUMNS,\sthen\scolumns\sin\sordinary\ntables\sand\sviews\sthat\shave\snames\sbeginning\swith\s"__hidden__"\sare\somitted\sfrom\nthe\s"*"\sexpansion\sin\sSELECT\sstatements\sand\sfrom\sthe\sautomatic\slist\sof\scolumns\nfollowing\sthe\stable\sname\sin\san\sINSERT\sINTO\sstatement. -D 2015-11-19T14:11:58.858 +C Create\sthe\snew\sTK_ASTERISK\stoken\sto\srepresent\sthe\s"*"\sin\s"SELECT\s*".\s\sFormerly\nthat\soperator\swas\sTK_ALL,\swhich\swas\salso\sused\sfor\sUNION\sALL.\s\sLess\sconfusion\sif\nthey\soperator\ssymbols\sare\sdistinct. +D 2015-11-19T16:33:31.729 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -300,7 +300,7 @@ F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 6677454f256e7992c68a6460b0224a7ec60ef5ed +F src/insert.c 7aa0846b25ab53e33a16fc3b9417ff87b3c60183 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 @@ -328,7 +328,7 @@ F src/os_win.c 2d77dab5c555a18c0aff379c6a692fc3499044d9 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e F src/pager.h 87c4118a71ba3965184148b379a6d93179071091 -F src/parse.y aad5cc866dc23719f361fe7e0b8eaec8ce4861a4 +F src/parse.y 23737e649c26ce327603799e57f5c2ff50e5e6ba F src/pcache.c 73895411fa6b7bd6f0091212feabbe833b358d23 F src/pcache.h 1ff11adce609ba7de139b6abfabaf9a2bac947b5 F src/pcache1.c 902e1bc7bdaa81b40f8543407c5e2ac8ef4dc035 @@ -339,7 +339,7 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c ac980e5b70478aab235d12b4565a745814453858 +F src/select.c e8eccb5b4482965f56fc46c69e75ce2da941b18e F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1345,7 +1345,7 @@ F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 8606413d3035c05373a0d7fae82ebf59ae9e16c3 -F tool/addopcodes.tcl f1fd17b639910226749d1ae006beef8f60378274 +F tool/addopcodes.tcl 4ca9c3ef196f08da30add5d07ce0c9458dc8c633 F tool/build-all-msvc.bat e42141ca3c3812315432f9813ef9eb78aa8d99c9 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/cg_anno.tcl 692ce4b8693d59e3a3de77ca97f4139ecfa641b0 x @@ -1404,8 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3833cbac0706ecac9a641d70b786d26f7e1a42b1 5490646b2eb74ea8bd5ab2690f69b9c707a0165f -R 4afe49c98c7e846f7bc0bfa4d2728afc -T +closed 5490646b2eb74ea8bd5ab2690f69b9c707a0165f +P 011904cad2be2ce34e2f37ffae8ff2f1044a2969 +R 40ad63765b750992e100464bfa82981f U drh -Z 1e726fa67e18842e3c05f4f72e06c5dc +Z 1545ad0787e026d6592cfaa98e731337 diff --git a/manifest.uuid b/manifest.uuid index 3567556e2e..7707d8b725 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -011904cad2be2ce34e2f37ffae8ff2f1044a2969 \ No newline at end of file +201ac6d449431dadc6b29faecd68b559bd64bc9f \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index d1226ee276..618b2dee7b 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1873,7 +1873,7 @@ static int xferOptimization( return 0; /* The result set must have exactly one column */ } assert( pEList->a[0].pExpr ); - if( pEList->a[0].pExpr->op!=TK_ALL ){ + if( pEList->a[0].pExpr->op!=TK_ASTERISK ){ return 0; /* The result set must be the special operator "*" */ } diff --git a/src/parse.y b/src/parse.y index e504e64548..6ac2be21f2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -546,7 +546,7 @@ distinct(A) ::= . {A = 0;} // selcollist is a list of expressions that are to become the return // values of the SELECT statement. The "*" in statements like // "SELECT * FROM ..." is encoded as a special expression with an -// opcode of TK_ALL. +// opcode of TK_ASTERISK. // %type selcollist {ExprList*} %destructor selcollist {sqlite3ExprListDelete(pParse->db, $$);} @@ -560,11 +560,11 @@ selcollist(A) ::= sclp(P) expr(X) as(Y). { sqlite3ExprListSetSpan(pParse,A,&X); } selcollist(A) ::= sclp(P) STAR. { - Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0); + Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0); A = sqlite3ExprListAppend(pParse, P, p); } selcollist(A) ::= sclp(P) nm(X) DOT STAR(Y). { - Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &Y); + Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0, &Y); Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); A = sqlite3ExprListAppend(pParse,P, pDot); diff --git a/src/select.c b/src/select.c index 793171f93c..2cf190b34c 100644 --- a/src/select.c +++ b/src/select.c @@ -118,7 +118,7 @@ Select *sqlite3SelectNew( memset(pNew, 0, sizeof(*pNew)); } if( pEList==0 ){ - pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0)); + pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0)); } pNew->pEList = pEList; if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc)); @@ -3938,7 +3938,7 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){ if( pNewSrc==0 ) return WRC_Abort; *pNew = *p; p->pSrc = pNewSrc; - p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0)); + p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ASTERISK, 0)); p->op = TK_SELECT; p->pWhere = 0; pNew->pGroupBy = 0; @@ -4279,19 +4279,20 @@ static int selectExpander(Walker *pWalker, Select *p){ /* For every "*" that occurs in the column list, insert the names of ** all columns in all tables. And for every TABLE.* insert the names ** of all columns in TABLE. The parser inserted a special expression - ** with the TK_ALL operator for each "*" that it found in the column list. - ** The following code just has to locate the TK_ALL expressions and expand - ** each one to the list of all columns in all tables. + ** with the TK_ASTERISK operator for each "*" that it found in the column + ** list. The following code just has to locate the TK_ASTERISK + ** expressions and expand each one to the list of all columns in + ** all tables. ** ** The first loop just checks to see if there are any "*" operators ** that need expanding. */ for(k=0; knExpr; k++){ pE = pEList->a[k].pExpr; - if( pE->op==TK_ALL ) break; + if( pE->op==TK_ASTERISK ) break; assert( pE->op!=TK_DOT || pE->pRight!=0 ); assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) ); - if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break; + if( pE->op==TK_DOT && pE->pRight->op==TK_ASTERISK ) break; } if( knExpr ){ /* @@ -4309,7 +4310,9 @@ static int selectExpander(Walker *pWalker, Select *p){ pE = a[k].pExpr; pRight = pE->pRight; assert( pE->op!=TK_DOT || pRight!=0 ); - if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pRight->op!=TK_ALL) ){ + if( pE->op!=TK_ASTERISK + && (pE->op!=TK_DOT || pRight->op!=TK_ASTERISK) + ){ /* This particular expression does not need to be expanded. */ pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); diff --git a/tool/addopcodes.tcl b/tool/addopcodes.tcl index bd0b73a35f..84e3994ce8 100644 --- a/tool/addopcodes.tcl +++ b/tool/addopcodes.tcl @@ -37,6 +37,7 @@ set extras { UMINUS UPLUS REGISTER + ASTERISK SPACE ILLEGAL } From ba68f8f3f58437deaea3d1bb26ca44a09faa837f Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 19 Nov 2015 16:46:46 +0000 Subject: [PATCH 52/55] Fix problems with INSERT INTO ... SELECT ... statements that write to tables with __hidden__ columns. FossilOrigin-Name: 59bd0ec7d4327852ee8c0206b2c59d0a12484db8 --- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/build.c | 6 ++++-- src/insert.c | 5 +++++ src/select.c | 2 +- src/sqliteInt.h | 2 +- test/hidden.test | 29 ++++++++++++++++++++++++++++- 7 files changed, 51 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index e87f64889b..5beeb22a50 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Create\sthe\snew\sTK_ASTERISK\stoken\sto\srepresent\sthe\s"*"\sin\s"SELECT\s*".\s\sFormerly\nthat\soperator\swas\sTK_ALL,\swhich\swas\salso\sused\sfor\sUNION\sALL.\s\sLess\sconfusion\sif\nthey\soperator\ssymbols\sare\sdistinct. -D 2015-11-19T16:33:31.729 +C Fix\sproblems\swith\sINSERT\sINTO\s...\sSELECT\s...\sstatements\sthat\swrite\sto\stables\swith\s__hidden__\scolumns. +D 2015-11-19T16:46:46.075 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -285,7 +285,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c d3bdd8462a86492e2ebc9aca4a0168429017de25 F src/btree.h 2d76dee44704c47eed323356a758662724b674a0 F src/btreeInt.h 3ab435ed27adea54d040584b0bcc488ee7db1e38 -F src/build.c c909d178ef900f56aaafa4a509fd1b12a7d52ea6 +F src/build.c 5a3b71786e2b96d2bb92d40f190eb1fe736f25ca F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a @@ -300,7 +300,7 @@ F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 7aa0846b25ab53e33a16fc3b9417ff87b3c60183 +F src/insert.c edb295a0b669e2dedba65cd546789770ae061277 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 @@ -339,12 +339,12 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c e8eccb5b4482965f56fc46c69e75ce2da941b18e +F src/select.c 3492a2794b8ff04dce2a91a284492df5725045f5 F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h 339067553cebac9ba7ec0c616b135db7905c20c9 +F src/sqliteInt.h 921678cb43bb7f63364e56757c07f3e6e0eb45c6 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -762,7 +762,7 @@ F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 -F test/hidden.test 9de6b1631ac23b27801868abaccd1a7f3e96a6f2 +F test/hidden.test df1540ad1017b49a0681ba3b01e0cde051dbeb58 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/ieee754.test 118b665a97a8df0e8f2fbdb07d113e596f4a6b53 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 011904cad2be2ce34e2f37ffae8ff2f1044a2969 -R 40ad63765b750992e100464bfa82981f -U drh -Z 1545ad0787e026d6592cfaa98e731337 +P 201ac6d449431dadc6b29faecd68b559bd64bc9f +R 1ed430a49a13a08f14d4334a2efebccc +U dan +Z 390e482d41754a020737571e763bbfaa diff --git a/manifest.uuid b/manifest.uuid index 7707d8b725..44fcfa5cdd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -201ac6d449431dadc6b29faecd68b559bd64bc9f \ No newline at end of file +59bd0ec7d4327852ee8c0206b2c59d0a12484db8 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 0e8d4cf0ea..f928ba3075 100644 --- a/src/build.c +++ b/src/build.c @@ -1052,10 +1052,12 @@ begin_table_error: /* Set properties of a table column based on the (magical) ** name of the column. */ -void sqlite3ColumnPropertiesFromName(Column *pCol){ +void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){ #if SQLITE_ENABLE_HIDDEN_COLUMNS if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){ pCol->colFlags |= COLFLAG_HIDDEN; + }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){ + pTab->tabFlags |= TF_OOOHidden; } #endif } @@ -1103,7 +1105,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){ pCol = &p->aCol[p->nCol]; memset(pCol, 0, sizeof(p->aCol[0])); pCol->zName = z; - sqlite3ColumnPropertiesFromName(pCol); + sqlite3ColumnPropertiesFromName(p, pCol); /* If there is no type specified, columns have the default affinity ** 'BLOB'. If there is a type specified, then sqlite3AddColumnType() will diff --git a/src/insert.c b/src/insert.c index 618b2dee7b..4b8ed22106 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1909,6 +1909,11 @@ static int xferOptimization( for(i=0; inCol; i++){ Column *pDestCol = &pDest->aCol[i]; Column *pSrcCol = &pSrc->aCol[i]; +#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS + if( (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN ){ + return 0; /* Neither table may have __hidden__ columns */ + } +#endif if( pDestCol->affinity!=pSrcCol->affinity ){ return 0; /* Affinity must be the same on all columns */ } diff --git a/src/select.c b/src/select.c index 2cf190b34c..967023420c 100644 --- a/src/select.c +++ b/src/select.c @@ -1659,7 +1659,7 @@ int sqlite3ColumnsFromExprList( if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; - sqlite3ColumnPropertiesFromName(pCol); + sqlite3ColumnPropertiesFromName(0, pCol); if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ db->mallocFailed = 1; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 788b348fbd..50a0c97eb0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3331,7 +3331,7 @@ void sqlite3OpenMasterTable(Parse *, int); Index *sqlite3PrimaryKeyIndex(Table*); i16 sqlite3ColumnOfIndex(Index*, i16); void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); -void sqlite3ColumnPropertiesFromName(Column*); +void sqlite3ColumnPropertiesFromName(Table*, Column*); void sqlite3AddColumn(Parse*,Token*); void sqlite3AddNotNull(Parse*, int); void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); diff --git a/test/hidden.test b/test/hidden.test index 07a370c4a5..9914a6ed10 100644 --- a/test/hidden.test +++ b/test/hidden.test @@ -70,5 +70,32 @@ foreach {tn view} { SELECT * FROM x1; } {1 2 3 4 5 {} 7 8 9} } - + +#------------------------------------------------------------------------- +# Test INSERT INTO ... SELECT ... statements that write to tables with +# hidden columns. +# +do_execsql_test 3.1 { + CREATE TABLE t4(a, __hidden__b, c); + INSERT INTO t4 SELECT 1, 2; + SELECT a, __hidden__b, c FROM t4; +} {1 {} 2} + +do_execsql_test 3.2.1 { + CREATE TABLE t5(__hidden__a, b, c); + CREATE TABLE t6(__hidden__a, b, c); + INSERT INTO t6(__hidden__a, b, c) VALUES(1, 2, 3); + INSERT INTO t6(__hidden__a, b, c) VALUES(4, 5, 6); + INSERT INTO t6(__hidden__a, b, c) VALUES(7, 8, 9); +} + +do_execsql_test 3.2.2 { + INSERT INTO t5 SELECT * FROM t6; + SELECT * FROM t5; +} {2 3 5 6 8 9} + +do_execsql_test 3.2.3 { + SELECT __hidden__a FROM t5; +} {{} {} {}} + finish_test From 80090f922137f4134e43af284956fa5acd9151c0 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Nov 2015 17:55:11 +0000 Subject: [PATCH 53/55] When manifesting a view as part of an DELETE or UPDATE, be sure to include the hidden columns in the manifestation. FossilOrigin-Name: 28df5dc4a9569f388af2ee0d1f016afbea132277 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/delete.c | 3 ++- src/select.c | 9 ++++++--- src/sqliteInt.h | 3 ++- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 5beeb22a50..6941675b3d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sproblems\swith\sINSERT\sINTO\s...\sSELECT\s...\sstatements\sthat\swrite\sto\stables\swith\s__hidden__\scolumns. -D 2015-11-19T16:46:46.075 +C When\smanifesting\sa\sview\sas\spart\sof\san\sDELETE\sor\sUPDATE,\sbe\ssure\sto\sinclude\nthe\shidden\scolumns\sin\sthe\smanifestation. +D 2015-11-19T17:55:11.376 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -291,7 +291,7 @@ F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a F src/date.c fb1c99172017dcc8e237339132c91a21a0788584 F src/dbstat.c ffd63fc8ba7541476ced189b95e95d7f2bc63f78 -F src/delete.c c4c6fb9da78b946fcba2a6aac5b24bc5c15e752a +F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da F src/expr.c 0080c0f12806eca91e75a23a121a68918e9da357 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 31900763094a3736a5fc887469202eb579fef2d0 @@ -339,12 +339,12 @@ F src/printf.c f8fc8f04e75b1e983ef2793c27ec7a43b287e94a F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 3492a2794b8ff04dce2a91a284492df5725045f5 +F src/select.c 2376d320907a5c28c55290f18fd94aa3400bf97c F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h 921678cb43bb7f63364e56757c07f3e6e0eb45c6 +F src/sqliteInt.h d8dc20e7b0e12cf5fd85f43a2abad99eb6f66d9b F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 201ac6d449431dadc6b29faecd68b559bd64bc9f -R 1ed430a49a13a08f14d4334a2efebccc -U dan -Z 390e482d41754a020737571e763bbfaa +P 59bd0ec7d4327852ee8c0206b2c59d0a12484db8 +R 626878acc4dd3cd8e822d0d9711e48d6 +U drh +Z 65ef55c8781837190650d43297c4895a diff --git a/manifest.uuid b/manifest.uuid index 44fcfa5cdd..17f91d54c7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -59bd0ec7d4327852ee8c0206b2c59d0a12484db8 \ No newline at end of file +28df5dc4a9569f388af2ee0d1f016afbea132277 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index cd683e37d8..ed273bde81 100644 --- a/src/delete.c +++ b/src/delete.c @@ -106,7 +106,8 @@ void sqlite3MaterializeView( assert( pFrom->a[0].pOn==0 ); assert( pFrom->a[0].pUsing==0 ); } - pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); + pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, + SF_IncludeHidden, 0, 0); sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); sqlite3Select(pParse, pSel, &dest); sqlite3SelectDelete(db, pSel); diff --git a/src/select.c b/src/select.c index 967023420c..3d69dfb03a 100644 --- a/src/select.c +++ b/src/select.c @@ -4364,10 +4364,13 @@ static int selectExpander(Walker *pWalker, Select *p){ continue; } - /* If a column is marked as 'hidden', do not include it in - ** the expanded result-set list. + /* If a column is marked as 'hidden', omit it from the expanded + ** result-set list unless the SELECT has the SF_IncludeHidden + ** bit set. */ - if( IsHiddenColumn(&pTab->aCol[j]) ){ + if( (p->selFlags & SF_IncludeHidden)==0 + && IsHiddenColumn(&pTab->aCol[j]) + ){ continue; } tableSeen = 1; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 50a0c97eb0..ea1ccda88b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1673,7 +1673,7 @@ struct Table { /* ** Allowed values for Table.tabFlags. ** -** TF_OOOHidden applies to virtual tables that have hidden columns that are +** TF_OOOHidden applies to tables or view that have hidden columns that are ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, ** the TF_OOOHidden attribute would apply in this case. Such tables require @@ -2512,6 +2512,7 @@ struct Select { #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ #define SF_Recursive 0x2000 /* The recursive part of a recursive CTE */ #define SF_Converted 0x4000 /* By convertCompoundSelectToSubquery() */ +#define SF_IncludeHidden 0x8000 /* Include hidden columns in output */ /* From aaea31439d595e2d64043da8c424d84b77fe9ca5 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 19 Nov 2015 18:09:05 +0000 Subject: [PATCH 54/55] Fix a problem with VACUUM and __hidden__ columns. FossilOrigin-Name: 13995756ad8b80568aa2f74387788a8cab1123ef --- manifest | 16 +++++++-------- manifest.uuid | 2 +- src/insert.c | 4 +++- test/hidden.test | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 6941675b3d..4c993920d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\smanifesting\sa\sview\sas\spart\sof\san\sDELETE\sor\sUPDATE,\sbe\ssure\sto\sinclude\nthe\shidden\scolumns\sin\sthe\smanifestation. -D 2015-11-19T17:55:11.376 +C Fix\sa\sproblem\swith\sVACUUM\sand\s__hidden__\scolumns. +D 2015-11-19T18:09:05.518 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -300,7 +300,7 @@ F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c edb295a0b669e2dedba65cd546789770ae061277 +F src/insert.c e1d20ae8979e25519c2670233718676bedcfedc9 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810 @@ -762,7 +762,7 @@ F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 -F test/hidden.test df1540ad1017b49a0681ba3b01e0cde051dbeb58 +F test/hidden.test 23c1393a79e846d68fd902d72c85d5e5dcf98711 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/ieee754.test 118b665a97a8df0e8f2fbdb07d113e596f4a6b53 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 59bd0ec7d4327852ee8c0206b2c59d0a12484db8 -R 626878acc4dd3cd8e822d0d9711e48d6 -U drh -Z 65ef55c8781837190650d43297c4895a +P 28df5dc4a9569f388af2ee0d1f016afbea132277 +R 223c84fbd92f4a39a8e2bec8517a666e +U dan +Z 81a0a463975756dda288ce492d814635 diff --git a/manifest.uuid b/manifest.uuid index 17f91d54c7..6e20668ab2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28df5dc4a9569f388af2ee0d1f016afbea132277 \ No newline at end of file +13995756ad8b80568aa2f74387788a8cab1123ef \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 4b8ed22106..52769e9c4f 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1910,7 +1910,9 @@ static int xferOptimization( Column *pDestCol = &pDest->aCol[i]; Column *pSrcCol = &pSrc->aCol[i]; #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS - if( (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN ){ + if( (db->flags & SQLITE_Vacuum)==0 + && (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN + ){ return 0; /* Neither table may have __hidden__ columns */ } #endif diff --git a/test/hidden.test b/test/hidden.test index 9914a6ed10..1db2cad12e 100644 --- a/test/hidden.test +++ b/test/hidden.test @@ -98,4 +98,56 @@ do_execsql_test 3.2.3 { SELECT __hidden__a FROM t5; } {{} {} {}} + +do_execsql_test 3.3.1 { + CREATE TABLE t5a(a, b, __hidden__c); + CREATE TABLE t6a(a, b, __hidden__c); + INSERT INTO t6a(a, b, __hidden__c) VALUES(1, 2, 3); + INSERT INTO t6a(a, b, __hidden__c) VALUES(4, 5, 6); + INSERT INTO t6a(a, b, __hidden__c) VALUES(7, 8, 9); +} + +do_execsql_test 3.3.2 { + INSERT INTO t5a SELECT * FROM t6a; + SELECT * FROM t5a; +} {1 2 4 5 7 8} + +do_execsql_test 3.3.3 { + SELECT __hidden__c FROM t5a; +} {{} {} {}} + +do_execsql_test 3.4.1 { + CREATE TABLE t5b(a, __hidden__b, c); + CREATE TABLE t6b(a, b, __hidden__c); + INSERT INTO t6b(a, b, __hidden__c) VALUES(1, 2, 3); + INSERT INTO t6b(a, b, __hidden__c) VALUES(4, 5, 6); + INSERT INTO t6b(a, b, __hidden__c) VALUES(7, 8, 9); +} + +do_execsql_test 3.4.2 { + INSERT INTO t5b SELECT * FROM t6b; + SELECT * FROM t5b; +} {1 2 4 5 7 8} + +do_execsql_test 3.4.3 { + SELECT __hidden__b FROM t5b; +} {{} {} {}} + +#------------------------------------------------------------------------- +# Test VACUUM +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t1(a, __hidden__b, c UNIQUE); + INSERT INTO t1(a, __hidden__b, c) VALUES(1, 2, 3); + INSERT INTO t1(a, __hidden__b, c) VALUES(4, 5, 6); + INSERT INTO t1(a, __hidden__b, c) VALUES(7, 8, 9); + DELETE FROM t1 WHERE __hidden__b = 5; + SELECT rowid, a, __hidden__b, c FROM t1; +} {1 1 2 3 3 7 8 9} +do_execsql_test 4.2 { + VACUUM; + SELECT rowid, a, __hidden__b, c FROM t1; +} {1 1 2 3 3 7 8 9} + finish_test From 18f8e73453be7c7a2394824739e890a4d4e8cad0 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 19 Nov 2015 18:11:20 +0000 Subject: [PATCH 55/55] Fix problems with the way the IsHiddenColumn() macro is defined. FossilOrigin-Name: 126b998cf163dcdd5a222634f1e929f04db3c700 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqliteInt.h | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 4c993920d8..d831f3f7cd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sVACUUM\sand\s__hidden__\scolumns. -D 2015-11-19T18:09:05.518 +C Fix\sproblems\swith\sthe\sway\sthe\sIsHiddenColumn()\smacro\sis\sdefined. +D 2015-11-19T18:11:20.451 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -344,7 +344,7 @@ F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 -F src/sqliteInt.h d8dc20e7b0e12cf5fd85f43a2abad99eb6f66d9b +F src/sqliteInt.h 25d0792e6d355a27975dc7c49c4514b3f6eb2294 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 28df5dc4a9569f388af2ee0d1f016afbea132277 -R 223c84fbd92f4a39a8e2bec8517a666e -U dan -Z 81a0a463975756dda288ce492d814635 +P 13995756ad8b80568aa2f74387788a8cab1123ef +R 7d5fbb49b212de9edfd34eb075dc8992 +U drh +Z bc25bafe8827ab2ba48c52405ca8c198 diff --git a/manifest.uuid b/manifest.uuid index 6e20668ab2..3e5e242be0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -13995756ad8b80568aa2f74387788a8cab1123ef \ No newline at end of file +126b998cf163dcdd5a222634f1e929f04db3c700 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index ea1ccda88b..2e1adb82e6 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1698,7 +1698,6 @@ struct Table { # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) #else # define IsVirtual(X) 0 -# define IsHiddenColumn(X) 0 #endif /* @@ -1710,7 +1709,7 @@ struct Table { #if defined(SQLITE_ENABLE_HIDDEN_COLUMNS) # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) # define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) -#elif !defined(SQLITE_OMIT_VIRTUAL) +#elif !defined(SQLITE_OMIT_VIRTUALTABLE) # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) # define IsOrdinaryHiddenColumn(X) 0 #else