From e45216fd9d90e193302c2bf990fc13481458f1d6 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 7 Mar 2016 17:39:30 +0000 Subject: [PATCH 01/57] Add a new row type to RBU (a peer of insert, update and delete) - "delete then insert". FossilOrigin-Name: 169311c85b30f625bdb6986c9cd11db70942d73b --- ext/rbu/rbuC.test | 142 ++++++++++++++++++++++++++++++++++++ ext/rbu/sqlite3rbu.c | 166 +++++++++++++++++++++++-------------------- manifest | 18 +++-- manifest.uuid | 2 +- 4 files changed, 244 insertions(+), 84 deletions(-) create mode 100644 ext/rbu/rbuC.test diff --git a/ext/rbu/rbuC.test b/ext/rbu/rbuC.test new file mode 100644 index 0000000000..89fd01518f --- /dev/null +++ b/ext/rbu/rbuC.test @@ -0,0 +1,142 @@ +# 2016 March 7 +# +# 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. +# +#*********************************************************************** +# Tests for RBU focused on the REPLACE operation (rbu_control column +# contains integer value 2). +# + +source [file join [file dirname [info script]] rbu_common.tcl] +set ::testprefix rbuC + +#------------------------------------------------------------------------- +# This test is actually of an UPDATE directive. Just to establish that +# these work with UNIQUE indexes before preceding to REPLACE. +# +do_execsql_test 1.0 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b, c UNIQUE); + INSERT INTO t1 VALUES(1, 'a', 'b', 'c'); +} + +forcedelete rbu.db +do_execsql_test 1.1 { + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_t1(i, a, b, c, rbu_control); + INSERT INTO data_t1 VALUES(1, 'a', 'b', 'c', '.xxx'); +} + +do_test 1.2 { + step_rbu test.db rbu.db +} {SQLITE_DONE} + +do_execsql_test 1.3 { + SELECT * FROM t1 +} { + 1 a b c +} + +#------------------------------------------------------------------------- +# +foreach {tn schema} { + 1 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b, c UNIQUE); + CREATE INDEX t1a ON t1(a); + } + 2 { + CREATE TABLE t1(i PRIMARY KEY, a, b, c UNIQUE); + CREATE INDEX t1a ON t1(a); + } + 3 { + CREATE TABLE t1(i PRIMARY KEY, a, b, c UNIQUE) WITHOUT ROWID; + CREATE INDEX t1a ON t1(a); + } +} { + reset_db + forcedelete rbu.db + execsql $schema + + do_execsql_test 2.$tn.0 { + INSERT INTO t1 VALUES(1, 'a', 'b', 'c'); + INSERT INTO t1 VALUES(2, 'b', 'c', 'd'); + INSERT INTO t1 VALUES(3, 'c', 'd', 'e'); + } + + do_execsql_test 2.$tn.1 { + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_t1(i, a, b, c, rbu_control); + INSERT INTO data_t1 VALUES(1, 1, 2, 3, 2); + INSERT INTO data_t1 VALUES(3, 'c', 'd', 'e', 2); + INSERT INTO data_t1 VALUES(4, 'd', 'e', 'f', 2); + } + + do_test 2.$tn.2 { + step_rbu test.db rbu.db + } {SQLITE_DONE} + + do_execsql_test 2.$tn.3 { + SELECT * FROM t1 ORDER BY i + } { + 1 1 2 3 + 2 b c d + 3 c d e + 4 d e f + } + + integrity_check 2.$tn.4 +} + +foreach {tn schema} { + 1 { + CREATE TABLE t1(a, b, c UNIQUE); + CREATE INDEX t1a ON t1(a); + } + + 2 { + CREATE VIRTUAL TABLE t1 USING fts5(a, b, c); + } +} { + if {$tn==2} { ifcapable !fts5 break } + reset_db + forcedelete rbu.db + execsql $schema + + do_execsql_test 3.$tn.0 { + INSERT INTO t1 VALUES('a', 'b', 'c'); + INSERT INTO t1 VALUES('b', 'c', 'd'); + INSERT INTO t1 VALUES('c', 'd', 'e'); + } + + do_execsql_test 3.$tn.1 { + ATTACH 'rbu.db' AS rbu; + CREATE TABLE rbu.data_t1(rbu_rowid, a, b, c, rbu_control); + INSERT INTO data_t1 VALUES(1, 1, 2, 3, 2); + INSERT INTO data_t1 VALUES(3, 'c', 'd', 'e', 2); + INSERT INTO data_t1 VALUES(4, 'd', 'e', 'f', 2); + } + + do_test 3.$tn.2 { + step_rbu test.db rbu.db + } {SQLITE_DONE} + + do_execsql_test 3.$tn.3 { + SELECT rowid, * FROM t1 ORDER BY 1 + } { + 1 1 2 3 + 2 b c d + 3 c d e + 4 d e f + } + + integrity_check 3.$tn.4 +} + + + +finish_test + diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 682becbb5c..7f27399988 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -280,10 +280,11 @@ struct RbuObjIter { */ #define RBU_INSERT 1 /* Insert on a main table b-tree */ #define RBU_DELETE 2 /* Delete a row from a main table b-tree */ -#define RBU_IDX_DELETE 3 /* Delete a row from an aux. index b-tree */ -#define RBU_IDX_INSERT 4 /* Insert on an aux. index b-tree */ -#define RBU_UPDATE 5 /* Update a row in a main table b-tree */ +#define RBU_REPLACE 3 /* Delete and then insert a row */ +#define RBU_IDX_DELETE 4 /* Delete a row from an aux. index b-tree */ +#define RBU_IDX_INSERT 5 /* Insert on an aux. index b-tree */ +#define RBU_UPDATE 6 /* Update a row in a main table b-tree */ /* ** A single step of an incremental checkpoint - frame iWalFrame of the wal @@ -1909,13 +1910,13 @@ static int rbuObjIterPrepareAll( ); }else{ zSql = sqlite3_mprintf( + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' " + "UNION ALL " "SELECT %s, rbu_control FROM '%q' " "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 " - "UNION ALL " - "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' " "ORDER BY %s%s", - zCollist, pIter->zDataTbl, zCollist, p->zStateDb, pIter->zDataTbl, + zCollist, pIter->zDataTbl, zCollist, zLimit ); } @@ -1981,17 +1982,17 @@ static int rbuObjIterPrepareAll( rbuMPrintfExec(p, p->dbMain, "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" " "BEGIN " - " SELECT rbu_tmp_insert(2, %s);" + " SELECT rbu_tmp_insert(3, %s);" "END;" "CREATE TEMP TRIGGER rbu_update1_tr BEFORE UPDATE ON \"%s%w\" " "BEGIN " - " SELECT rbu_tmp_insert(2, %s);" + " SELECT rbu_tmp_insert(3, %s);" "END;" "CREATE TEMP TRIGGER rbu_update2_tr AFTER UPDATE ON \"%s%w\" " "BEGIN " - " SELECT rbu_tmp_insert(3, %s);" + " SELECT rbu_tmp_insert(4, %s);" "END;", zWrite, zTbl, zOldlist, zWrite, zTbl, zOldlist, @@ -2509,14 +2510,12 @@ static int rbuStepType(sqlite3rbu *p, const char **pzMask){ switch( sqlite3_column_type(p->objiter.pSelect, iCol) ){ case SQLITE_INTEGER: { int iVal = sqlite3_column_int(p->objiter.pSelect, iCol); - if( iVal==0 ){ - res = RBU_INSERT; - }else if( iVal==1 ){ - res = RBU_DELETE; - }else if( iVal==2 ){ - res = RBU_IDX_DELETE; - }else if( iVal==3 ){ - res = RBU_IDX_INSERT; + switch( iVal ){ + case 0: res = RBU_INSERT; break; + case 1: res = RBU_DELETE; break; + case 2: res = RBU_REPLACE; break; + case 3: res = RBU_IDX_DELETE; break; + case 4: res = RBU_IDX_INSERT; break; } break; } @@ -2555,6 +2554,67 @@ static void assertColumnName(sqlite3_stmt *pStmt, int iCol, const char *zName){ # define assertColumnName(x,y,z) #endif +/* +** Argument eType must be one of RBU_INSERT, RBU_DELETE, RBU_IDX_INSERT or +** RBU_IDX_DELETE. This function performs the work of a single +** sqlite3rbu_step() call for the type of operation specified by eType. +*/ +static void rbuStepOneOp(sqlite3rbu *p, int eType){ + RbuObjIter *pIter = &p->objiter; + sqlite3_value *pVal; + sqlite3_stmt *pWriter; + int i; + + assert( p->rc==SQLITE_OK ); + assert( eType!=RBU_DELETE || pIter->zIdx==0 ); + + if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){ + pWriter = pIter->pDelete; + }else{ + pWriter = pIter->pInsert; + } + + for(i=0; inCol; i++){ + /* If this is an INSERT into a table b-tree and the table has an + ** explicit INTEGER PRIMARY KEY, check that this is not an attempt + ** to write a NULL into the IPK column. That is not permitted. */ + if( eType==RBU_INSERT + && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i] + && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL + ){ + p->rc = SQLITE_MISMATCH; + p->zErrmsg = sqlite3_mprintf("datatype mismatch"); + return; + } + + if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){ + continue; + } + + pVal = sqlite3_column_value(pIter->pSelect, i); + p->rc = sqlite3_bind_value(pWriter, i+1, pVal); + if( p->rc ) return; + } + if( pIter->zIdx==0 + && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) + ){ + /* For a virtual table, or a table with no primary key, the + ** SELECT statement is: + ** + ** SELECT , rbu_control, rbu_rowid FROM .... + ** + ** Hence column_value(pIter->nCol+1). + */ + assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); + pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); + p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal); + } + if( p->rc==SQLITE_OK ){ + sqlite3_step(pWriter); + p->rc = resetAndCollectError(pWriter, &p->zErrmsg); + } +} + /* ** This function does the work for an sqlite3rbu_step() call. ** @@ -2569,78 +2629,32 @@ static void assertColumnName(sqlite3_stmt *pStmt, int iCol, const char *zName){ static int rbuStep(sqlite3rbu *p){ RbuObjIter *pIter = &p->objiter; const char *zMask = 0; - int i; int eType = rbuStepType(p, &zMask); if( eType ){ + assert( eType==RBU_INSERT || eType==RBU_DELETE + || eType==RBU_REPLACE || eType==RBU_IDX_DELETE + || eType==RBU_IDX_INSERT || eType==RBU_UPDATE + ); assert( eType!=RBU_UPDATE || pIter->zIdx==0 ); if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){ rbuBadControlError(p); } - else if( - eType==RBU_INSERT - || eType==RBU_DELETE - || eType==RBU_IDX_DELETE - || eType==RBU_IDX_INSERT - ){ - sqlite3_value *pVal; - sqlite3_stmt *pWriter; - - assert( eType!=RBU_UPDATE ); - assert( eType!=RBU_DELETE || pIter->zIdx==0 ); - - if( eType==RBU_IDX_DELETE || eType==RBU_DELETE ){ - pWriter = pIter->pDelete; - }else{ - pWriter = pIter->pInsert; - } - - for(i=0; inCol; i++){ - /* If this is an INSERT into a table b-tree and the table has an - ** explicit INTEGER PRIMARY KEY, check that this is not an attempt - ** to write a NULL into the IPK column. That is not permitted. */ - if( eType==RBU_INSERT - && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i] - && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL - ){ - p->rc = SQLITE_MISMATCH; - p->zErrmsg = sqlite3_mprintf("datatype mismatch"); - goto step_out; - } - - if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){ - continue; - } - - pVal = sqlite3_column_value(pIter->pSelect, i); - p->rc = sqlite3_bind_value(pWriter, i+1, pVal); - if( p->rc ) goto step_out; - } - if( pIter->zIdx==0 - && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) - ){ - /* For a virtual table, or a table with no primary key, the - ** SELECT statement is: - ** - ** SELECT , rbu_control, rbu_rowid FROM .... - ** - ** Hence column_value(pIter->nCol+1). - */ - assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); - pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); - p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal); - } - if( p->rc==SQLITE_OK ){ - sqlite3_step(pWriter); - p->rc = resetAndCollectError(pWriter, &p->zErrmsg); - } - }else{ + else if( eType==RBU_REPLACE ){ + if( pIter->zIdx==0 ) rbuStepOneOp(p, RBU_DELETE); + if( p->rc==SQLITE_OK ) rbuStepOneOp(p, RBU_INSERT); + } + else if( eType!=RBU_UPDATE ){ + rbuStepOneOp(p, eType); + } + else{ sqlite3_value *pVal; sqlite3_stmt *pUpdate = 0; assert( eType==RBU_UPDATE ); rbuGetUpdateStmt(p, pIter, zMask, &pUpdate); if( pUpdate ){ + int i; for(i=0; p->rc==SQLITE_OK && inCol; i++){ char c = zMask[pIter->aiSrcOrder[i]]; pVal = sqlite3_column_value(pIter->pSelect, i); diff --git a/manifest b/manifest index 6cf99353de..9153631b3a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_CONFIG_STMTJRNL_SPILL\soption\sfor\ssqlite3_config(). -D 2016-03-07T17:37:37.281 +C Add\sa\snew\srow\stype\sto\sRBU\s(a\speer\sof\sinsert,\supdate\sand\sdelete)\s-\s"delete\sthen\sinsert". +D 2016-03-07T17:39:30.317 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -234,6 +234,7 @@ F ext/rbu/rbu8.test 3bbf2c35d71a843c463efe93946f14ad10c3ede0 F ext/rbu/rbu9.test 0806d1772c9f4981774ff028de6656e4183082af F ext/rbu/rbuA.test c1a7b3e2d926b8f8448bb3b4ae787e314ee4b2b3 F ext/rbu/rbuB.test c25bc325b8072a766e56bb76c001866b405925c2 +F ext/rbu/rbuC.test efe47db508a0269b683cb2a1913a425ffd39a831 F ext/rbu/rbu_common.tcl 0398545fed614f807d5f0ba55a85a51f08ba8f1a F ext/rbu/rbucrash.test 8d2ed5d4b05fef6c00c2a6b5f7ead71fa172a695 F ext/rbu/rbudiff.test 6cc806dc36389292f2a8f5842d0103721df4a07d @@ -241,7 +242,7 @@ F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89 F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06 F ext/rbu/rbufts.test 828cd689da825f0a7b7c53ffc1f6f7fdb6fa5bda F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48 -F ext/rbu/sqlite3rbu.c 371e8bf06cfb3f691adac47eb15ab1073ed92dcf +F ext/rbu/sqlite3rbu.c 0d901d773bf4c9e7d101daaf545263044e7e6615 F ext/rbu/sqlite3rbu.h 0bdeb3be211aaba7d85445fa36f4701a25a3dbde F ext/rbu/test_rbu.c 4a4cdcef4ef9379fc2a21f008805c80b27bcf573 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -1453,7 +1454,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d8d89d69a490a708b83147945f74134ae0e4b387 -R bbf6d9fea009c5097a1f1af27ba30392 -U drh -Z 638bda7b36ac0921edfae65baff4e139 +P b6c4202432dc96f8f1740f52d0bf872116357fcc +R 56e1f15e83703ebf857ebd55a98bbcfe +T *branch * rbu-delete-then-insert +T *sym-rbu-delete-then-insert * +T -sym-trunk * +U dan +Z 681ea677d41a7fd6408ffd5219102c46 diff --git a/manifest.uuid b/manifest.uuid index 9a5e54bf85..683dc4199a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b6c4202432dc96f8f1740f52d0bf872116357fcc \ No newline at end of file +169311c85b30f625bdb6986c9cd11db70942d73b \ No newline at end of file From 237b2b7111b4d8df3417b6a4aa77546609ada1db Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 7 Mar 2016 19:08:27 +0000 Subject: [PATCH 02/57] Avoid a NULL pointer dereference following an OOM while generating code for IN operators on virtual tables. FossilOrigin-Name: c924008692e35f1f5144830af08d6de051dd21dd --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/wherecode.c | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6cf99353de..381efdf956 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_CONFIG_STMTJRNL_SPILL\soption\sfor\ssqlite3_config(). -D 2016-03-07T17:37:37.281 +C Avoid\sa\sNULL\spointer\sdereference\sfollowing\san\sOOM\swhile\sgenerating\scode\nfor\sIN\soperators\son\svirtual\stables. +D 2016-03-07T19:08:27.802 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -430,7 +430,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c ccc62c39af1e6340f6af36fcf68efb96482d4c3a F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 -F src/wherecode.c 3ca820435c5b597bb50e63ed11e938786fe5c23e +F src/wherecode.c 870f3e92602f216701a14d3f26805caffbfb5c34 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1453,7 +1453,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d8d89d69a490a708b83147945f74134ae0e4b387 -R bbf6d9fea009c5097a1f1af27ba30392 +P b6c4202432dc96f8f1740f52d0bf872116357fcc +R e48be4f1fe6a73cf9fce9701a7a4b585 U drh -Z 638bda7b36ac0921edfae65baff4e139 +Z 61bc8adb3df986a31e200efbd3ce6ae3 diff --git a/manifest.uuid b/manifest.uuid index 9a5e54bf85..c96048b4e5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b6c4202432dc96f8f1740f52d0bf872116357fcc \ No newline at end of file +c924008692e35f1f5144830af08d6de051dd21dd \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index bfc52fb470..1f5a324ec0 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -932,8 +932,10 @@ Bitmask sqlite3WhereCodeOneLoopStart( if( pCompare ){ pCompare->pLeft = pTerm->pExpr->pLeft; pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); - if( pRight ) pRight->iTable = iReg+j+2; - sqlite3ExprIfFalse(pParse, pCompare, pLevel->addrCont, 0); + if( pRight ){ + pRight->iTable = iReg+j+2; + sqlite3ExprIfFalse(pParse, pCompare, pLevel->addrCont, 0); + } pCompare->pLeft = 0; sqlite3ExprDelete(db, pCompare); } From 108b7953ed1ec8b434edcd3764bed457fedab4bd Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 7 Mar 2016 20:14:27 +0000 Subject: [PATCH 03/57] Update fts3/4 so that the 'merge=X,0' command merges X pages from all segments of the first level in the fts index that contains 2 or more segments. FossilOrigin-Name: cddf69dbc46f10ee7e87538dd850e086386b544c --- ext/fts3/fts3_write.c | 13 +++- manifest | 17 +++-- manifest.uuid | 2 +- test/fts4merge.test | 1 - test/fts4opt.test | 169 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+), 14 deletions(-) create mode 100644 test/fts4opt.test diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index d5a408222e..6a2299fccf 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -333,7 +333,8 @@ static int fts3SqlStmt( ** of the oldest level in the db that contains at least ? segments. Or, ** if no level in the FTS index contains more than ? segments, the statement ** returns zero rows. */ -/* 28 */ "SELECT level FROM %Q.'%q_segdir' GROUP BY level HAVING count(*)>=?" +/* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' " + " GROUP BY level HAVING cnt>=?" " ORDER BY (level %% 1024) ASC LIMIT 1", /* Estimate the upper limit on the number of leaf nodes in a new segment @@ -4836,10 +4837,14 @@ int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){ ** set nSeg to -1. */ rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0); - sqlite3_bind_int(pFindLevel, 1, nMin); + sqlite3_bind_int(pFindLevel, 1, MAX(2, nMin)); if( sqlite3_step(pFindLevel)==SQLITE_ROW ){ iAbsLevel = sqlite3_column_int64(pFindLevel, 0); - nSeg = nMin; + if( nMin<2 ){ + nSeg = sqlite3_column_int(pFindLevel, 1); + }else{ + nSeg = nMin; + } }else{ nSeg = -1; } @@ -4991,7 +4996,7 @@ static int fts3DoIncrmerge( nMin = fts3Getint(&z); } - if( z[0]!='\0' || nMin<2 ){ + if( z[0]!='\0' || nMin<0 || nMin==1 ){ rc = SQLITE_ERROR; }else{ rc = SQLITE_OK; diff --git a/manifest b/manifest index 381efdf956..c6b7f7d8a4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sa\sNULL\spointer\sdereference\sfollowing\san\sOOM\swhile\sgenerating\scode\nfor\sIN\soperators\son\svirtual\stables. -D 2016-03-07T19:08:27.802 +C Update\sfts3/4\sso\sthat\sthe\s'merge=X,0'\scommand\smerges\sX\spages\sfrom\sall\ssegments\sof\sthe\sfirst\slevel\sin\sthe\sfts\sindex\sthat\scontains\s2\sor\smore\ssegments. +D 2016-03-07T20:14:27.338 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -88,7 +88,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 F ext/fts3/fts3_unicode2.c c3d01968d497bd7001e7dc774ba75b372738c057 -F ext/fts3/fts3_write.c f442223e4a1914dc1fc12b65af7e4f2c255fa47c +F ext/fts3/fts3_write.c f56345c64387ca30bf91b91511082fa83d9b5178 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/fts3/tool/fts3view.c 5d78b668f4e9598af9147f8999632599fb0d9dd5 @@ -748,12 +748,13 @@ F test/fts4growth.test 60d6bb3f78e25b34f533797dd9f2f9402310a13a F test/fts4growth2.test 13ad4e76451af6e6906c95cdc725d01b00044269 F test/fts4incr.test 4e353a0bd886ea984e56fce9e77724fc923b8d0d F test/fts4langid.test 9794addcc8faaee85ac60eceecdb52feb0c70f68 -F test/fts4merge.test c424309743fdd203f8e56a1f1cd7872cd66cc0ee +F test/fts4merge.test 146563df4a90ccb7f111a6e11ab29bbfe9e6ce2c F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891 F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7 F test/fts4merge4.test d895b1057a7798b67e03455d0fa50e9ea836c47b F test/fts4noti.test 5553d7bb2e20bf4a06b23e849352efc022ce6309 F test/fts4onepass.test 7319d61a2ed1325fc54afd0c060a0513b462303a +F test/fts4opt.test f15c84305c4b78c665fc476d8569e27ab9a0d418 F test/fts4unicode.test 27378af76394542cf490cf001d8d1505fe55f6a9 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/func.test ae97561957aba6ca9e3a7b8a13aac41830d701ef @@ -1453,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b6c4202432dc96f8f1740f52d0bf872116357fcc -R e48be4f1fe6a73cf9fce9701a7a4b585 -U drh -Z 61bc8adb3df986a31e200efbd3ce6ae3 +P c924008692e35f1f5144830af08d6de051dd21dd +R f3add94e73abe6caae33e7ec37099121 +U dan +Z db7aad48334dff0e6979b8c94cd633a5 diff --git a/manifest.uuid b/manifest.uuid index c96048b4e5..9c4f38bdba 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c924008692e35f1f5144830af08d6de051dd21dd \ No newline at end of file +cddf69dbc46f10ee7e87538dd850e086386b544c \ No newline at end of file diff --git a/test/fts4merge.test b/test/fts4merge.test index fabb651e64..41f91fdc8f 100644 --- a/test/fts4merge.test +++ b/test/fts4merge.test @@ -89,7 +89,6 @@ foreach mod {fts3 fts4} { 5 {merge=6,%} 6 {merge=6,six} 7 {merge=6,1} - 8 {merge=6,0} } { do_catchsql_test 2.$tn { INSERT INTO t2(t2) VALUES($arg); diff --git a/test/fts4opt.test b/test/fts4opt.test new file mode 100644 index 0000000000..5638aff1b1 --- /dev/null +++ b/test/fts4opt.test @@ -0,0 +1,169 @@ +# 2016 March 8 +# +# 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. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4opt + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table +# with the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +do_execsql_test 1.0 { CREATE TABLE t1(docid, words) } +fts_kjv_genesis + +#------------------------------------------------------------------------- +# Argument $db is an open database handle. $tbl is the name of an FTS3/4 +# table with the database. This command rearranges the contents of the +# %_segdir table so that all segments within each index are on the same +# level. This means that the 'merge' command can then be used for an +# incremental optimize routine. +# +proc prepare_for_optimize {db tbl} { + $db eval [string map [list % $tbl] { + BEGIN; + CREATE TEMP TABLE tmp_segdir( + level, idx, start_block, leaves_end_block, end_block, root + ); + + INSERT INTO temp.tmp_segdir + SELECT + 1024*(o.level / 1024) + 32, -- level + sum(o.leveli.idx)), -- idx + o.start_block, o.leaves_end_block, o.end_block, o.root -- other + FROM %_segdir o, %_segdir i + WHERE (o.level / 1024) = (i.level / 1024) + GROUP BY o.level, o.idx; + + DELETE FROM %_segdir; + INSERT INTO %_segdir SELECT * FROM temp.tmp_segdir; + DROP TABLE temp.tmp_segdir; + + COMMIT; + }] +} + +do_test 1.1 { + execsql { CREATE VIRTUAL TABLE t2 USING fts4(words, prefix="1,2,3") } + foreach {docid words} [db eval { SELECT * FROM t1 }] { + execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) } + } +} {} + +do_execsql_test 1.2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 0 13 1 15 2 5 + 1024 13 1025 15 1026 5 + 2048 13 2049 15 2050 5 + 3072 13 3073 15 3074 5 +} + +do_execsql_test 1.3 { INSERT INTO t2(t2) VALUES('integrity-check') } +prepare_for_optimize db t2 +do_execsql_test 1.4 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 1.5 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 32 33 + 1056 33 + 2080 33 + 3104 33 +} + +do_test 1.6 { + while 1 { + set tc1 [db total_changes] + execsql { INSERT INTO t2(t2) VALUES('merge=5,0') } + set tc2 [db total_changes] + if {($tc2 - $tc1) < 2} break + } + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } +} {33 1 1057 1 2081 1 3105 1} +do_execsql_test 1.7 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 1.8 { + INSERT INTO t2(words) SELECT words FROM t1; + SELECT level, count(*) FROM t2_segdir GROUP BY level; +} {0 2 1024 2 2048 2 3072 2} + +#------------------------------------------------------------------------- + +do_execsql_test 2.0 { + DELETE FROM t2; +} +do_test 2.1 { + foreach {docid words} [db eval { SELECT * FROM t1 }] { + execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) } + } + + set i 0 + foreach {docid words} [db eval { SELECT * FROM t1 }] { + if {[incr i] % 2} { execsql { DELETE FROM t2 WHERE docid = $docid } } + } + + set i 0 + foreach {docid words} [db eval { SELECT * FROM t1 }] { + if {[incr i] % 3} { + execsql { INSERT OR REPLACE INTO t2(docid, words) VALUES($docid, $words) } + } + } +} {} + +do_execsql_test 2.2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 0 10 1 15 2 12 + 1024 10 1025 15 1026 12 + 2048 10 2049 15 2050 12 + 3072 10 3073 15 3074 12 +} + +do_execsql_test 2.3 { INSERT INTO t2(t2) VALUES('integrity-check') } +prepare_for_optimize db t2 +do_execsql_test 2.4 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 2.5 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 32 37 + 1056 37 + 2080 37 + 3104 37 +} + +do_test 2.6 { + while 1 { + set tc1 [db total_changes] + execsql { INSERT INTO t2(t2) VALUES('merge=5,0') } + set tc2 [db total_changes] + if {($tc2 - $tc1) < 2} break + } + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } +} {33 1 1057 1 2081 1 3105 1} +do_execsql_test 2.7 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 2.8 { + INSERT INTO t2(words) SELECT words FROM t1; + SELECT level, count(*) FROM t2_segdir GROUP BY level; +} {0 2 1024 2 2048 2 3072 2} + +finish_test From fb826b8c13d10fbabfd83301979c9779bc8fe8b3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 00:39:58 +0000 Subject: [PATCH 04/57] Changes so that some assert()s in the virtual table query planner are correct even following an OOM error. FossilOrigin-Name: 9805f6f85211dcb5a0ab3ceca204e6f2e48530ea --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index c6b7f7d8a4..1361fa2b6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sfts3/4\sso\sthat\sthe\s'merge=X,0'\scommand\smerges\sX\spages\sfrom\sall\ssegments\sof\sthe\sfirst\slevel\sin\sthe\sfts\sindex\sthat\scontains\s2\sor\smore\ssegments. -D 2016-03-07T20:14:27.338 +C Changes\sso\sthat\ssome\sassert()s\sin\sthe\svirtual\stable\squery\splanner\sare\ncorrect\seven\sfollowing\san\sOOM\serror. +D 2016-03-08T00:39:58.482 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -430,7 +430,7 @@ F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c ccc62c39af1e6340f6af36fcf68efb96482d4c3a F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 -F src/wherecode.c 870f3e92602f216701a14d3f26805caffbfb5c34 +F src/wherecode.c 36ea3526e4d297b8438453689176c6543fe67b3a F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c924008692e35f1f5144830af08d6de051dd21dd -R f3add94e73abe6caae33e7ec37099121 -U dan -Z db7aad48334dff0e6979b8c94cd633a5 +P cddf69dbc46f10ee7e87538dd850e086386b544c +R eadc238ea6455af5bdaa5c7ea27cb6ae +U drh +Z 93924e30a271561dfe424f31cad070b7 diff --git a/manifest.uuid b/manifest.uuid index 9c4f38bdba..2b6f7883de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cddf69dbc46f10ee7e87538dd850e086386b544c \ No newline at end of file +9805f6f85211dcb5a0ab3ceca204e6f2e48530ea \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 1f5a324ec0..4c0878a5af 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -915,7 +915,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( ** the xFilter implementation might have changed the datatype or ** encoding of the value in the register, so it *must* be reloaded. */ assert( pLevel->u.in.aInLoop!=0 || db->mallocFailed ); - if( pLevel->u.in.aInLoop!=0 ){ + if( !db->mallocFailed ){ assert( iIn>0 ); pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[--iIn].addrInTop); assert( pOp->opcode==OP_Column || pOp->opcode==OP_Rowid ); From 599d57645625e39738952326d4618f7e86d104c3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 01:11:51 +0000 Subject: [PATCH 05/57] Add a NEVER() to the code generator. Change the parameter name "mExtra" to "mPrereq" in the query planner, to more closely reflect its meaning. FossilOrigin-Name: 721ae51e443647291f3a8f7f2128aa410fee2682 --- manifest | 14 +++++------ manifest.uuid | 2 +- src/where.c | 66 ++++++++++++++++++++++++------------------------- src/wherecode.c | 2 +- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index 1361fa2b6d..773add8218 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Changes\sso\sthat\ssome\sassert()s\sin\sthe\svirtual\stable\squery\splanner\sare\ncorrect\seven\sfollowing\san\sOOM\serror. -D 2016-03-08T00:39:58.482 +C Add\sa\sNEVER()\sto\sthe\scode\sgenerator.\s\sChange\sthe\sparameter\sname\s"mExtra"\nto\s"mPrereq"\sin\sthe\squery\splanner,\sto\smore\sclosely\sreflect\sits\smeaning. +D 2016-03-08T01:11:51.292 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -428,9 +428,9 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c ccc62c39af1e6340f6af36fcf68efb96482d4c3a +F src/where.c 3787158e3b365eec7553d6f1d6596b7fa64ea6de F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 -F src/wherecode.c 36ea3526e4d297b8438453689176c6543fe67b3a +F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cddf69dbc46f10ee7e87538dd850e086386b544c -R eadc238ea6455af5bdaa5c7ea27cb6ae +P 9805f6f85211dcb5a0ab3ceca204e6f2e48530ea +R ee7409507ed80149a169811d9e037a32 U drh -Z 93924e30a271561dfe424f31cad070b7 +Z 2ec5edc1158dca51232e491f1a3a4594 diff --git a/manifest.uuid b/manifest.uuid index 2b6f7883de..4c968a7a8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9805f6f85211dcb5a0ab3ceca204e6f2e48530ea \ No newline at end of file +721ae51e443647291f3a8f7f2128aa410fee2682 \ No newline at end of file diff --git a/src/where.c b/src/where.c index ea62617c53..9ed2d561cb 100644 --- a/src/where.c +++ b/src/where.c @@ -2554,7 +2554,7 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){ */ static int whereLoopAddBtree( WhereLoopBuilder *pBuilder, /* WHERE clause information */ - Bitmask mExtra /* Extra prerequesites for using this table */ + Bitmask mPrereq /* Extra prerequesites for using this table */ ){ WhereInfo *pWInfo; /* WHERE analysis context */ Index *pProbe; /* An index we are evaluating */ @@ -2654,7 +2654,7 @@ static int whereLoopAddBtree( pNew->nOut = 43; assert( 43==sqlite3LogEst(20) ); pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut); pNew->wsFlags = WHERE_AUTO_INDEX; - pNew->prereq = mExtra | pTerm->prereqRight; + pNew->prereq = mPrereq | pTerm->prereqRight; rc = whereLoopInsert(pBuilder, pNew); } } @@ -2675,7 +2675,7 @@ static int whereLoopAddBtree( pNew->nLTerm = 0; pNew->iSortIdx = 0; pNew->rSetup = 0; - pNew->prereq = mExtra; + pNew->prereq = mPrereq; pNew->nOut = rSize; pNew->u.btree.pIndex = pProbe; b = indexMightHelpWithOrderBy(pBuilder, pProbe, pSrc->iCursor); @@ -2762,7 +2762,7 @@ static int whereLoopAddBtree( ** * It is not one of the operators specified in the mExclude mask passed ** as the fourth argument (which in practice is either WO_IN or 0). ** -** Argument mExtra is a mask of tables that must be scanned before the +** Argument mPrereq is a mask of tables that must be scanned before the ** virtual table in question. These are added to the plans prerequisites ** before it is added to pBuilder. ** @@ -2771,7 +2771,7 @@ static int whereLoopAddBtree( */ static int whereLoopAddVirtualOne( WhereLoopBuilder *pBuilder, - Bitmask mExtra, /* Mask of tables that must be used. */ + Bitmask mPrereq, /* Mask of tables that must be used. */ Bitmask mUsable, /* Mask of usable prereqs */ u16 mExclude, /* Exclude terms for this operator */ sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */ @@ -2788,9 +2788,9 @@ static int whereLoopAddVirtualOne( struct SrcList_item *pSrc = &pBuilder->pWInfo->pTabList->a[pNew->iTab]; int nConstraint = pIdxInfo->nConstraint; - assert( (mUsable & mExtra)==mExtra ); + assert( (mUsable & mPrereq)==mPrereq ); *pbIn = 0; - pNew->prereq = mExtra; + pNew->prereq = mPrereq; /* Set the usable flag on the subset of constraints identified by ** arguments mUsable and mExclude. */ @@ -2897,8 +2897,8 @@ static int whereLoopAddVirtualOne( ** Add all WhereLoop objects for a table of the join identified by ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table. ** -** If there are no LEFT or CROSS JOIN joins in the query, both mExtra and -** mUnusable are set to 0. Otherwise, mExtra is a mask of all FROM clause +** If there are no LEFT or CROSS JOIN joins in the query, both mPrereq and +** mUnusable are set to 0. Otherwise, mPrereq is a mask of all FROM clause ** entries that occur before the virtual table in the FROM clause and are ** separated from it by at least one LEFT or CROSS JOIN. Similarly, the ** mUnusable mask contains all FROM clause entries that occur after the @@ -2909,18 +2909,18 @@ static int whereLoopAddVirtualOne( ** ** ... FROM t1, t2 LEFT JOIN t3, t4, vt CROSS JOIN t5, t6; ** -** then mExtra corresponds to (t1, t2) and mUnusable to (t5, t6). +** then mPrereq corresponds to (t1, t2) and mUnusable to (t5, t6). ** -** All the tables in mExtra must be scanned before the current virtual +** All the tables in mPrereq must be scanned before the current virtual ** table. So any terms for which all prerequisites are satisfied by -** mExtra may be specified as "usable" in all calls to xBestIndex. +** mPrereq may be specified as "usable" in all calls to xBestIndex. ** Conversely, all tables in mUnusable must be scanned after the current ** virtual table, so any terms for which the prerequisites overlap with ** mUnusable should always be configured as "not-usable" for xBestIndex. */ static int whereLoopAddVirtual( WhereLoopBuilder *pBuilder, /* WHERE clause information */ - Bitmask mExtra, /* Tables that must be scanned before this one */ + Bitmask mPrereq, /* Tables that must be scanned before this one */ Bitmask mUnusable /* Tables that must be scanned after this one */ ){ int rc = SQLITE_OK; /* Return code */ @@ -2934,7 +2934,7 @@ static int whereLoopAddVirtual( WhereLoop *pNew; Bitmask mBest; /* Tables used by best possible plan */ - assert( (mExtra & mUnusable)==0 ); + assert( (mPrereq & mUnusable)==0 ); pWInfo = pBuilder->pWInfo; pParse = pWInfo->pParse; pWC = pBuilder->pWC; @@ -2954,8 +2954,8 @@ static int whereLoopAddVirtual( } /* First call xBestIndex() with all constraints usable. */ - rc = whereLoopAddVirtualOne(pBuilder, mExtra, (Bitmask)(-1), 0, p, &bIn); - mBest = pNew->prereq & ~mExtra; + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, (Bitmask)(-1), 0, p, &bIn); + mBest = pNew->prereq & ~mPrereq; /* If the call to xBestIndex() with all terms enabled produced a plan ** that does not require any source tables, there is no point in making @@ -2971,15 +2971,15 @@ static int whereLoopAddVirtual( /* If the plan produced by the earlier call uses an IN(...) term, call ** xBestIndex again, this time with IN(...) terms disabled. */ if( rc==SQLITE_OK && bIn ){ - rc = whereLoopAddVirtualOne(pBuilder, mExtra, (Bitmask)-1, WO_IN, p,&bIn); - mBestNoIn = pNew->prereq & ~mExtra; + rc = whereLoopAddVirtualOne(pBuilder,mPrereq,(Bitmask)-1,WO_IN,p,&bIn); + mBestNoIn = pNew->prereq & ~mPrereq; if( mBestNoIn==0 ){ seenZero = 1; if( bIn==0 ) seenZeroNoIN = 1; } } - /* Call xBestIndex once for each distinct value of (prereqRight & ~mExtra) + /* Call xBestIndex once for each distinct value of (prereqRight & ~mPrereq) ** in the set of terms that apply to the current virtual table. */ while( rc==SQLITE_OK ){ int i; @@ -2987,15 +2987,15 @@ static int whereLoopAddVirtual( assert( mNext>0 ); for(i=0; ia[p->aConstraint[i].iTermOffset].prereqRight & ~mExtra + pWC->a[p->aConstraint[i].iTermOffset].prereqRight & ~mPrereq ); if( mThis>mPrev && mThisprereq==mExtra ){ + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mNext|mPrereq, 0, p, &bIn); + if( pNew->prereq==mPrereq ){ seenZero = 1; if( bIn==0 ) seenZeroNoIN = 1; } @@ -3005,7 +3005,7 @@ static int whereLoopAddVirtual( ** that requires no source tables at all (i.e. one guaranteed to be ** usable), make a call here with all source tables disabled */ if( rc==SQLITE_OK && seenZero==0 ){ - rc = whereLoopAddVirtualOne(pBuilder, mExtra, mExtra, 0, p, &bIn); + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mPrereq, 0, p, &bIn); if( bIn==0 ) seenZeroNoIN = 1; } @@ -3013,7 +3013,7 @@ static int whereLoopAddVirtual( ** that requires no source tables at all and does not use an IN(...) ** operator, make a final call to obtain one here. */ if( rc==SQLITE_OK && seenZeroNoIN==0 ){ - rc = whereLoopAddVirtualOne(pBuilder, mExtra, mExtra, WO_IN, p, &bIn); + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mPrereq, WO_IN, p, &bIn); } } @@ -3029,7 +3029,7 @@ static int whereLoopAddVirtual( */ static int whereLoopAddOr( WhereLoopBuilder *pBuilder, - Bitmask mExtra, + Bitmask mPrereq, Bitmask mUnusable ){ WhereInfo *pWInfo = pBuilder->pWInfo; @@ -3090,14 +3090,14 @@ static int whereLoopAddOr( #endif #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pItem->pTab) ){ - rc = whereLoopAddVirtual(&sSubBuild, mExtra, mUnusable); + rc = whereLoopAddVirtual(&sSubBuild, mPrereq, mUnusable); }else #endif { - rc = whereLoopAddBtree(&sSubBuild, mExtra); + rc = whereLoopAddBtree(&sSubBuild, mPrereq); } if( rc==SQLITE_OK ){ - rc = whereLoopAddOr(&sSubBuild, mExtra, mUnusable); + rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable); } assert( rc==SQLITE_OK || sCur.n==0 ); if( sCur.n==0 ){ @@ -3154,7 +3154,7 @@ static int whereLoopAddOr( */ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){ WhereInfo *pWInfo = pBuilder->pWInfo; - Bitmask mExtra = 0; + Bitmask mPrereq = 0; Bitmask mPrior = 0; int iTab; SrcList *pTabList = pWInfo->pTabList; @@ -3175,7 +3175,7 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){ if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){ /* This condition is true when pItem is the FROM clause term on the ** right-hand-side of a LEFT or CROSS JOIN. */ - mExtra = mPrior; + mPrereq = mPrior; } priorJointype = pItem->fg.jointype; if( IsVirtual(pItem->pTab) ){ @@ -3185,12 +3185,12 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){ mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor); } } - rc = whereLoopAddVirtual(pBuilder, mExtra, mUnusable); + rc = whereLoopAddVirtual(pBuilder, mPrereq, mUnusable); }else{ - rc = whereLoopAddBtree(pBuilder, mExtra); + rc = whereLoopAddBtree(pBuilder, mPrereq); } if( rc==SQLITE_OK ){ - rc = whereLoopAddOr(pBuilder, mExtra, mUnusable); + rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable); } mPrior |= pNew->maskSelf; if( rc || db->mallocFailed ) break; diff --git a/src/wherecode.c b/src/wherecode.c index 4c0878a5af..3705aab51d 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -882,7 +882,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( for(j=0; jaLTerm[j]; - if( pTerm==0 ) continue; + if( NEVER(pTerm==0) ) continue; if( pTerm->eOperator & WO_IN ){ codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget); addrNotFound = pLevel->addrNxt; From 8426e36c8f55d4b73892afd4c81aa67d2735ced3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 01:32:30 +0000 Subject: [PATCH 06/57] Add the ALLBITS macro as a shorthand for "(Bitmask)(-1)". FossilOrigin-Name: 91bd619d27e4d91510a187bbb88de961a31c8a2e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/sqliteInt.h | 1 + src/update.c | 2 +- src/where.c | 18 +++++++++--------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 773add8218..4cdc82a8c0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sNEVER()\sto\sthe\scode\sgenerator.\s\sChange\sthe\sparameter\sname\s"mExtra"\nto\s"mPrereq"\sin\sthe\squery\splanner,\sto\smore\sclosely\sreflect\sits\smeaning. -D 2016-03-08T01:11:51.292 +C Add\sthe\sALLBITS\smacro\sas\sa\sshorthand\sfor\s"(Bitmask)(-1)". +D 2016-03-08T01:32:30.559 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -353,7 +353,7 @@ F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 0235586b3fb639e85998d495c90f007657fd82af F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 8c32c1f4566c577cfb8e1c96e56f61e8b3e780d7 +F src/sqliteInt.h 4c7b8501b37eb768a5457b01cb9a9a5505f3fd85 F src/sqliteLimit.h 7b28cf72cbd52f178bfc97ea266445e351f2cd24 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -410,7 +410,7 @@ F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 3d338cdd00d916ce8a05c397001d64ed58e6fe1c F src/treeview.c e4b41a37530a191579d3c53142cc44ee2eb99373 F src/trigger.c e14840ee0c3e549e758ec9bf3e4146e166002280 -F src/update.c a7eeeaffad59c6506f01303a071dac11de8269ca +F src/update.c 56b3db7edff0110360a12b76af97c39ebe3ea8b8 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c 12800a93f0664f41575f96799eb881a786d565e6 F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52 @@ -428,7 +428,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c 3787158e3b365eec7553d6f1d6596b7fa64ea6de +F src/where.c e4d2d0ea8403339db188e75b75ca44fff225abba F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9805f6f85211dcb5a0ab3ceca204e6f2e48530ea -R ee7409507ed80149a169811d9e037a32 +P 721ae51e443647291f3a8f7f2128aa410fee2682 +R 06f3b1fde5a5e4d09bcfebd9ae1525b6 U drh -Z 2ec5edc1158dca51232e491f1a3a4594 +Z acf689ff3c45ad889c44d18cadd3bf9c diff --git a/manifest.uuid b/manifest.uuid index 4c968a7a8f..78794d5451 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -721ae51e443647291f3a8f7f2128aa410fee2682 \ No newline at end of file +91bd619d27e4d91510a187bbb88de961a31c8a2e \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e9aab2e1bd..ff4dbd4864 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2353,6 +2353,7 @@ struct IdList { */ #define MASKBIT(n) (((Bitmask)1)<<(n)) #define MASKBIT32(n) (((unsigned int)1)<<(n)) +#define ALLBITS ((Bitmask)-1) /* ** The following structure describes the FROM clause of a SELECT statement. diff --git a/src/update.c b/src/update.c index 2a436b9701..9b351662e2 100644 --- a/src/update.c +++ b/src/update.c @@ -268,7 +268,7 @@ void sqlite3Update( ** case, set all bits of the colUsed mask (to ensure that the virtual ** table implementation makes all columns available). */ - pTabList->a[0].colUsed = IsVirtual(pTab) ? (Bitmask)-1 : 0; + pTabList->a[0].colUsed = IsVirtual(pTab) ? ALLBITS : 0; hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey); diff --git a/src/where.c b/src/where.c index 9ed2d561cb..7510839791 100644 --- a/src/where.c +++ b/src/where.c @@ -2771,9 +2771,9 @@ static int whereLoopAddBtree( */ static int whereLoopAddVirtualOne( WhereLoopBuilder *pBuilder, - Bitmask mPrereq, /* Mask of tables that must be used. */ - Bitmask mUsable, /* Mask of usable prereqs */ - u16 mExclude, /* Exclude terms for this operator */ + Bitmask mPrereq, /* Mask of tables that must be used. */ + Bitmask mUsable, /* Mask of usable tables */ + u16 mExclude, /* Exclude terms using these operators */ sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */ int *pbIn /* OUT: True if plan uses an IN(...) op */ ){ @@ -2941,7 +2941,7 @@ static int whereLoopAddVirtual( pNew = pBuilder->pNew; pSrc = &pWInfo->pTabList->a[pNew->iTab]; assert( IsVirtual(pSrc->pTab) ); - p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc,pBuilder->pOrderBy); + p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy); if( p==0 ) return SQLITE_NOMEM_BKPT; pNew->rSetup = 0; pNew->wsFlags = WHERE_VIRTUALTABLE; @@ -2954,7 +2954,7 @@ static int whereLoopAddVirtual( } /* First call xBestIndex() with all constraints usable. */ - rc = whereLoopAddVirtualOne(pBuilder, mPrereq, (Bitmask)(-1), 0, p, &bIn); + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, &bIn); mBest = pNew->prereq & ~mPrereq; /* If the call to xBestIndex() with all terms enabled produced a plan @@ -2971,7 +2971,7 @@ static int whereLoopAddVirtual( /* If the plan produced by the earlier call uses an IN(...) term, call ** xBestIndex again, this time with IN(...) terms disabled. */ if( rc==SQLITE_OK && bIn ){ - rc = whereLoopAddVirtualOne(pBuilder,mPrereq,(Bitmask)-1,WO_IN,p,&bIn); + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, WO_IN, p, &bIn); mBestNoIn = pNew->prereq & ~mPrereq; if( mBestNoIn==0 ){ seenZero = 1; @@ -2983,7 +2983,7 @@ static int whereLoopAddVirtual( ** in the set of terms that apply to the current virtual table. */ while( rc==SQLITE_OK ){ int i; - Bitmask mNext = (Bitmask)(-1); + Bitmask mNext = ALLBITS; assert( mNext>0 ); for(i=0; imPrev && mThisprereq==mPrereq ){ @@ -4280,7 +4280,7 @@ WhereInfo *sqlite3WhereBegin( } } if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ - pWInfo->revMask = (Bitmask)(-1); + pWInfo->revMask = ALLBITS; } if( pParse->nErr || NEVER(db->mallocFailed) ){ goto whereBeginError; From 6de32e7cdb9fe691ff3b046d69ebfe458887c3d5 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 02:59:33 +0000 Subject: [PATCH 07/57] Simplified error detection in the xBestIndex processing. FossilOrigin-Name: 82ca2131b670505578628687746135ac413d156b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 13 +++++++++---- test/vtab6.test | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 4cdc82a8c0..02f759a644 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sALLBITS\smacro\sas\sa\sshorthand\sfor\s"(Bitmask)(-1)". -D 2016-03-08T01:32:30.559 +C Simplified\serror\sdetection\sin\sthe\sxBestIndex\sprocessing. +D 2016-03-08T02:59:33.371 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -428,7 +428,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c e4d2d0ea8403339db188e75b75ca44fff225abba +F src/where.c dff52f7f0842430f80a7017c7859124685b08453 F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1286,7 +1286,7 @@ F test/vtab2.test f8cd1bb9aba7143eba97812d9617880a36d247ad F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e F test/vtab4.test 8e73ed268f3d596bc3590f45fc948fb40f28e9c3 F test/vtab5.test 889f444970393c73f1e077e2bdc5d845e157a391 -F test/vtab6.test d2986cf418dc51e7fb81d12366bea2caa8b812df +F test/vtab6.test 8e789f526e6594cf7ae933d1adee0caa87dc9f78 F test/vtab7.test ae560ebea870ed04e9aa4177cc302f910faaabb5 F test/vtab8.test e19fa4a538fcd1bb66c22825fa8f71618fb13583 F test/vtab9.test ea58d2b95d61955f87226381716b2d0b1d4e4f9b @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 721ae51e443647291f3a8f7f2128aa410fee2682 -R 06f3b1fde5a5e4d09bcfebd9ae1525b6 +P 91bd619d27e4d91510a187bbb88de961a31c8a2e +R 925559caeda122c2e0a2ca4fc28cc0ee U drh -Z acf689ff3c45ad889c44d18cadd3bf9c +Z b4b54118bbf4d13b5c60372c03985e73 diff --git a/manifest.uuid b/manifest.uuid index 78794d5451..21eda15faa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -91bd619d27e4d91510a187bbb88de961a31c8a2e \ No newline at end of file +82ca2131b670505578628687746135ac413d156b \ No newline at end of file diff --git a/src/where.c b/src/where.c index 7510839791..2d7272a742 100644 --- a/src/where.c +++ b/src/where.c @@ -934,7 +934,6 @@ static sqlite3_index_info *allocateIndexInfo( */ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; - int i; int rc; TRACE_IDX_INPUTS(p); @@ -953,12 +952,16 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ sqlite3_free(pVtab->zErrMsg); pVtab->zErrMsg = 0; +#if 0 + /* This error is now caught by the caller. + ** Search for "xBestIndex malfunction" below */ for(i=0; inConstraint; i++){ if( !p->aConstraint[i].usable && p->aConstraintUsage[i].argvIndex>0 ){ sqlite3ErrorMsg(pParse, "table %s: xBestIndex returned an invalid plan", pTab->zName); } } +#endif return pParse->nErr; } @@ -2835,9 +2838,10 @@ static int whereLoopAddVirtualOne( || j<0 || j>=pWC->nTerm || pNew->aLTerm[iTerm]!=0 + || pIdxCons->usable==0 ){ rc = SQLITE_ERROR; - sqlite3ErrorMsg(pParse,"%s.xBestIndex() malfunction",pSrc->pTab->zName); + sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName); return rc; } testcase( iTerm==nConstraint-1 ); @@ -2859,7 +2863,7 @@ static int whereLoopAddVirtualOne( ** together. */ pIdxInfo->orderByConsumed = 0; pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE; - *pbIn = 1; + *pbIn = 1; assert( (mExclude & WO_IN)==0 ); } } } @@ -2972,10 +2976,11 @@ static int whereLoopAddVirtual( ** xBestIndex again, this time with IN(...) terms disabled. */ if( rc==SQLITE_OK && bIn ){ rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, WO_IN, p, &bIn); + assert( bIn==0 ); mBestNoIn = pNew->prereq & ~mPrereq; if( mBestNoIn==0 ){ seenZero = 1; - if( bIn==0 ) seenZeroNoIN = 1; + seenZeroNoIN = 1; } } diff --git a/test/vtab6.test b/test/vtab6.test index f8e0935a28..f4504b017d 100644 --- a/test/vtab6.test +++ b/test/vtab6.test @@ -566,12 +566,12 @@ do_test vtab6-11.4.1 { catchsql { SELECT a, b, c FROM ab NATURAL JOIN bc; } -} {1 {table ab: xBestIndex returned an invalid plan}} +} {1 {ab.xBestIndex malfunction}} do_test vtab6-11.4.2 { catchsql { SELECT a, b, c FROM bc NATURAL JOIN ab; } -} {1 {table bc: xBestIndex returned an invalid plan}} +} {1 {bc.xBestIndex malfunction}} unset ::echo_module_ignore_usable From 0dba3304f61cc07aac8e64421eec824db7792584 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 13:56:02 +0000 Subject: [PATCH 08/57] Fix comments on pager flag settings to include synchronous=EXTRA. FossilOrigin-Name: 3a65a1fc0fd2408c6984153801ec5dcd5211c897 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 9 +++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 02f759a644..2807800e01 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplified\serror\sdetection\sin\sthe\sxBestIndex\sprocessing. -D 2016-03-08T02:59:33.371 +C Fix\scomments\son\spager\sflag\ssettings\sto\sinclude\ssynchronous=EXTRA. +D 2016-03-08T13:56:02.581 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -335,7 +335,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c f5bac8e74aaefc4ea520e43b4540793c3b8a9e8f F src/os_win.c f0d7aa603eb6262143d7169a222aea07c4fca91d F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca -F src/pager.c d40cf1e890a0582b6ac7cb208c24619d72d2c900 +F src/pager.c 17aa37b3b53a62a1bd98fe6f3c758bb41429ef08 F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56 F src/parse.y 5ea8c81c5c41b27887f41b4a7e1c58470d7d3821 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 91bd619d27e4d91510a187bbb88de961a31c8a2e -R 925559caeda122c2e0a2ca4fc28cc0ee +P 82ca2131b670505578628687746135ac413d156b +R 4e1de8a7b93ab084a5d8af152570ff89 U drh -Z b4b54118bbf4d13b5c60372c03985e73 +Z 8d271451485b418fda3cdda213f61b81 diff --git a/manifest.uuid b/manifest.uuid index 21eda15faa..9831ba312c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -82ca2131b670505578628687746135ac413d156b \ No newline at end of file +3a65a1fc0fd2408c6984153801ec5dcd5211c897 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index f045ce0eff..6cc6ebff42 100644 --- a/src/pager.c +++ b/src/pager.c @@ -3460,7 +3460,7 @@ void sqlite3PagerShrink(Pager *pPager){ ** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness ** of the database to damage due to OS crashes or power failures by ** changing the number of syncs()s when writing the journals. -** There are three levels: +** There are four levels: ** ** OFF sqlite3OsSync() is never called. This is the default ** for temporary and transient files. @@ -3480,6 +3480,10 @@ void sqlite3PagerShrink(Pager *pPager){ ** assurance that the journal will not be corrupted to the ** point of causing damage to the database during rollback. ** +** EXTRA This is like FULL except that is also syncs the directory +** that contains the rollback journal after the rollback +** journal is unlinked. +** ** The above is for a rollback-journal mode. For WAL mode, OFF continues ** to mean that no syncs ever occur. NORMAL means that the WAL is synced ** prior to the start of checkpoint and that the database file is synced @@ -3487,7 +3491,8 @@ void sqlite3PagerShrink(Pager *pPager){ ** was written back into the database. But no sync operations occur for ** an ordinary commit in NORMAL mode with WAL. FULL means that the WAL ** file is synced following each commit operation, in addition to the -** syncs associated with NORMAL. +** syncs associated with NORMAL. There is no difference between FULL +** and EXTRA for WAL mode. ** ** Do not confuse synchronous=FULL with SQLITE_SYNC_FULL. The ** SQLITE_SYNC_FULL macro means to use the MacOSX-style full-fsync From 6702f761ea6e942b042952376e086c64b69d193a Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 14:16:23 +0000 Subject: [PATCH 09/57] Fix ATTACH to use the symbolic name PAGER_SYNCHRONOUS_FULL rather than an integer literal. FossilOrigin-Name: c4e192a0e5a408e198dbacb2752859a00d2b572f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/attach.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2807800e01..cff32735ef 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scomments\son\spager\sflag\ssettings\sto\sinclude\ssynchronous=EXTRA. -D 2016-03-08T13:56:02.581 +C Fix\sATTACH\sto\suse\sthe\ssymbolic\sname\sPAGER_SYNCHRONOUS_FULL\srather\sthan\nan\sinteger\sliteral. +D 2016-03-08T14:16:23.535 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -287,7 +287,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 1bb0709b3048e24217b80ec6bd78a3e99a47c01b F src/analyze.c ab57b6763dd4c6170a20673d14882c033affd188 -F src/attach.c a3724c64de1099d85e30751213d285752aed9505 +F src/attach.c 34b254f398339c5283f91684bff6d9b19a899255 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63 @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 82ca2131b670505578628687746135ac413d156b -R 4e1de8a7b93ab084a5d8af152570ff89 +P 3a65a1fc0fd2408c6984153801ec5dcd5211c897 +R 713ccf93fbf940d5f93658dc674d69a8 U drh -Z 8d271451485b418fda3cdda213f61b81 +Z 60af40306ae0297078d0f487c0fa1cd6 diff --git a/manifest.uuid b/manifest.uuid index 9831ba312c..60ec4c1d29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3a65a1fc0fd2408c6984153801ec5dcd5211c897 \ No newline at end of file +c4e192a0e5a408e198dbacb2752859a00d2b572f \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 484a5a110c..3101357113 100644 --- a/src/attach.c +++ b/src/attach.c @@ -161,7 +161,7 @@ static void attachFunc( #endif sqlite3BtreeLeave(aNew->pBt); } - aNew->safety_level = 3; + aNew->safety_level = PAGER_SYNCHRONOUS_FULL; aNew->zName = sqlite3DbStrDup(db, zName); if( rc==SQLITE_OK && aNew->zName==0 ){ rc = SQLITE_NOMEM_BKPT; From 50a1a5aaca05efe5682668e009146023b05688c9 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 14:40:11 +0000 Subject: [PATCH 10/57] Add compile-time options SQLITE_DEFAULT_SYNCHRONOUS and SQLITE_DEFAULT_WAL_SYNCHRONOUS used to specify the default synchronous settings for all database connections. FossilOrigin-Name: 1fefa967aa93372d232b96b1e0232b7b855d6d00 --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/attach.c | 2 +- src/main.c | 2 +- src/pragma.c | 1 + src/sqliteInt.h | 11 ++++++++++- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index cff32735ef..63f123d486 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sATTACH\sto\suse\sthe\ssymbolic\sname\sPAGER_SYNCHRONOUS_FULL\srather\sthan\nan\sinteger\sliteral. -D 2016-03-08T14:16:23.535 +C Add\scompile-time\soptions\sSQLITE_DEFAULT_SYNCHRONOUS\sand\nSQLITE_DEFAULT_WAL_SYNCHRONOUS\sused\sto\sspecify\sthe\sdefault\ssynchronous\nsettings\sfor\sall\sdatabase\sconnections. +D 2016-03-08T14:40:11.978 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -287,7 +287,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 1bb0709b3048e24217b80ec6bd78a3e99a47c01b F src/analyze.c ab57b6763dd4c6170a20673d14882c033affd188 -F src/attach.c 34b254f398339c5283f91684bff6d9b19a899255 +F src/attach.c 3d23c66919305799201749c75cae4774a520d773 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63 @@ -313,7 +313,7 @@ F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/insert.c 723d5d708cdb61bdd47c00b9f07c75be45aefc09 F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e F src/loadext.c 9e2a41adcaff16ebc1ebff1f336cbf33de55396f -F src/main.c 93c571d78bc41b257f36912e678db4817d3c540e +F src/main.c ae066482662f47b596ff5441c3efc8f6536761b8 F src/malloc.c 1443d1ad95d67c21d77af7ae3f44678252f0efec F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b @@ -341,7 +341,7 @@ F src/parse.y 5ea8c81c5c41b27887f41b4a7e1c58470d7d3821 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 -F src/pragma.c 42b3f1475b483710ba1dd1cc1ecc0c0f8db59a2e +F src/pragma.c c7061870c235702a513ce4152fe978faf3f282eb F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c F src/prepare.c 22df6171aec1d86904ed2ad30c2348a5748aa04e F src/printf.c 63e6fb12bbe702dd664dc3703776c090383a5a26 @@ -353,7 +353,7 @@ F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 0235586b3fb639e85998d495c90f007657fd82af F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 4c7b8501b37eb768a5457b01cb9a9a5505f3fd85 +F src/sqliteInt.h fa49759aff49ab56eed9c0b4670895924b66aedb F src/sqliteLimit.h 7b28cf72cbd52f178bfc97ea266445e351f2cd24 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -1454,7 +1454,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3a65a1fc0fd2408c6984153801ec5dcd5211c897 -R 713ccf93fbf940d5f93658dc674d69a8 +P c4e192a0e5a408e198dbacb2752859a00d2b572f +R ed8cb54862c87c7000f2b5316b253427 +T *branch * default-synchronous +T *sym-default-synchronous * +T -sym-trunk * U drh -Z 60af40306ae0297078d0f487c0fa1cd6 +Z e2df223f431828867c29b052b714b5b9 diff --git a/manifest.uuid b/manifest.uuid index 60ec4c1d29..789760b567 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c4e192a0e5a408e198dbacb2752859a00d2b572f \ No newline at end of file +1fefa967aa93372d232b96b1e0232b7b855d6d00 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 3101357113..30f6739bba 100644 --- a/src/attach.c +++ b/src/attach.c @@ -161,7 +161,7 @@ static void attachFunc( #endif sqlite3BtreeLeave(aNew->pBt); } - aNew->safety_level = PAGER_SYNCHRONOUS_FULL; + aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS; aNew->zName = sqlite3DbStrDup(db, zName); if( rc==SQLITE_OK && aNew->zName==0 ){ rc = SQLITE_NOMEM_BKPT; diff --git a/src/main.c b/src/main.c index e4252e7aa9..fd74c97e29 100644 --- a/src/main.c +++ b/src/main.c @@ -2878,7 +2878,7 @@ static int openDatabase( ** database it is OFF. This matches the pager layer defaults. */ db->aDb[0].zName = "main"; - db->aDb[0].safety_level = PAGER_SYNCHRONOUS_FULL; + db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS; db->aDb[1].zName = "temp"; db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF; diff --git a/src/pragma.c b/src/pragma.c index 1d62914310..883ab60c67 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -993,6 +993,7 @@ void sqlite3Pragma( int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; if( iLevel==0 ) iLevel = 1; pDb->safety_level = iLevel; + pDb->bSyncSet = 1; setAllPagerFlags(db); } } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index ff4dbd4864..a49601e748 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1002,10 +1002,18 @@ typedef struct With With; #include "vdbe.h" #include "pager.h" #include "pcache.h" - #include "os.h" #include "mutex.h" +/* +** Default synchronous levels +*/ +#ifndef SQLITE_DEFAULT_SYNCHRONOUS +# define SQLITE_DEFAULT_SYNCHRONOUS PAGER_SYNCHRONOUS_FULL +#endif +#ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS +# define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS +#endif /* ** Each database file to be accessed by the system is an instance @@ -1018,6 +1026,7 @@ struct Db { char *zName; /* Name of this database */ Btree *pBt; /* The B*Tree structure for this database file */ u8 safety_level; /* How aggressive at syncing data to disk */ + u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */ Schema *pSchema; /* Pointer to database schema (possibly shared) */ }; From e243de5cf51f5799d91b4b9fc7c22800dcfe3a78 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 15:14:26 +0000 Subject: [PATCH 11/57] If SQLITE_DEFAULT_WAL_SYNCHRONOUS is not the same value as SQLITE_DEFAULT_SYNCHRONOUS and the application has not run "PRAGMA synchronous", then set synchronous to the SQLITE_DEFAULT_WAL_SYNCHRONOUS setting when entering WAL mode for the first time. FossilOrigin-Name: 5791407b523abd24e832fc2361b3e9f01ee2f36a --- manifest | 21 +++++++++------------ manifest.uuid | 2 +- src/btree.c | 22 +++++++++++++++++++--- test/unixexcl.test | 1 + test/wal2.test | 2 +- test/zerodamage.test | 1 + 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 63f123d486..64534b8ae9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\scompile-time\soptions\sSQLITE_DEFAULT_SYNCHRONOUS\sand\nSQLITE_DEFAULT_WAL_SYNCHRONOUS\sused\sto\sspecify\sthe\sdefault\ssynchronous\nsettings\sfor\sall\sdatabase\sconnections. -D 2016-03-08T14:40:11.978 +C If\sSQLITE_DEFAULT_WAL_SYNCHRONOUS\sis\snot\sthe\ssame\svalue\sas\nSQLITE_DEFAULT_SYNCHRONOUS\sand\sthe\sapplication\shas\snot\srun\n"PRAGMA\ssynchronous",\sthen\sset\ssynchronous\sto\sthe\s\nSQLITE_DEFAULT_WAL_SYNCHRONOUS\ssetting\swhen\sentering\sWAL\smode\sfor\nthe\sfirst\stime. +D 2016-03-08T15:14:26.164 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -292,7 +292,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63 F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c 7bb920c473c277380fcb3e8a8ee28ce1a48e0abc +F src/btree.c be3ac34a9d669fed0e0b315e4b62fb198b3534a1 F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c 43b93fe757bfffe00f97462596418b052eefdccd @@ -1268,7 +1268,7 @@ F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a F test/unique.test 93f8b2ef5ea51b9495f8d6493429b1fd0f465264 F test/unique2.test 3674e9f2a3f1fbbfd4772ac74b7a97090d0f77d2 -F test/unixexcl.test cd6c765f75e50e8e2c2ba763149e5d340ea19825 +F test/unixexcl.test d936ba2b06794018e136418addd59a2354eeae97 F test/unordered.test ca7adce0419e4ca0c50f039885e76ed2c531eda8 F test/update.test 6c68446b8a0a33d522a7c72b320934596a2d7d32 F test/uri.test 6630ecbdea2aac10df3c89dbae2243f4c2c353e4 @@ -1302,7 +1302,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad F test/wal.test 0148c8b3421a25fdb4d9c160e84a681d0646371b -F test/wal2.test 1f841d2048080d32f552942e333fd99ce541dada +F test/wal2.test 25ae059e900dbb584e0775627e45415ba5940df1 F test/wal3.test 5dd734147f1f8f958c5261a1f2775d346d7013ce F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c F test/wal5.test 88b5d9a6a3d1532497ee9f4296f010d66f07e33c @@ -1368,7 +1368,7 @@ F test/without_rowid5.test 89b1c587bd92a0590e440da33e7666bf4891572a F test/without_rowid6.test 1f99644e6508447fb050f73697350c7ceca3392e F test/wordcount.c 2a0a6c0d0e8e8bbbac1f06d72a6791828c37c0cf F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa -F test/zerodamage.test cf6748bad89553cc1632be51a6f54e487e4039ac +F test/zerodamage.test 2d725c214b883e25ae6bb85ef228ecdfa03c6a7b F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 629d87562e0487c386db630033931d12d62e6372 F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91 @@ -1454,10 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c4e192a0e5a408e198dbacb2752859a00d2b572f -R ed8cb54862c87c7000f2b5316b253427 -T *branch * default-synchronous -T *sym-default-synchronous * -T -sym-trunk * +P 1fefa967aa93372d232b96b1e0232b7b855d6d00 +R 96b74d7d7452050d9fb3b3bb7ed48b9b U drh -Z e2df223f431828867c29b052b714b5b9 +Z fb25535cfc55b70029b29a9169aa4b7e diff --git a/manifest.uuid b/manifest.uuid index 789760b567..1546aa7117 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1fefa967aa93372d232b96b1e0232b7b855d6d00 \ No newline at end of file +5791407b523abd24e832fc2361b3e9f01ee2f36a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 036e63a016..bc16cbedd4 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2864,9 +2864,25 @@ static int lockBtree(BtShared *pBt){ rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen); if( rc!=SQLITE_OK ){ goto page1_init_failed; - }else if( isOpen==0 ){ - releasePage(pPage1); - return SQLITE_OK; + }else{ +#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS + sqlite3 *db; + Db *pDb; + if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){ + while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; } + if( pDb->bSyncSet==0 + && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS + ){ + pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS; + sqlite3PagerSetFlags(pBt->pPager, + pDb->safety_level | (db->flags & PAGER_FLAGS_MASK)); + } + } +#endif + if( isOpen==0 ){ + releasePage(pPage1); + return SQLITE_OK; + } } rc = SQLITE_NOTADB; } diff --git a/test/unixexcl.test b/test/unixexcl.test index d6762178dd..8e9c4644d1 100644 --- a/test/unixexcl.test +++ b/test/unixexcl.test @@ -87,6 +87,7 @@ do_multiclient_test tn { sql1 { PRAGMA auto_vacuum = 0; PRAGMA journal_mode = WAL; + PRAGMA synchronous = FULL; CREATE TABLE t1(a, b); INSERT INTO t1 VALUES(1, 2); } diff --git a/test/wal2.test b/test/wal2.test index 9d45444d6a..4b9bbf315f 100644 --- a/test/wal2.test +++ b/test/wal2.test @@ -1196,7 +1196,7 @@ foreach {tn sql reslist} { } { faultsim_delete_and_reopen - execsql {PRAGMA auto_vacuum = 0} + execsql {PRAGMA auto_vacuum = 0; PRAGMA synchronous = FULL;} execsql $sql do_execsql_test wal2-14.$tn.0 { PRAGMA page_size = 4096 } {} do_execsql_test wal2-14.$tn.1 { PRAGMA journal_mode = WAL } {wal} diff --git a/test/zerodamage.test b/test/zerodamage.test index dccaba816e..d781ab89a3 100644 --- a/test/zerodamage.test +++ b/test/zerodamage.test @@ -112,6 +112,7 @@ ifcapable wal { db close sqlite3 db file:test.db?psow=FALSE -uri 1 db eval { + PRAGMA synchronous=FULL; UPDATE t1 SET y=randomblob(50) WHERE x=124; } file size test.db-wal From c2ae2073d93f0cd0c85cd7adddbaacd5b622cac1 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 15:30:01 +0000 Subject: [PATCH 12/57] Make the SQLITE_DEFAULT_SYNCHRONOUS and SQLITE_DEFAULT_WAL_SYNCHRONOUS values zero-based to agree with PRAGMA synchronous. FossilOrigin-Name: 592d2104361500e5002783ba329a2609389c57b9 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/attach.c | 2 +- src/btree.c | 4 ++-- src/main.c | 2 +- src/sqliteInt.h | 17 +++++++++++++++-- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 64534b8ae9..f00f793ab6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sSQLITE_DEFAULT_WAL_SYNCHRONOUS\sis\snot\sthe\ssame\svalue\sas\nSQLITE_DEFAULT_SYNCHRONOUS\sand\sthe\sapplication\shas\snot\srun\n"PRAGMA\ssynchronous",\sthen\sset\ssynchronous\sto\sthe\s\nSQLITE_DEFAULT_WAL_SYNCHRONOUS\ssetting\swhen\sentering\sWAL\smode\sfor\nthe\sfirst\stime. -D 2016-03-08T15:14:26.164 +C Make\sthe\sSQLITE_DEFAULT_SYNCHRONOUS\sand\sSQLITE_DEFAULT_WAL_SYNCHRONOUS\nvalues\szero-based\sto\sagree\swith\sPRAGMA\ssynchronous. +D 2016-03-08T15:30:01.003 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -287,12 +287,12 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 1bb0709b3048e24217b80ec6bd78a3e99a47c01b F src/analyze.c ab57b6763dd4c6170a20673d14882c033affd188 -F src/attach.c 3d23c66919305799201749c75cae4774a520d773 +F src/attach.c 771153bd1f4ab0b97a44a13dde2c7e5e1efeba22 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63 F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c be3ac34a9d669fed0e0b315e4b62fb198b3534a1 +F src/btree.c 2712f087351f5c4ff0e71631b1e67b461611b99d F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c 43b93fe757bfffe00f97462596418b052eefdccd @@ -313,7 +313,7 @@ F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/insert.c 723d5d708cdb61bdd47c00b9f07c75be45aefc09 F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e F src/loadext.c 9e2a41adcaff16ebc1ebff1f336cbf33de55396f -F src/main.c ae066482662f47b596ff5441c3efc8f6536761b8 +F src/main.c 29ea8ebb23ceb5159da167e18d5c807fbb1545c4 F src/malloc.c 1443d1ad95d67c21d77af7ae3f44678252f0efec F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b @@ -353,7 +353,7 @@ F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 0235586b3fb639e85998d495c90f007657fd82af F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h fa49759aff49ab56eed9c0b4670895924b66aedb +F src/sqliteInt.h b017fbf491606a0fd1a5d43af40dbe965a928ead F src/sqliteLimit.h 7b28cf72cbd52f178bfc97ea266445e351f2cd24 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1fefa967aa93372d232b96b1e0232b7b855d6d00 -R 96b74d7d7452050d9fb3b3bb7ed48b9b +P 5791407b523abd24e832fc2361b3e9f01ee2f36a +R bba2e4d185d472ce58e719fcfcf03f67 U drh -Z fb25535cfc55b70029b29a9169aa4b7e +Z 6f7df0629a8472a1465e8e2960a9953c diff --git a/manifest.uuid b/manifest.uuid index 1546aa7117..ba3ff1f350 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5791407b523abd24e832fc2361b3e9f01ee2f36a \ No newline at end of file +592d2104361500e5002783ba329a2609389c57b9 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 30f6739bba..ea378a40a2 100644 --- a/src/attach.c +++ b/src/attach.c @@ -161,7 +161,7 @@ static void attachFunc( #endif sqlite3BtreeLeave(aNew->pBt); } - aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS; + aNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; aNew->zName = sqlite3DbStrDup(db, zName); if( rc==SQLITE_OK && aNew->zName==0 ){ rc = SQLITE_NOMEM_BKPT; diff --git a/src/btree.c b/src/btree.c index bc16cbedd4..4b9bba55ac 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2871,9 +2871,9 @@ static int lockBtree(BtShared *pBt){ if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){ while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; } if( pDb->bSyncSet==0 - && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS + && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS+1 ){ - pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS; + pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS+1; sqlite3PagerSetFlags(pBt->pPager, pDb->safety_level | (db->flags & PAGER_FLAGS_MASK)); } diff --git a/src/main.c b/src/main.c index fd74c97e29..70e46a4ee1 100644 --- a/src/main.c +++ b/src/main.c @@ -2878,7 +2878,7 @@ static int openDatabase( ** database it is OFF. This matches the pager layer defaults. */ db->aDb[0].zName = "main"; - db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS; + db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; db->aDb[1].zName = "temp"; db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a49601e748..741caec3e3 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1006,10 +1006,23 @@ typedef struct With With; #include "mutex.h" /* -** Default synchronous levels +** Default synchronous levels. +** +** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ +** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1. +** +** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS +** OFF 1 0 +** NORMAL 2 1 +** FULL 3 2 +** EXTRA 4 3 +** +** The "PRAGMA synchronous" statement also uses the zero-based numbers. +** In other words, the zero-based numbers are used for all external interfaces +** and the one-based values are used internally. */ #ifndef SQLITE_DEFAULT_SYNCHRONOUS -# define SQLITE_DEFAULT_SYNCHRONOUS PAGER_SYNCHRONOUS_FULL +# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1) #endif #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS From c7dbce0f2a533a146ea556523e433e6f042c5334 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 8 Mar 2016 15:37:48 +0000 Subject: [PATCH 13/57] Update fts3/4 so that the 'merge=X,Y' command merges at least, instead of exactly, Y segments from a single level. This matches the documentation. 'merge=X,0' is, as it was in 3.11, an error. FossilOrigin-Name: 64b3cb29159491cbfab7e01844b54408541ece5e --- ext/fts3/fts3_write.c | 9 +++------ manifest | 26 +++++++++++++------------- manifest.uuid | 2 +- test/backcompat.test | 10 ++++++++-- test/fts4growth.test | 40 ++++++++++++++++++++++------------------ test/fts4langid.test | 2 +- test/fts4merge.test | 25 ++++++++----------------- test/fts4merge3.test | 6 +++--- test/fts4opt.test | 4 ++-- 9 files changed, 61 insertions(+), 63 deletions(-) diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 6a2299fccf..24039aef30 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -4840,11 +4840,8 @@ int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){ sqlite3_bind_int(pFindLevel, 1, MAX(2, nMin)); if( sqlite3_step(pFindLevel)==SQLITE_ROW ){ iAbsLevel = sqlite3_column_int64(pFindLevel, 0); - if( nMin<2 ){ - nSeg = sqlite3_column_int(pFindLevel, 1); - }else{ - nSeg = nMin; - } + nSeg = sqlite3_column_int(pFindLevel, 1); + assert( nSeg>=2 ); }else{ nSeg = -1; } @@ -4996,7 +4993,7 @@ static int fts3DoIncrmerge( nMin = fts3Getint(&z); } - if( z[0]!='\0' || nMin<0 || nMin==1 ){ + if( z[0]!='\0' || nMin<2 ){ rc = SQLITE_ERROR; }else{ rc = SQLITE_OK; diff --git a/manifest b/manifest index cff32735ef..27e5d3a87d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sATTACH\sto\suse\sthe\ssymbolic\sname\sPAGER_SYNCHRONOUS_FULL\srather\sthan\nan\sinteger\sliteral. -D 2016-03-08T14:16:23.535 +C Update\sfts3/4\sso\sthat\sthe\s'merge=X,Y'\scommand\smerges\sat\sleast,\sinstead\sof\sexactly,\sY\ssegments\sfrom\sa\ssingle\slevel.\sThis\smatches\sthe\sdocumentation.\s'merge=X,0'\sis,\sas\sit\swas\sin\s3.11,\san\serror. +D 2016-03-08T15:37:48.202 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -88,7 +88,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 F ext/fts3/fts3_unicode2.c c3d01968d497bd7001e7dc774ba75b372738c057 -F ext/fts3/fts3_write.c f56345c64387ca30bf91b91511082fa83d9b5178 +F ext/fts3/fts3_write.c fb0456fa1407758f82458417c76fe4b06c86be98 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/fts3/tool/fts3view.c 5d78b668f4e9598af9147f8999632599fb0d9dd5 @@ -482,7 +482,7 @@ F test/autoindex5.test 96f084a5e6024ea07cace5888df3223f3ea86990 F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 -F test/backcompat.test 19a1f337c68419b020a7481dd272a472c4ad8ef4 +F test/backcompat.test 28403f43d11624e696c5ef134c7c7d81015cd19e F test/backup.test b79299a536a4c6d919094786595b95be56d02014 F test/backup2.test 34986ef926ea522911a51dfdb2f8e99b7b75ebcf F test/backup4.test 2a2e4a64388090b152de753fd9e123f28f6a3bd4 @@ -744,17 +744,17 @@ F test/fts4aa.test 10aac8e9d62c7357590acfabe3fad01e9a9ce1cb F test/fts4check.test c3056eab9524232e4c9bdcd119912947e07bcc1c F test/fts4content.test 05716af19a899cd70d5cd916c580043c03f30db4 F test/fts4docid.test e33c383cfbdff0284685604d256f347a18fdbf01 -F test/fts4growth.test 60d6bb3f78e25b34f533797dd9f2f9402310a13a +F test/fts4growth.test e5390da74619cacc389711bac9349640b32c4f9a F test/fts4growth2.test 13ad4e76451af6e6906c95cdc725d01b00044269 F test/fts4incr.test 4e353a0bd886ea984e56fce9e77724fc923b8d0d -F test/fts4langid.test 9794addcc8faaee85ac60eceecdb52feb0c70f68 -F test/fts4merge.test 146563df4a90ccb7f111a6e11ab29bbfe9e6ce2c +F test/fts4langid.test 65a7332c9bc257919e259a304aa8a38c41655b9d +F test/fts4merge.test d2b39f6b1bd4a9738a13540e2d044cba11c43d47 F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891 -F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7 +F test/fts4merge3.test 8d9ccb4a3d41c4c617a149d6c4b13ad02de797d0 F test/fts4merge4.test d895b1057a7798b67e03455d0fa50e9ea836c47b F test/fts4noti.test 5553d7bb2e20bf4a06b23e849352efc022ce6309 F test/fts4onepass.test 7319d61a2ed1325fc54afd0c060a0513b462303a -F test/fts4opt.test f15c84305c4b78c665fc476d8569e27ab9a0d418 +F test/fts4opt.test 1901f696214c4e16a995dd7fdd70576fc5c41dbe F test/fts4unicode.test 27378af76394542cf490cf001d8d1505fe55f6a9 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/func.test ae97561957aba6ca9e3a7b8a13aac41830d701ef @@ -1454,7 +1454,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3a65a1fc0fd2408c6984153801ec5dcd5211c897 -R 713ccf93fbf940d5f93658dc674d69a8 -U drh -Z 60af40306ae0297078d0f487c0fa1cd6 +P c4e192a0e5a408e198dbacb2752859a00d2b572f +R 3e8d6ecab7b420c32f9b7a175d510e4d +U dan +Z 45820e8758a67cfc47c6d8f8a214769a diff --git a/manifest.uuid b/manifest.uuid index 60ec4c1d29..5eb2c62ef9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c4e192a0e5a408e198dbacb2752859a00d2b572f \ No newline at end of file +64b3cb29159491cbfab7e01844b54408541ece5e \ No newline at end of file diff --git a/test/backcompat.test b/test/backcompat.test index ea7e6a9eed..fe8a83f0a6 100644 --- a/test/backcompat.test +++ b/test/backcompat.test @@ -63,7 +63,7 @@ proc do_backcompat_test {rv bin1 bin2 script} { set v [split [db version] .] if {[llength $v]==3} {lappend v 0} set ::sqlite_libversion [format \ - "%d%.2d%.2d%2d" [lindex $v 0] [lindex $v 1] [lindex $v 2] [lindex $v 3] + "%d%.2d%.2d%.2d" [lindex $v 0] [lindex $v 1] [lindex $v 2] [lindex $v 3] ] } } @@ -420,6 +420,12 @@ ifcapable fts3 { if {[code1 { set ::sqlite_libversion }] >=3071200 && [code2 { set ::sqlite_libversion }] >=3071200 } { + if {[code1 { set ::sqlite_libversion }]<3120000} { + set res {0 {0 1} 1 0} + } else { + set res {1 0} + } + do_test backcompat-3.9 { sql1 { INSERT INTO t2(t2) VALUES('merge=100,4'); } sql2 { INSERT INTO t2(t2) VALUES('merge=100,4'); } @@ -428,7 +434,7 @@ ifcapable fts3 { sql2 { SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level; } - } {0 {0 1} 1 0} + } $res do_test backcompat-3.10 { sql1 { INSERT INTO t2(t2) VALUES('integrity-check') } diff --git a/test/fts4growth.test b/test/fts4growth.test index e4b5f19ecb..4dc2212464 100644 --- a/test/fts4growth.test +++ b/test/fts4growth.test @@ -59,11 +59,11 @@ do_test 1.4 { INSERT INTO x1(x1) VALUES('merge=4,4'); SELECT level, end_block, length(root) FROM x1_segdir; } -} {0 {0 110} 110 0 {0 132} 132 0 {0 129} 129 1 {128 658} 2} +} {1 {224 921} 2} do_execsql_test 1.5 { SELECT length(block) FROM x1_segments; -} {658 {}} +} {921 {}} do_test 1.6 { foreach L { @@ -71,27 +71,33 @@ do_test 1.6 { {That perched above Dead Man's Creek, beside the mountain road.} {He turned the cycle down the hill and mounted for the fray,} {But 'ere he'd gone a dozen yards it bolted clean away.} + {It left the track, and through the trees, just like a silver steak,} {It whistled down the awful slope towards the Dead Man's Creek.} {It shaved a stump by half an inch, it dodged a big white-box:} {The very wallaroos in fright went scrambling up the rocks,} + {The wombats hiding in their caves dug deeper underground,} {As Mulga Bill, as white as chalk, sat tight to every bound.} {It struck a stone and gave a spring that cleared a fallen tree,} {It raced beside a precipice as close as close could be;} + {And then as Mulga Bill let out one last despairing shriek} {It made a leap of twenty feet into the Dead Man's Creek.} + {It shaved a stump by half an inch, it dodged a big white-box:} + {The very wallaroos in fright went scrambling up the rocks,} + {The wombats hiding in their caves dug deeper underground,} } { execsql { INSERT INTO x1 VALUES($L) } } execsql { SELECT level, end_block, length(root) FROM x1_segdir; } -} {1 {128 658} 2 1 {130 1377} 6 0 {0 117} 117} +} {1 {224 921} 2 1 {226 1230} 7 0 {0 98} 98} do_execsql_test 1.7 { - SELECT sum(length(block)) FROM x1_segments WHERE blockid IN (129, 130); -} {1377} + SELECT sum(length(block)) FROM x1_segments WHERE blockid IN (224,225,226) +} {1230} #------------------------------------------------------------------------- # @@ -131,24 +137,24 @@ do_execsql_test 2.5 { SELECT end_block FROM x2_segdir WHERE level=3; INSERT INTO x2(x2) VALUES('merge=4,4'); SELECT end_block FROM x2_segdir WHERE level=3; -} {{3828 -3430} {3828 -10191} {3828 -14109}} +} {{5588 -3950} {5588 -11766} {5588 -15541}} do_execsql_test 2.6 { SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE blockid BETWEEN start_block AND leaves_end_block AND level=3 -} {14109} +} {15541} do_execsql_test 2.7 { INSERT INTO x2(x2) VALUES('merge=1000,4'); SELECT end_block FROM x2_segdir WHERE level=3; -} {{3828 86120}} +} {{5588 127563}} do_execsql_test 2.8 { SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE blockid BETWEEN start_block AND leaves_end_block AND level=3 -} {86120} +} {127563} #-------------------------------------------------------------------------- # Test that delete markers are removed from FTS segments when possible. @@ -391,7 +397,7 @@ do_execsql_test 7.2 { } { 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} - 1 0 {16014 -51226} + 1 0 {23694 -69477} } do_execsql_test 7.3 { @@ -400,7 +406,7 @@ do_execsql_test 7.3 { } { 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} - 1 0 16014 + 1 0 23694 } do_execsql_test 7.4 { @@ -409,28 +415,26 @@ do_execsql_test 7.4 { } { 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} - 1 0 16014 + 1 0 23694 } do_execsql_test 7.5 { INSERT INTO x6(x6) VALUES('merge=2500,4'); - SELECT level, idx, end_block FROM x6_segdir; + SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir; } { - 0 0 {598 118006} 0 1 {718 118006} 1 0 16014 + 1 0 719 1171 23694 } do_execsql_test 7.6 { INSERT INTO x6(x6) VALUES('merge=2500,2'); SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir; } { - 2 0 23695 24147 {41262 633507} + 1 0 719 1171 23694 } do_execsql_test 7.7 { SELECT sum(length(block)) FROM x6_segments - WHERE blockid BETWEEN 23695 AND 24147 -} {633507} - +} {635247} finish_test diff --git a/test/fts4langid.test b/test/fts4langid.test index eb3602b4b8..fdb1876be8 100644 --- a/test/fts4langid.test +++ b/test/fts4langid.test @@ -481,6 +481,6 @@ foreach lid [list 4 [expr 1<<30]] { do_execsql_test 5.4.$lid.5 { SELECT count(*) FROM t6_segdir; SELECT count(*) FROM t6_segments; - } {4 4} + } {1 2} } finish_test diff --git a/test/fts4merge.test b/test/fts4merge.test index 41f91fdc8f..eac18311d3 100644 --- a/test/fts4merge.test +++ b/test/fts4merge.test @@ -55,8 +55,6 @@ foreach mod {fts3 fts4} { do_execsql_test 1.3 { SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level } { - 0 {0 1 2 3} - 1 {0 1 2 3 4 5 6} 2 {0 1 2 3} } @@ -71,7 +69,6 @@ foreach mod {fts3 fts4} { do_execsql_test 1.5 { SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level } { - 2 {0 1} 3 0 } @@ -118,11 +115,7 @@ foreach mod {fts3 fts4} { INSERT INTO t2(t2) VALUES('merge=1000000,2'); SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level } { - 0 0 - 2 0 - 3 0 4 0 - 6 0 } #------------------------------------------------------------------------- @@ -202,28 +195,27 @@ foreach mod {fts3 fts4} { INSERT INTO t1(t1) VALUES('merge=1,5'); SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; } { - 0 {0 1 2} 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} 2 {0 1 2 3} } - do_execsql_test 5.4 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'0105'} + do_execsql_test 5.4 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'010F'} do_test 5.5 { foreach docid [execsql {SELECT docid FROM t1}] { execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid} } } {} - do_execsql_test 5.6 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'0105'} + do_execsql_test 5.6 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'010F'} do_execsql_test 5.7 { SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; SELECT quote(value) from t1_stat WHERE rowid=1; } { - 0 {0 1 2 3 4 5 6 7 8 9 10} + 0 {0 1 2 3 4 5 6 7} 1 {0 1 2 3 4 5 6 7 8 9 10 11 12} - 2 {0 1 2 3 4 5 6 7} - X'0105' + 2 {0 1 2 3 4 5 6 7} + X'010F' } do_execsql_test 5.8 { @@ -232,9 +224,8 @@ foreach mod {fts3 fts4} { SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; SELECT quote(value) from t1_stat WHERE rowid=1; } { - 0 {0 1 2 3 4} 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} - 2 {0 1 2 3 4 5 6 7 8} X'0106' + 2 {0 1 2 3 4 5 6 7 8} X'010E' } do_test 5.8.1 { fts3_integrity_check t1 } ok @@ -252,7 +243,7 @@ foreach mod {fts3 fts4} { SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; SELECT quote(value) from t1_stat WHERE rowid=1; } { - 0 0 1 {0 1} 2 0 3 0 X'0106' + 0 {0 1 2 3 4 5 6 7 8 9 10 11} 1 0 2 0 3 0 X'010E' } do_execsql_test 5.11 { @@ -260,7 +251,7 @@ foreach mod {fts3 fts4} { SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; SELECT quote(value) from t1_stat WHERE rowid=1; } { - 0 0 1 {0 1} 2 0 3 0 X'' + 1 {0 1} 2 0 3 0 X'010E' } #------------------------------------------------------------------------- diff --git a/test/fts4merge3.test b/test/fts4merge3.test index 329b4d2cc4..08b68b97d9 100644 --- a/test/fts4merge3.test +++ b/test/fts4merge3.test @@ -62,7 +62,7 @@ do_all_bc_test { do_test 1.7 { sql2 { SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 - } } [list 0 1 2 18 3 5] + } } {2 15 3 5} # Using the old connection, insert many rows. do_test 1.8 { @@ -73,7 +73,7 @@ do_all_bc_test { do_test 1.9 { sql2 { SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 - } } [list 0 13 1 13 2 5 3 6] + } } [list 0 12 1 13 2 4 3 6] # Run a big incr-merge operation on the db. do_test 1.10 { sql1 { INSERT INTO t2(t2) VALUES('merge=2000,2') } } {} @@ -97,7 +97,7 @@ do_all_bc_test { do_test 1.15 { sql2 { SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 - } } {6 1} + } } {4 1} } } diff --git a/test/fts4opt.test b/test/fts4opt.test index 5638aff1b1..1933c57b1b 100644 --- a/test/fts4opt.test +++ b/test/fts4opt.test @@ -92,7 +92,7 @@ do_execsql_test 1.5 { do_test 1.6 { while 1 { set tc1 [db total_changes] - execsql { INSERT INTO t2(t2) VALUES('merge=5,0') } + execsql { INSERT INTO t2(t2) VALUES('merge=5,2') } set tc2 [db total_changes] if {($tc2 - $tc1) < 2} break } @@ -153,7 +153,7 @@ do_execsql_test 2.5 { do_test 2.6 { while 1 { set tc1 [db total_changes] - execsql { INSERT INTO t2(t2) VALUES('merge=5,0') } + execsql { INSERT INTO t2(t2) VALUES('merge=5,2') } set tc2 [db total_changes] if {($tc2 - $tc1) < 2} break } From 15d36c603d51a64aa161458a25183363fe0b1c72 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 16:02:37 +0000 Subject: [PATCH 14/57] Remove an unused goto label in the RBU extension. FossilOrigin-Name: 2179a106e8dd7943d4f37093e65ce7826720904e --- ext/rbu/sqlite3rbu.c | 2 -- manifest | 15 +++++++-------- manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 7f27399988..474e39fe8d 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -2677,8 +2677,6 @@ static int rbuStep(sqlite3rbu *p){ } } } - - step_out: return p->rc; } diff --git a/manifest b/manifest index 95a229990c..f93e9c0c2c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\snew\srow\stype\sto\sRBU\s(a\speer\sof\sinsert,\supdate\sand\sdelete)\s-\s"delete\sthen\sinsert". -D 2016-03-08T15:52:43.903 +C Remove\san\sunused\sgoto\slabel\sin\sthe\sRBU\sextension. +D 2016-03-08T16:02:37.304 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -242,7 +242,7 @@ F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89 F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06 F ext/rbu/rbufts.test 828cd689da825f0a7b7c53ffc1f6f7fdb6fa5bda F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48 -F ext/rbu/sqlite3rbu.c 0d901d773bf4c9e7d101daaf545263044e7e6615 +F ext/rbu/sqlite3rbu.c 5956f8bee63b5ab2b04e65c1801ea0f5920dac92 F ext/rbu/sqlite3rbu.h 0bdeb3be211aaba7d85445fa36f4701a25a3dbde F ext/rbu/test_rbu.c 4a4cdcef4ef9379fc2a21f008805c80b27bcf573 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -1455,8 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5a847a676e756bbe33436596d4279f339bfb247c 169311c85b30f625bdb6986c9cd11db70942d73b -R 43c0b748ba126143d737a43b13d0c445 -T +closed 169311c85b30f625bdb6986c9cd11db70942d73b -U dan -Z 99ed19537580c1e7328c1d8043178b0a +P 1d9468d2427d2c9b7240b364554ac85a0b62fa44 +R 45c0cb408cd3189b0d141b544c4ab247 +U drh +Z 224db619cbf5201e3fc07a0cf6e997b5 diff --git a/manifest.uuid b/manifest.uuid index e6281cbd82..ad37f3bd4b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d9468d2427d2c9b7240b364554ac85a0b62fa44 \ No newline at end of file +2179a106e8dd7943d4f37093e65ce7826720904e \ No newline at end of file From 33b104af0849a0d820b041c6200e1d93b37ae7ab Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 16:07:59 +0000 Subject: [PATCH 15/57] Drop support for SQLITE_EXTRA_DURABLE. The new SQLITE_DEFAULT_SYNCHRONOUS compile-time option is a more general replacement. FossilOrigin-Name: f6d3156ba9af1da517dd77c1df03fa7869888463 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pager.c | 17 ----------------- src/sqliteInt.h | 8 ++++++++ 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index f93e9c0c2c..40a77bc19a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunused\sgoto\slabel\sin\sthe\sRBU\sextension. -D 2016-03-08T16:02:37.304 +C Drop\ssupport\sfor\sSQLITE_EXTRA_DURABLE.\s\sThe\snew\sSQLITE_DEFAULT_SYNCHRONOUS\ncompile-time\soption\sis\sa\smore\sgeneral\sreplacement. +D 2016-03-08T16:07:59.373 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -336,7 +336,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c f5bac8e74aaefc4ea520e43b4540793c3b8a9e8f F src/os_win.c f0d7aa603eb6262143d7169a222aea07c4fca91d F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca -F src/pager.c 17aa37b3b53a62a1bd98fe6f3c758bb41429ef08 +F src/pager.c 2d950142528e5d9b291a1160443d7ade0d90700d F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56 F src/parse.y 5ea8c81c5c41b27887f41b4a7e1c58470d7d3821 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df @@ -354,7 +354,7 @@ F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 0235586b3fb639e85998d495c90f007657fd82af F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h b017fbf491606a0fd1a5d43af40dbe965a928ead +F src/sqliteInt.h 24e2eed36a68d48bd43d866adb528001b0795275 F src/sqliteLimit.h 7b28cf72cbd52f178bfc97ea266445e351f2cd24 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1d9468d2427d2c9b7240b364554ac85a0b62fa44 -R 45c0cb408cd3189b0d141b544c4ab247 +P 2179a106e8dd7943d4f37093e65ce7826720904e +R 82b2467863d1f8153e3f75a5d4f56472 U drh -Z 224db619cbf5201e3fc07a0cf6e997b5 +Z ded4eae64cbc81643a193c9cf7561702 diff --git a/manifest.uuid b/manifest.uuid index ad37f3bd4b..d7438755d1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2179a106e8dd7943d4f37093e65ce7826720904e \ No newline at end of file +f6d3156ba9af1da517dd77c1df03fa7869888463 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 6cc6ebff42..316a5e8ec0 100644 --- a/src/pager.c +++ b/src/pager.c @@ -428,19 +428,6 @@ int sqlite3PagerTrace=1; /* True to enable tracing */ */ #define MAX_SECTOR_SIZE 0x10000 -/* -** If the option SQLITE_EXTRA_DURABLE option is set at compile-time, then -** SQLite will do extra fsync() operations when synchronous==FULL to help -** ensure that transactions are durable across a power failure. Most -** applications are happy as long as transactions are consistent across -** a power failure, and are perfectly willing to lose the last transaction -** in exchange for the extra performance of avoiding directory syncs. -** And so the default SQLITE_EXTRA_DURABLE setting is off. -*/ -#ifndef SQLITE_EXTRA_DURABLE -# define SQLITE_EXTRA_DURABLE 0 -#endif - /* ** An instance of the following structure is allocated for each active @@ -4823,11 +4810,7 @@ act_like_temp_file: assert( pPager->ckptSyncFlags==0 ); }else{ pPager->fullSync = 1; -#if SQLITE_EXTRA_DURABLE - pPager->extraSync = 1; -#else pPager->extraSync = 0; -#endif pPager->syncFlags = SQLITE_SYNC_NORMAL; pPager->walSyncFlags = SQLITE_SYNC_NORMAL | WAL_SYNC_TRANSACTIONS; pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 741caec3e3..350832a2e7 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1005,6 +1005,14 @@ typedef struct With With; #include "os.h" #include "mutex.h" +/* The SQLITE_EXTRA_DURABLE compile-time option used to set the default +** synchronous setting to EXTRA. It is no longer supported. +*/ +#ifdef SQLITE_EXTRA_DURABLE +# warning Use SQLITE_DEFAULT_SYNCHRONOUS=3 instead of SQLITE_EXTRA_DURABLE +# define SQLITE_DEFAULT_SYNCHRONOUS 3 +#endif + /* ** Default synchronous levels. ** From 7ed4020890fbcc93dbf09a7ee75ab600355a9097 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 8 Mar 2016 17:44:08 +0000 Subject: [PATCH 16/57] Modify the memjournal.c code to make it a bit smaller. FossilOrigin-Name: d99ac4154812065eef26c298de52954d7ee0bd75 --- manifest | 16 +++++---- manifest.uuid | 2 +- src/memjournal.c | 93 ++++++++++++++++++++---------------------------- 3 files changed, 49 insertions(+), 62 deletions(-) diff --git a/manifest b/manifest index 95a229990c..40bd34b006 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\snew\srow\stype\sto\sRBU\s(a\speer\sof\sinsert,\supdate\sand\sdelete)\s-\s"delete\sthen\sinsert". -D 2016-03-08T15:52:43.903 +C Modify\sthe\smemjournal.c\scode\sto\smake\sit\sa\sbit\ssmaller. +D 2016-03-08T17:44:08.043 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -321,7 +321,7 @@ F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memjournal.c 011da5236a7250385cc74c253f14bbee04c0d61e +F src/memjournal.c 02deb8930ae8103fbe5640433a9d55c5dd2c13f1 F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495 F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 @@ -1455,8 +1455,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5a847a676e756bbe33436596d4279f339bfb247c 169311c85b30f625bdb6986c9cd11db70942d73b -R 43c0b748ba126143d737a43b13d0c445 -T +closed 169311c85b30f625bdb6986c9cd11db70942d73b +P 1d9468d2427d2c9b7240b364554ac85a0b62fa44 +R f53a6f3e4bc637f282a01c3504067543 +T *branch * memjournal-exp +T *sym-memjournal-exp * +T -sym-trunk * U dan -Z 99ed19537580c1e7328c1d8043178b0a +Z e2ab5ced3facb0c6a3be08b7e7370857 diff --git a/manifest.uuid b/manifest.uuid index e6281cbd82..c324dea819 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d9468d2427d2c9b7240b364554ac85a0b62fa44 \ No newline at end of file +d99ac4154812065eef26c298de52954d7ee0bd75 \ No newline at end of file diff --git a/src/memjournal.c b/src/memjournal.c index 04780df99c..2d6922ddeb 100644 --- a/src/memjournal.c +++ b/src/memjournal.c @@ -69,7 +69,6 @@ struct MemJournal { int flags; /* xOpen flags */ sqlite3_vfs *pVfs; /* The "real" underlying VFS */ const char *zJournal; /* Name of the journal file */ - sqlite3_file *pReal; /* The "real" underlying file descriptor */ }; /* @@ -83,9 +82,7 @@ static int memjrnlRead( sqlite_int64 iOfst /* Begin reading at this offset */ ){ MemJournal *p = (MemJournal *)pJfd; - if( p->pReal ){ - return sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst); - }else if( (iAmt+iOfst)>p->endpoint.iOffset ){ + if( (iAmt+iOfst)>p->endpoint.iOffset ){ return SQLITE_IOERR_SHORT_READ; }else{ u8 *zOut = zBuf; @@ -138,36 +135,37 @@ static void memjrnlFreeChunks(MemJournal *p){ ** Flush the contents of memory to a real file on disk. */ static int memjrnlCreateFile(MemJournal *p){ - int rc = SQLITE_OK; - if( !p->pReal ){ - sqlite3_file *pReal = (sqlite3_file *)&p[1]; - rc = sqlite3OsOpen(p->pVfs, p->zJournal, pReal, p->flags, 0); - if( rc==SQLITE_OK ){ - int nChunk = p->nChunkSize; - i64 iOff = 0; - FileChunk *pIter; - p->pReal = pReal; - for(pIter=p->pFirst; pIter && rc==SQLITE_OK; pIter=pIter->pNext){ - int nWrite = nChunk; - if( pIter==p->endpoint.pChunk ){ - nWrite = p->endpoint.iOffset % p->nChunkSize; - if( nWrite==0 ) nWrite = p->nChunkSize; - } - rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nWrite, iOff); - iOff += nWrite; - } - if( rc!=SQLITE_OK ){ - /* If an error occurred while writing to the file, close it before - ** returning. This way, SQLite uses the in-memory journal data to - ** roll back changes made to the internal page-cache before this - ** function was called. */ - sqlite3OsClose(pReal); - p->pReal = 0; - }else{ - /* No error has occurred. Free the in-memory buffers. */ - memjrnlFreeChunks(p); + int rc; + sqlite3_file *pReal = (sqlite3_file*)p; + MemJournal copy = *p; + + memset(p, 0, sizeof(MemJournal)); + rc = sqlite3OsOpen(copy.pVfs, copy.zJournal, pReal, copy.flags, 0); + if( rc==SQLITE_OK ){ + int nChunk = copy.nChunkSize; + i64 iOff = 0; + FileChunk *pIter; + for(pIter=copy.pFirst; pIter && rc==SQLITE_OK; pIter=pIter->pNext){ + int nWrite = nChunk; + if( pIter==copy.endpoint.pChunk ){ + nWrite = copy.endpoint.iOffset % copy.nChunkSize; + if( nWrite==0 ) nWrite = copy.nChunkSize; } + rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nWrite, iOff); + iOff += nWrite; } + if( rc==SQLITE_OK ){ + /* No error has occurred. Free the in-memory buffers. */ + memjrnlFreeChunks(©); + } + } + if( rc!=SQLITE_OK ){ + /* If an error occurred while creating or writing to the file, restore + ** the original before returning. This way, SQLite uses the in-memory + ** journal data to roll back changes made to the internal page-cache + ** before this function was called. */ + sqlite3OsClose(pReal); + *p = copy; } return rc; } @@ -186,16 +184,12 @@ static int memjrnlWrite( int nWrite = iAmt; u8 *zWrite = (u8 *)zBuf; - /* If the file has already been created on disk. */ - if( p->pReal ){ - return sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst); - } - - /* If the file should be created now. */ - else if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){ + /* If the file should be created now, create it and write the new data + ** into the file on disk. */ + if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){ int rc = memjrnlCreateFile(p); if( rc==SQLITE_OK ){ - rc = memjrnlWrite(pJfd, zBuf, iAmt, iOfst); + rc = sqlite3OsWrite(pJfd, zBuf, iAmt, iOfst); } return rc; } @@ -255,9 +249,7 @@ static int memjrnlWrite( */ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ MemJournal *p = (MemJournal *)pJfd; - if( p->pReal ){ - return sqlite3OsTruncate(p->pReal, size); - }else if( size==0 ){ + if( size==0 ){ memjrnlFreeChunks(p); p->nSize = 0; p->endpoint.pChunk = 0; @@ -274,7 +266,6 @@ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ static int memjrnlClose(sqlite3_file *pJfd){ MemJournal *p = (MemJournal *)pJfd; memjrnlFreeChunks(p); - if( p->pReal ) sqlite3OsClose(p->pReal); return SQLITE_OK; } @@ -285,10 +276,7 @@ static int memjrnlClose(sqlite3_file *pJfd){ ** syncing an in-memory journal is a no-op. */ static int memjrnlSync(sqlite3_file *pJfd, int flags){ - MemJournal *p = (MemJournal *)pJfd; - if( p->pReal ){ - return sqlite3OsSync(p->pReal, flags); - } + UNUSED_PARAMETER2(pJfd, flags); return SQLITE_OK; } @@ -297,9 +285,6 @@ static int memjrnlSync(sqlite3_file *pJfd, int flags){ */ static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){ MemJournal *p = (MemJournal *)pJfd; - if( p->pReal ){ - return sqlite3OsFileSize(p->pReal, pSize); - } *pSize = (sqlite_int64) p->endpoint.iOffset; return SQLITE_OK; } @@ -354,7 +339,7 @@ int sqlite3JournalOpen( ** it using the sqlite3OsOpen() function of the underlying VFS. In this ** case none of the code in this module is executed as a result of calls ** made on the journal file-handle. */ - memset(p, 0, sizeof(MemJournal) + (pVfs ? pVfs->szOsFile : 0)); + memset(p, 0, sizeof(MemJournal)); if( nSpill==0 ){ return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0); } @@ -403,7 +388,7 @@ int sqlite3JournalCreate(sqlite3_file *p){ ** or false otherwise. */ int sqlite3JournalIsInMemory(sqlite3_file *p){ - return p->pMethods==&MemJournalMethods && ((MemJournal*)p)->pReal==0; + return p->pMethods==&MemJournalMethods; } /* @@ -411,5 +396,5 @@ int sqlite3JournalIsInMemory(sqlite3_file *p){ ** pVfs to create the underlying on-disk files. */ int sqlite3JournalSize(sqlite3_vfs *pVfs){ - return pVfs->szOsFile + sizeof(MemJournal); + return MAX(pVfs->szOsFile, sizeof(MemJournal)); } From 3349d9bea956eaf1a2d9554ce3e4c9e1d5b34075 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 23:18:51 +0000 Subject: [PATCH 17/57] Improved comments on virtual table query planning. Added many new WHERETRACE() macros. FossilOrigin-Name: 4c89c2534abcf67bc486d5a900a84a6c4f59537e --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/where.c | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index bb6f77ee42..25c4175d4a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\smemjournal.c,\sreuse\sthe\ssame\ssqlite3_file\sobject\sfor\sboth\sthe\sin-memory\nphase\sand\sthe\son-disk\sphase. -D 2016-03-08T17:59:19.784 +C Improved\scomments\son\svirtual\stable\squery\splanning.\s\sAdded\smany\snew\nWHERETRACE()\smacros. +D 2016-03-08T23:18:51.182 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -429,7 +429,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c dff52f7f0842430f80a7017c7859124685b08453 +F src/where.c a3f6db088f335a9217fe53d976f9441610061a2f F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1455,8 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f6d3156ba9af1da517dd77c1df03fa7869888463 d99ac4154812065eef26c298de52954d7ee0bd75 -R bec56382cb26d93b90f8b590f852c457 -T +closed d99ac4154812065eef26c298de52954d7ee0bd75 +P e7fbbdc25c0991d4e58d78a5fcb7386e1aa7f3af +R 624279792742522c1a4793f09c7ca2f6 U drh -Z 55dc3dcac976fd228dc3d62385f9ab1a +Z ab3adc4bc8a1b11824c36206a5455ed4 diff --git a/manifest.uuid b/manifest.uuid index 45d67c3642..572a4db2fb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e7fbbdc25c0991d4e58d78a5fcb7386e1aa7f3af \ No newline at end of file +4c89c2534abcf67bc486d5a900a84a6c4f59537e \ No newline at end of file diff --git a/src/where.c b/src/where.c index 2d7272a742..364bfca3c5 100644 --- a/src/where.c +++ b/src/where.c @@ -2892,6 +2892,9 @@ static int whereLoopAddVirtualOne( sqlite3_free(pNew->u.vtab.idxStr); pNew->u.vtab.needFree = 0; } + WHERETRACE(0xffff, (" bIn=%d prereqIn=%04llx prereqOut=%04llx\n", + *pbIn, (sqlite3_uint64)mPrereq, + (sqlite3_uint64)(pNew->prereq & ~mPrereq))); return SQLITE_OK; } @@ -2958,15 +2961,15 @@ static int whereLoopAddVirtual( } /* First call xBestIndex() with all constraints usable. */ + WHERETRACE(0x40, (" VirtualOne: all usable\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, &bIn); - mBest = pNew->prereq & ~mPrereq; /* If the call to xBestIndex() with all terms enabled produced a plan - ** that does not require any source tables, there is no point in making - ** any further calls - if the xBestIndex() method is sane they will all - ** return the same plan anyway. - */ - if( mBest ){ + ** that does not require any source tables (IOW: a plan with mBest==0), + ** then there is no point in making any further calls to xBestIndex() + ** since they will all return the same result (if the xBestIndex() + ** implementation is sane). */ + if( rc==SQLITE_OK && (mBest = (pNew->prereq & ~mPrereq))!=0 ){ int seenZero = 0; /* True if a plan with no prereqs seen */ int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */ Bitmask mPrev = 0; @@ -2974,7 +2977,8 @@ static int whereLoopAddVirtual( /* If the plan produced by the earlier call uses an IN(...) term, call ** xBestIndex again, this time with IN(...) terms disabled. */ - if( rc==SQLITE_OK && bIn ){ + if( bIn ){ + WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, WO_IN, p, &bIn); assert( bIn==0 ); mBestNoIn = pNew->prereq & ~mPrereq; @@ -2999,6 +3003,8 @@ static int whereLoopAddVirtual( mPrev = mNext; if( mNext==ALLBITS ) break; if( mNext==mBest || mNext==mBestNoIn ) continue; + WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n", + (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext)); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mNext|mPrereq, 0, p, &bIn); if( pNew->prereq==mPrereq ){ seenZero = 1; @@ -3010,6 +3016,7 @@ static int whereLoopAddVirtual( ** that requires no source tables at all (i.e. one guaranteed to be ** usable), make a call here with all source tables disabled */ if( rc==SQLITE_OK && seenZero==0 ){ + WHERETRACE(0x40, (" VirtualOne: all disabled\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mPrereq, 0, p, &bIn); if( bIn==0 ) seenZeroNoIN = 1; } @@ -3018,6 +3025,7 @@ static int whereLoopAddVirtual( ** that requires no source tables at all and does not use an IN(...) ** operator, make a final call to obtain one here. */ if( rc==SQLITE_OK && seenZeroNoIN==0 ){ + WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mPrereq, WO_IN, p, &bIn); } } From d1cca3b721485738e96e3cc34bc8fef862016101 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Mar 2016 23:44:48 +0000 Subject: [PATCH 18/57] Change an unreachable branch in the virtual table query planner into an assert(). FossilOrigin-Name: 73b97b9ec3c39ab2828ae6353b5d7e04a27996c9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 25c4175d4a..7dcb18c721 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scomments\son\svirtual\stable\squery\splanning.\s\sAdded\smany\snew\nWHERETRACE()\smacros. -D 2016-03-08T23:18:51.182 +C Change\san\sunreachable\sbranch\sin\sthe\svirtual\stable\squery\splanner\sinto\nan\sassert(). +D 2016-03-08T23:44:48.075 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -429,7 +429,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c a3f6db088f335a9217fe53d976f9441610061a2f +F src/where.c f2859a4f9e3ce0585fd75648fb5cae9f985c458d F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e7fbbdc25c0991d4e58d78a5fcb7386e1aa7f3af -R 624279792742522c1a4793f09c7ca2f6 +P 4c89c2534abcf67bc486d5a900a84a6c4f59537e +R ba189513b00cd0d7f1cb51ba2837236b U drh -Z ab3adc4bc8a1b11824c36206a5455ed4 +Z b92bcbc09edaf6b80c374c7506559755 diff --git a/manifest.uuid b/manifest.uuid index 572a4db2fb..b773d03caf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c89c2534abcf67bc486d5a900a84a6c4f59537e \ No newline at end of file +73b97b9ec3c39ab2828ae6353b5d7e04a27996c9 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 364bfca3c5..927469f0d5 100644 --- a/src/where.c +++ b/src/where.c @@ -2810,10 +2810,9 @@ static int whereLoopAddVirtualOne( /* Initialize the output fields of the sqlite3_index_info structure */ memset(pUsage, 0, sizeof(pUsage[0])*nConstraint); - if( pIdxInfo->needToFreeIdxStr ) sqlite3_free(pIdxInfo->idxStr); + assert( pIdxInfo->needToFreeIdxStr==0 ); pIdxInfo->idxStr = 0; pIdxInfo->idxNum = 0; - pIdxInfo->needToFreeIdxStr = 0; pIdxInfo->orderByConsumed = 0; pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2; pIdxInfo->estimatedRows = 25; From 273021d71a892d8155ad17354e52ce3b743b8c3a Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 02:03:03 +0000 Subject: [PATCH 19/57] Add an #ifdef and an ALWAYS() for coverage. FossilOrigin-Name: 069337a922867ad0d023f5bf36e13ea46e047000 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/memjournal.c | 9 +++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 7dcb18c721..7b1d29dc01 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\san\sunreachable\sbranch\sin\sthe\svirtual\stable\squery\splanner\sinto\nan\sassert(). -D 2016-03-08T23:44:48.075 +C Add\san\s#ifdef\sand\san\sALWAYS()\sfor\scoverage. +D 2016-03-09T02:03:03.758 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -321,7 +321,7 @@ F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memjournal.c 02deb8930ae8103fbe5640433a9d55c5dd2c13f1 +F src/memjournal.c 9704b40cd63d53f584ac06c0cd1b52d399bb63ec F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495 F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4c89c2534abcf67bc486d5a900a84a6c4f59537e -R ba189513b00cd0d7f1cb51ba2837236b +P 73b97b9ec3c39ab2828ae6353b5d7e04a27996c9 +R ff350e249f52320a06e1a0030d694c10 U drh -Z b92bcbc09edaf6b80c374c7506559755 +Z 4b008537bb55e8cdb449348ac3153700 diff --git a/manifest.uuid b/manifest.uuid index b773d03caf..1716d33ca2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -73b97b9ec3c39ab2828ae6353b5d7e04a27996c9 \ No newline at end of file +069337a922867ad0d023f5bf36e13ea46e047000 \ No newline at end of file diff --git a/src/memjournal.c b/src/memjournal.c index 2d6922ddeb..706703ed80 100644 --- a/src/memjournal.c +++ b/src/memjournal.c @@ -202,10 +202,15 @@ static int memjrnlWrite( ** atomic-write optimization. In this case the first 28 bytes of the ** journal file may be written as part of committing the transaction. */ assert( iOfst==p->endpoint.iOffset || iOfst==0 ); +#ifdef SQLITE_ENABLE_ATOMIC_WRITE if( iOfst==0 && p->pFirst ){ assert( p->nChunkSize>iAmt ); memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt); - }else{ + }else +#else + assert( iOfst>0 || p->pFirst==0 ); +#endif + { while( nWrite>0 ){ FileChunk *pChunk = p->endpoint.pChunk; int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize); @@ -249,7 +254,7 @@ static int memjrnlWrite( */ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){ MemJournal *p = (MemJournal *)pJfd; - if( size==0 ){ + if( ALWAYS(size==0) ){ memjrnlFreeChunks(p); p->nSize = 0; p->endpoint.pChunk = 0; From 2f1e02e8a7f263b4af5322cab874a4bc68c54080 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 02:12:44 +0000 Subject: [PATCH 20/57] Change a branch made obsolete by recent parser enhancements into an assert(). FossilOrigin-Name: ee486ef742557244f532e8d3b3604ff04e024b8a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/build.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 7b1d29dc01..e6d9d8a391 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\s#ifdef\sand\san\sALWAYS()\sfor\scoverage. -D 2016-03-09T02:03:03.758 +C Change\sa\sbranch\smade\sobsolete\sby\srecent\sparser\senhancements\sinto\san\sassert(). +D 2016-03-09T02:12:44.430 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -296,7 +296,7 @@ F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 F src/btree.c 2712f087351f5c4ff0e71631b1e67b461611b99d F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 -F src/build.c 43b93fe757bfffe00f97462596418b052eefdccd +F src/build.c 213cbf84e99dd834e6ea46615633656d7ef79321 F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 73b97b9ec3c39ab2828ae6353b5d7e04a27996c9 -R ff350e249f52320a06e1a0030d694c10 +P 069337a922867ad0d023f5bf36e13ea46e047000 +R 3e57a4be2efca34c86d71580042aa5c5 U drh -Z 4b008537bb55e8cdb449348ac3153700 +Z 969405448d01de3e3b82aafcc7d6fe5a diff --git a/manifest.uuid b/manifest.uuid index 1716d33ca2..fb4b683b73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -069337a922867ad0d023f5bf36e13ea46e047000 \ No newline at end of file +ee486ef742557244f532e8d3b3604ff04e024b8a \ No newline at end of file diff --git a/src/build.c b/src/build.c index a32dfbd029..e89c744461 100644 --- a/src/build.c +++ b/src/build.c @@ -1135,7 +1135,7 @@ char sqlite3AffinityType(const char *zIn, u8 *pszEst){ char aff = SQLITE_AFF_NUMERIC; const char *zChar = 0; - if( zIn==0 ) return aff; + assert( zIn!=0 ); while( zIn[0] ){ h = (h<<8) + sqlite3UpperToLower[(*zIn)&0xff]; zIn++; From c1fb2b87bd2bf58959dec99cc34441437cf2a799 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 03:29:27 +0000 Subject: [PATCH 21/57] Update a comment in btree.c to account for WITHOUT ROWID tables. No code changes. FossilOrigin-Name: fa20dcb03b92be3bb32f8e3d6f88681ace3f6c84 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index e6d9d8a391..0c5b9408ab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sa\sbranch\smade\sobsolete\sby\srecent\sparser\senhancements\sinto\san\sassert(). -D 2016-03-09T02:12:44.430 +C Update\sa\scomment\sin\sbtree.c\sto\saccount\sfor\sWITHOUT\sROWID\stables.\s\sNo\scode\nchanges. +D 2016-03-09T03:29:27.407 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -293,7 +293,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63 F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c 2712f087351f5c4ff0e71631b1e67b461611b99d +F src/btree.c 6eee126fe9d1f57118de9be2be840a4c6e691828 F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c 213cbf84e99dd834e6ea46615633656d7ef79321 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 069337a922867ad0d023f5bf36e13ea46e047000 -R 3e57a4be2efca34c86d71580042aa5c5 +P ee486ef742557244f532e8d3b3604ff04e024b8a +R 58c822ca96b5496f25a8c479ed6f41b8 U drh -Z 969405448d01de3e3b82aafcc7d6fe5a +Z 14a12081690d2b5a8e4723ef05aa614c diff --git a/manifest.uuid b/manifest.uuid index fb4b683b73..758bea7f1a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ee486ef742557244f532e8d3b3604ff04e024b8a \ No newline at end of file +fa20dcb03b92be3bb32f8e3d6f88681ace3f6c84 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4b9bba55ac..18e6be9f38 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7572,9 +7572,9 @@ static int balance_nonroot( ** any cell). But it is important to pass the correct size to ** insertCell(), so reparse the cell now. ** - ** Note that this can never happen in an SQLite data file, as all - ** cells are at least 4 bytes. It only happens in b-trees used - ** to evaluate "IN (SELECT ...)" and similar clauses. + ** This can only happen for b-trees used to evaluate "IN (SELECT ...)" + ** and WITHOUT ROWID tables with exactly one column which is the + ** primary key. */ if( b.szCell[j]==4 ){ assert(leafCorrection==4); From 769b4c95ca98318bf5ff2152f09148a9694e9ed7 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 03:44:32 +0000 Subject: [PATCH 22/57] Move the write failure test in memjrnlCreateFile() to just after the actual write, thus reducing the number of instances of the test by one. FossilOrigin-Name: 7f00d80c63b15376391f661d872f2b29a970702d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/memjournal.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 0c5b9408ab..cc0b431865 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sa\scomment\sin\sbtree.c\sto\saccount\sfor\sWITHOUT\sROWID\stables.\s\sNo\scode\nchanges. -D 2016-03-09T03:29:27.407 +C Move\sthe\swrite\sfailure\stest\sin\smemjrnlCreateFile()\sto\sjust\safter\sthe\nactual\swrite,\sthus\sreducing\sthe\snumber\sof\sinstances\sof\sthe\stest\sby\sone. +D 2016-03-09T03:44:32.424 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -321,7 +321,7 @@ F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memjournal.c 9704b40cd63d53f584ac06c0cd1b52d399bb63ec +F src/memjournal.c 13ae08696117438e7fa2518af71e52ee00c02395 F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495 F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ee486ef742557244f532e8d3b3604ff04e024b8a -R 58c822ca96b5496f25a8c479ed6f41b8 +P fa20dcb03b92be3bb32f8e3d6f88681ace3f6c84 +R ddfc9f5547c4cd989efbf516628daef2 U drh -Z 14a12081690d2b5a8e4723ef05aa614c +Z f80415911853dbc4f72e4c714eb20705 diff --git a/manifest.uuid b/manifest.uuid index 758bea7f1a..ad041f10c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa20dcb03b92be3bb32f8e3d6f88681ace3f6c84 \ No newline at end of file +7f00d80c63b15376391f661d872f2b29a970702d \ No newline at end of file diff --git a/src/memjournal.c b/src/memjournal.c index 706703ed80..ed1d6bba8c 100644 --- a/src/memjournal.c +++ b/src/memjournal.c @@ -145,13 +145,14 @@ static int memjrnlCreateFile(MemJournal *p){ int nChunk = copy.nChunkSize; i64 iOff = 0; FileChunk *pIter; - for(pIter=copy.pFirst; pIter && rc==SQLITE_OK; pIter=pIter->pNext){ + for(pIter=copy.pFirst; pIter; pIter=pIter->pNext){ int nWrite = nChunk; if( pIter==copy.endpoint.pChunk ){ nWrite = copy.endpoint.iOffset % copy.nChunkSize; if( nWrite==0 ) nWrite = copy.nChunkSize; } rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nWrite, iOff); + if( rc ) break; iOff += nWrite; } if( rc==SQLITE_OK ){ From d93b2b840d916442bd0b3655788a4571e7adba5f Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 04:17:17 +0000 Subject: [PATCH 23/57] Simplifications to the memjournal.c logic to facilitate testing. FossilOrigin-Name: 8baa2c2c7698e03418531482a8314a5d7ae2c7d3 --- manifest | 12 ++++---- manifest.uuid | 2 +- src/memjournal.c | 71 ++++++++++++++++++++++++------------------------ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index cc0b431865..463e7f81dd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sthe\swrite\sfailure\stest\sin\smemjrnlCreateFile()\sto\sjust\safter\sthe\nactual\swrite,\sthus\sreducing\sthe\snumber\sof\sinstances\sof\sthe\stest\sby\sone. -D 2016-03-09T03:44:32.424 +C Simplifications\sto\sthe\smemjournal.c\slogic\sto\sfacilitate\stesting. +D 2016-03-09T04:17:17.100 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -321,7 +321,7 @@ F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memjournal.c 13ae08696117438e7fa2518af71e52ee00c02395 +F src/memjournal.c 6423a0817ffd8c7a04ef9e5fb974b6b9dd71f8b6 F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495 F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fa20dcb03b92be3bb32f8e3d6f88681ace3f6c84 -R ddfc9f5547c4cd989efbf516628daef2 +P 7f00d80c63b15376391f661d872f2b29a970702d +R 3dfe324883f59e455687da1f2d0dc6fa U drh -Z f80415911853dbc4f72e4c714eb20705 +Z 09a89868e4ca6983fd083bec8c9845f2 diff --git a/manifest.uuid b/manifest.uuid index ad041f10c3..2a3c3e97a0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7f00d80c63b15376391f661d872f2b29a970702d \ No newline at end of file +8baa2c2c7698e03418531482a8314a5d7ae2c7d3 \ No newline at end of file diff --git a/src/memjournal.c b/src/memjournal.c index ed1d6bba8c..b81682de85 100644 --- a/src/memjournal.c +++ b/src/memjournal.c @@ -82,38 +82,41 @@ static int memjrnlRead( sqlite_int64 iOfst /* Begin reading at this offset */ ){ MemJournal *p = (MemJournal *)pJfd; + u8 *zOut = zBuf; + int nRead = iAmt; + int iChunkOffset; + FileChunk *pChunk; + +#ifdef SQLITE_ENABLE_ATOMIC_WRITE if( (iAmt+iOfst)>p->endpoint.iOffset ){ return SQLITE_IOERR_SHORT_READ; - }else{ - u8 *zOut = zBuf; - int nRead = iAmt; - int iChunkOffset; - FileChunk *pChunk; - - if( p->readpoint.iOffset!=iOfst || iOfst==0 ){ - sqlite3_int64 iOff = 0; - for(pChunk=p->pFirst; - ALWAYS(pChunk) && (iOff+p->nChunkSize)<=iOfst; - pChunk=pChunk->pNext - ){ - iOff += p->nChunkSize; - } - }else{ - pChunk = p->readpoint.pChunk; - } - - iChunkOffset = (int)(iOfst%p->nChunkSize); - do { - int iSpace = p->nChunkSize - iChunkOffset; - int nCopy = MIN(nRead, (p->nChunkSize - iChunkOffset)); - memcpy(zOut, (u8*)pChunk->zChunk + iChunkOffset, nCopy); - zOut += nCopy; - nRead -= iSpace; - iChunkOffset = 0; - } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 ); - p->readpoint.iOffset = iOfst+iAmt; - p->readpoint.pChunk = pChunk; } +#endif + + assert( (iAmt+iOfst)<=p->endpoint.iOffset ); + if( p->readpoint.iOffset!=iOfst || iOfst==0 ){ + sqlite3_int64 iOff = 0; + for(pChunk=p->pFirst; + ALWAYS(pChunk) && (iOff+p->nChunkSize)<=iOfst; + pChunk=pChunk->pNext + ){ + iOff += p->nChunkSize; + } + }else{ + pChunk = p->readpoint.pChunk; + } + + iChunkOffset = (int)(iOfst%p->nChunkSize); + do { + int iSpace = p->nChunkSize - iChunkOffset; + int nCopy = MIN(nRead, (p->nChunkSize - iChunkOffset)); + memcpy(zOut, (u8*)pChunk->zChunk + iChunkOffset, nCopy); + zOut += nCopy; + nRead -= iSpace; + iChunkOffset = 0; + } while( nRead>=0 && (pChunk=pChunk->pNext)!=0 && nRead>0 ); + p->readpoint.iOffset = iOfst+iAmt; + p->readpoint.pChunk = pChunk; return SQLITE_OK; } @@ -146,14 +149,12 @@ static int memjrnlCreateFile(MemJournal *p){ i64 iOff = 0; FileChunk *pIter; for(pIter=copy.pFirst; pIter; pIter=pIter->pNext){ - int nWrite = nChunk; - if( pIter==copy.endpoint.pChunk ){ - nWrite = copy.endpoint.iOffset % copy.nChunkSize; - if( nWrite==0 ) nWrite = copy.nChunkSize; + if( iOff + nChunk > copy.endpoint.iOffset ){ + nChunk = copy.endpoint.iOffset - iOff; } - rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nWrite, iOff); + rc = sqlite3OsWrite(pReal, (u8*)pIter->zChunk, nChunk, iOff); if( rc ) break; - iOff += nWrite; + iOff += nChunk; } if( rc==SQLITE_OK ){ /* No error has occurred. Free the in-memory buffers. */ From c5644346b698a37763942e55fb41d310d0d45461 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 11:59:16 +0000 Subject: [PATCH 24/57] Disable the bestindex*.test modules when building without virtual table support. FossilOrigin-Name: e0bac2f3eed900d3a26de339fb7d5963f9b47724 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/bestindex1.test | 7 +++++-- test/bestindex2.test | 5 ++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 463e7f81dd..1db0431740 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\smemjournal.c\slogic\sto\sfacilitate\stesting. -D 2016-03-09T04:17:17.100 +C Disable\sthe\sbestindex*.test\smodules\swhen\sbuilding\swithout\svirtual\stable\ssupport. +D 2016-03-09T11:59:16.171 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -493,8 +493,8 @@ F test/backup_malloc.test 7162d604ec2b4683c4b3799a48657fb8b5e2d450 F test/badutf.test d5360fc31f643d37a973ab0d8b4fb85799c3169f F test/badutf2.test f5bc7f2d280670ecd79b9cf4f0f1760c607fe51f F test/bc_common.tcl 3eda41ef9cda7d5f6c205462c96228b301da4191 -F test/bestindex1.test e228fe1e3794dbe20271481164e000d695abcd24 -F test/bestindex2.test 10f2c6791f1cd0de414012528cd10a114648fd8f +F test/bestindex1.test d5ba89a7941a941476d8d69be39b146aaed3614c +F test/bestindex2.test 4a06b8922ab2fd09434870da8d1cdf525aaf7060 F test/between.test 34d375fb5ce1ae283ffe82b6b233e9f38e84fc6c F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7f00d80c63b15376391f661d872f2b29a970702d -R 3dfe324883f59e455687da1f2d0dc6fa +P 8baa2c2c7698e03418531482a8314a5d7ae2c7d3 +R edb83c934a274796cafb7c4f60da05c5 U drh -Z 09a89868e4ca6983fd083bec8c9845f2 +Z 1fd2317c8384669beba01778fd436686 diff --git a/manifest.uuid b/manifest.uuid index 2a3c3e97a0..aeb04d38bc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8baa2c2c7698e03418531482a8314a5d7ae2c7d3 \ No newline at end of file +e0bac2f3eed900d3a26de339fb7d5963f9b47724 \ No newline at end of file diff --git a/test/bestindex1.test b/test/bestindex1.test index fffb7aebea..97ae4b0f81 100644 --- a/test/bestindex1.test +++ b/test/bestindex1.test @@ -15,6 +15,11 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix bestindex1 +ifcapable !vtab { + finish_test + return +} + register_tcl_module db proc vtab_command {method args} { @@ -161,5 +166,3 @@ foreach {tn mode} { } finish_test - - diff --git a/test/bestindex2.test b/test/bestindex2.test index 7ccd61640d..8bc3fbc323 100644 --- a/test/bestindex2.test +++ b/test/bestindex2.test @@ -13,6 +13,10 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix bestindex2 +ifcapable !vtab { + finish_test + return +} #------------------------------------------------------------------------- # Virtual table callback for table named $tbl, with the columns specified @@ -135,4 +139,3 @@ do_eqp_test 1.7.2 { } finish_test - From bacbbccd16aefaeb51c30f6a3b8d0c8ba20b07b1 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 12:35:18 +0000 Subject: [PATCH 25/57] In the query planner, make sure OOM errors are reported up into whereLoopAddVirtual() so that it shuts down appropriately. FossilOrigin-Name: a13c59d08bcbc6f26ce6ac761a892eff8f035201 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 1db0431740..729dbda1a4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\sbestindex*.test\smodules\swhen\sbuilding\swithout\svirtual\stable\ssupport. -D 2016-03-09T11:59:16.171 +C In\sthe\squery\splanner,\smake\ssure\sOOM\serrors\sare\sreported\sup\sinto\nwhereLoopAddVirtual()\sso\sthat\sit\sshuts\sdown\sappropriately. +D 2016-03-09T12:35:18.466 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -429,7 +429,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c f2859a4f9e3ce0585fd75648fb5cae9f985c458d +F src/where.c 5533002ddf4fbc256f450cb629668a200b06a3ce F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8baa2c2c7698e03418531482a8314a5d7ae2c7d3 -R edb83c934a274796cafb7c4f60da05c5 +P e0bac2f3eed900d3a26de339fb7d5963f9b47724 +R ef93df8fd296bfa582e1a9a9087c3fc6 U drh -Z 1fd2317c8384669beba01778fd436686 +Z 498b8899efc263dd56cd46e3ec14e230 diff --git a/manifest.uuid b/manifest.uuid index aeb04d38bc..809eeb8fca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e0bac2f3eed900d3a26de339fb7d5963f9b47724 \ No newline at end of file +a13c59d08bcbc6f26ce6ac761a892eff8f035201 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 927469f0d5..83d72ee397 100644 --- a/src/where.c +++ b/src/where.c @@ -1979,6 +1979,7 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ WhereLoop **ppPrev, *p; WhereInfo *pWInfo = pBuilder->pWInfo; sqlite3 *db = pWInfo->pParse->db; + int rc; /* If pBuilder->pOrSet is defined, then only keep track of the costs ** and prereqs. @@ -2061,14 +2062,14 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ whereLoopDelete(db, pToDel); } } - whereLoopXfer(db, p, pTemplate); + rc = whereLoopXfer(db, p, pTemplate); if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){ Index *pIndex = p->u.btree.pIndex; if( pIndex && pIndex->tnum==0 ){ p->u.btree.pIndex = 0; } } - return SQLITE_OK; + return rc; } /* @@ -2886,7 +2887,7 @@ static int whereLoopAddVirtualOne( }else{ pNew->wsFlags &= ~WHERE_ONEROW; } - whereLoopInsert(pBuilder, pNew); + rc = whereLoopInsert(pBuilder, pNew); if( pNew->u.vtab.needFree ){ sqlite3_free(pNew->u.vtab.idxStr); pNew->u.vtab.needFree = 0; @@ -2895,7 +2896,7 @@ static int whereLoopAddVirtualOne( *pbIn, (sqlite3_uint64)mPrereq, (sqlite3_uint64)(pNew->prereq & ~mPrereq))); - return SQLITE_OK; + return rc; } From 7c621fb967b21c1f780a43b5e20118c9d0122b17 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 13:39:43 +0000 Subject: [PATCH 26/57] Automatically disable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_OMIT_EXPLAIN is defined. FossilOrigin-Name: 8d4b6b2b519a80f831d64345ac26db825b0e2ebe --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqliteInt.h | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 729dbda1a4..32aef606c9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\squery\splanner,\smake\ssure\sOOM\serrors\sare\sreported\sup\sinto\nwhereLoopAddVirtual()\sso\sthat\sit\sshuts\sdown\sappropriately. -D 2016-03-09T12:35:18.466 +C Automatically\sdisable\sSQLITE_ENABLE_EXPLAIN_COMMENTS\sif\sSQLITE_OMIT_EXPLAIN\nis\sdefined. +D 2016-03-09T13:39:43.412 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -354,7 +354,7 @@ F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 0235586b3fb639e85998d495c90f007657fd82af F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h 24e2eed36a68d48bd43d866adb528001b0795275 +F src/sqliteInt.h 84c673f27b77dfbd367cb3ed1de8b6f3b73102dc F src/sqliteLimit.h 7b28cf72cbd52f178bfc97ea266445e351f2cd24 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e0bac2f3eed900d3a26de339fb7d5963f9b47724 -R ef93df8fd296bfa582e1a9a9087c3fc6 +P a13c59d08bcbc6f26ce6ac761a892eff8f035201 +R dc65bf9f81f047db6984b996890cdadd U drh -Z 498b8899efc263dd56cd46e3ec14e230 +Z 0ec66dff68629b4a77d366f261f0f00c diff --git a/manifest.uuid b/manifest.uuid index 809eeb8fca..5d4e109453 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a13c59d08bcbc6f26ce6ac761a892eff8f035201 \ No newline at end of file +8d4b6b2b519a80f831d64345ac26db825b0e2ebe \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 350832a2e7..f2f485778a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -451,6 +451,13 @@ # undef SQLITE_NEED_ERR_NAME #endif +/* +** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN +*/ +#ifdef SQLITE_OMIT_EXPLAIN +# undef SQLITE_ENABLE_EXPLAIN_COMMENTS +#endif + /* ** Return true (non-zero) if the input is an integer that is too large ** to fit in 32-bits. This macro is used inside of various testcase() From 90730c9e689cc79921b8e1ce7252b40ea1f232cc Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 15:09:22 +0000 Subject: [PATCH 27/57] When optimizing expressions of the form "x IN (SELECT ...)" make sure that the subquery is not correlated. Fix for ticket [5e3c886796e5512]. FossilOrigin-Name: 1ed6b06ea3c432f920fb2b66b6042be906c5d21c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 5 ++++- test/where2.test | 11 +++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 32aef606c9..6ca9667196 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Automatically\sdisable\sSQLITE_ENABLE_EXPLAIN_COMMENTS\sif\sSQLITE_OMIT_EXPLAIN\nis\sdefined. -D 2016-03-09T13:39:43.412 +C When\soptimizing\sexpressions\sof\sthe\sform\s"x\sIN\s(SELECT\s...)"\smake\ssure\sthat\nthe\ssubquery\sis\snot\scorrelated.\s\sFix\sfor\sticket\s[5e3c886796e5512]. +D 2016-03-09T15:09:22.795 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -303,7 +303,7 @@ F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 0b73e681c11fca867fec554750c07fe0d4e417c1 F src/dbstat.c c845548d4346e606e2f2b7d2e714ace2b8a7dd1b F src/delete.c 48802aa3ee6339f576d074336d3ae1b5f40e240f -F src/expr.c c4dad2cd6cec00387b75fef4551aff655430dcd2 +F src/expr.c 4ce9e66a297ec08d234817c3d9f7fa8c3bf4d851 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 5cb42d9a59e2a590776fd3fc8ff6f61d40df3c6e F src/func.c 552d300265aed09eea21f68ac742a440550c0062 @@ -1332,7 +1332,7 @@ F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test c05c68d4dc2700a982f89133ce103a1a84cc285f F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e F test/where.test f0c325563acde44f2c4ea6ba348e9e29f7121757 -F test/where2.test af78c55589cbc82d793449493adba0dc3d659f23 +F test/where2.test 478d2170637b9211f593120648858593bf2445a1 F test/where3.test 1ad55ba900bd7747f98b6082e65bd3e442c5004e F test/where4.test 4a371bfcc607f41d233701bdec33ac2972908ba8 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a13c59d08bcbc6f26ce6ac761a892eff8f035201 -R dc65bf9f81f047db6984b996890cdadd +P 8d4b6b2b519a80f831d64345ac26db825b0e2ebe +R 903e4bb527a74ada303408f9543fd4d8 U drh -Z 0ec66dff68629b4a77d366f261f0f00c +Z 88acb6b3e9ba3ec690e7fd39f78d002e diff --git a/manifest.uuid b/manifest.uuid index 5d4e109453..95f57d41b6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d4b6b2b519a80f831d64345ac26db825b0e2ebe \ No newline at end of file +1ed6b06ea3c432f920fb2b66b6042be906c5d21c \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 8a69732195..22ca21de01 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1584,6 +1584,7 @@ static int isCandidateForInOpt(Select *p){ SrcList *pSrc; ExprList *pEList; Table *pTab; + Expr *pRes; /* Result expression */ if( p==0 ) return 0; /* right-hand side of IN is SELECT */ if( p->pPrior ) return 0; /* Not a compound SELECT */ if( p->selFlags & (SF_Distinct|SF_Aggregate) ){ @@ -1605,7 +1606,9 @@ static int isCandidateForInOpt(Select *p){ if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */ pEList = p->pEList; if( pEList->nExpr!=1 ) return 0; /* One column in the result set */ - if( pEList->a[0].pExpr->op!=TK_COLUMN ) return 0; /* Result is a column */ + pRes = pEList->a[0].pExpr; + if( pRes->op!=TK_COLUMN ) return 0; /* Result is a column */ + if( pRes->iTable!=pSrc->a[0].iCursor ) return 0; /* Not a correlated subq */ return 1; } #endif /* SQLITE_OMIT_SUBQUERY */ diff --git a/test/where2.test b/test/where2.test index 434a7bcd9a..0a0533506a 100644 --- a/test/where2.test +++ b/test/where2.test @@ -765,4 +765,15 @@ do_execsql_test where2-13.1 { SELECT * FROM t13 WHERE (1=2 AND a=3) OR a=4; } {4 5} +# https://www.sqlite.org/src/info/5e3c886796e5512e (2016-03-09) +# Correlated subquery on the RHS of an IN operator +# +do_execsql_test where2-14.1 { + CREATE TABLE t14a(x INTEGER PRIMARY KEY); + INSERT INTO t14a(x) VALUES(1),(2),(3),(4); + CREATE TABLE t14b(y INTEGER PRIMARY KEY); + INSERT INTO t14b(y) VALUES(1); + SELECT x FROM t14a WHERE x NOT IN (SELECT x FROM t14b); +} {} + finish_test From ab8aa11b960a916fa25330837334ff06918fda7e Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 9 Mar 2016 15:14:54 +0000 Subject: [PATCH 28/57] Add another test case for bug [5e3c8867]. FossilOrigin-Name: d91e57e49f23414ec9211b775eb11cd6230a4f96 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/in5.test | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6ca9667196..75c68eb813 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\soptimizing\sexpressions\sof\sthe\sform\s"x\sIN\s(SELECT\s...)"\smake\ssure\sthat\nthe\ssubquery\sis\snot\scorrelated.\s\sFix\sfor\sticket\s[5e3c886796e5512]. -D 2016-03-09T15:09:22.795 +C Add\sanother\stest\scase\sfor\sbug\s[5e3c8867]. +D 2016-03-09T15:14:54.990 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -788,7 +788,7 @@ F test/in.test 61a24ae38d4b64ec69f06ccdf022992f68a98176 F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068 -F test/in5.test 1de657472fa9ac2924be25c2c959ac5ca1aae554 +F test/in5.test acc710c12af118df5f8645eaba9479f5619eed81 F test/incrblob.test e81846d214f3637622620fbde7cd526781cfe328 F test/incrblob2.test a5ce5ed1d0b01e2ed347245a21170372528af0a5 F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8d4b6b2b519a80f831d64345ac26db825b0e2ebe -R 903e4bb527a74ada303408f9543fd4d8 -U drh -Z 88acb6b3e9ba3ec690e7fd39f78d002e +P 1ed6b06ea3c432f920fb2b66b6042be906c5d21c +R 95d0f94d6b7106c7ee892a8bac9f59f5 +U dan +Z b79fcffb60dd8a57430224ebf643a8ab diff --git a/manifest.uuid b/manifest.uuid index 95f57d41b6..519f37196f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ed6b06ea3c432f920fb2b66b6042be906c5d21c \ No newline at end of file +d91e57e49f23414ec9211b775eb11cd6230a4f96 \ No newline at end of file diff --git a/test/in5.test b/test/in5.test index 67d212589d..b49c93e15b 100644 --- a/test/in5.test +++ b/test/in5.test @@ -183,4 +183,39 @@ do_execsql_test 6.3.1 { SELECT count(*) FROM x2 WHERE b IN (SELECT DISTINCT a FROM x1 LIMIT 2); } {2} +#------------------------------------------------------------------------- +# Test to confirm that bug [5e3c886796e5] is fixed. +# +do_execsql_test 7.1 { + CREATE TABLE y1(a, b); + CREATE TABLE y2(c); + + INSERT INTO y1 VALUES(1, 'one'); + INSERT INTO y1 VALUES('two', 'two'); + INSERT INTO y1 VALUES(3, 'three'); + + INSERT INTO y2 VALUES('one'); + INSERT INTO y2 VALUES('two'); + INSERT INTO y2 VALUES('three'); +} {} + +do_execsql_test 7.2.1 { + SELECT a FROM y1 WHERE b NOT IN (SELECT a FROM y2); +} {1 3} +do_execsql_test 7.2.2 { + SELECT a FROM y1 WHERE b IN (SELECT a FROM y2); +} {two} + +do_execsql_test 7.3.1 { + CREATE INDEX y2c ON y2(c); + SELECT a FROM y1 WHERE b NOT IN (SELECT a FROM y2); +} {1 3} +do_execsql_test 7.3.2 { + SELECT a FROM y1 WHERE b IN (SELECT a FROM y2); +} {two} + +finish_test + + + finish_test From 69c355bd9a749eb6349f2a67aeefbc937ca458bb Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 9 Mar 2016 15:34:51 +0000 Subject: [PATCH 29/57] Slight simplification to the query optimizer logic associated with IN (SELECT). FossilOrigin-Name: 2c55c3c2950cafdc256ab540f60dc4609b9c354b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 34 +++++++++++++++------------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 75c68eb813..5189ebea8e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sanother\stest\scase\sfor\sbug\s[5e3c8867]. -D 2016-03-09T15:14:54.990 +C Slight\ssimplification\sto\sthe\squery\soptimizer\slogic\sassociated\swith\sIN\s(SELECT). +D 2016-03-09T15:34:51.959 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -303,7 +303,7 @@ F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 0b73e681c11fca867fec554750c07fe0d4e417c1 F src/dbstat.c c845548d4346e606e2f2b7d2e714ace2b8a7dd1b F src/delete.c 48802aa3ee6339f576d074336d3ae1b5f40e240f -F src/expr.c 4ce9e66a297ec08d234817c3d9f7fa8c3bf4d851 +F src/expr.c c329d581e5d631153456369684d7d4bcd94c907d F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 5cb42d9a59e2a590776fd3fc8ff6f61d40df3c6e F src/func.c 552d300265aed09eea21f68ac742a440550c0062 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1ed6b06ea3c432f920fb2b66b6042be906c5d21c -R 95d0f94d6b7106c7ee892a8bac9f59f5 -U dan -Z b79fcffb60dd8a57430224ebf643a8ab +P d91e57e49f23414ec9211b775eb11cd6230a4f96 +R c1ca42221fb7dbc6b010dbeefd096918 +U drh +Z 8017c7a46c10555b3cc0af7ce0a6b14d diff --git a/manifest.uuid b/manifest.uuid index 519f37196f..41eb62d748 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d91e57e49f23414ec9211b775eb11cd6230a4f96 \ No newline at end of file +2c55c3c2950cafdc256ab540f60dc4609b9c354b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 22ca21de01..3672d02df1 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1568,24 +1568,22 @@ int sqlite3IsRowid(const char *z){ } /* -** Return true if we are able to the IN operator optimization on a -** query of the form -** -** x IN (SELECT ...) -** -** Where the SELECT... clause is as specified by the parameter to this -** routine. -** -** The Select object passed in has already been preprocessed and no -** errors have been found. +** pX is the RHS of an IN operator. If pX is a SELECT statement +** that can be simplified to a direct table access, then return +** a pointer to the SELECT statement. If pX is not a SELECT statement, +** or if the SELECT statement needs to be manifested into a transient +** table, then return NULL. */ #ifndef SQLITE_OMIT_SUBQUERY -static int isCandidateForInOpt(Select *p){ +static Select *isCandidateForInOpt(Expr *pX){ + Select *p; SrcList *pSrc; ExprList *pEList; + Expr *pRes; Table *pTab; - Expr *pRes; /* Result expression */ - if( p==0 ) return 0; /* right-hand side of IN is SELECT */ + if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */ + if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */ + p = pX->x.pSelect; if( p->pPrior ) return 0; /* Not a compound SELECT */ if( p->selFlags & (SF_Distinct|SF_Aggregate) ){ testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ); @@ -1601,15 +1599,15 @@ static int isCandidateForInOpt(Select *p){ if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */ if( pSrc->a[0].pSelect ) return 0; /* FROM is not a subquery or view */ pTab = pSrc->a[0].pTab; - if( NEVER(pTab==0) ) return 0; + assert( pTab!=0 ); assert( pTab->pSelect==0 ); /* FROM clause is not a view */ if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */ pEList = p->pEList; if( pEList->nExpr!=1 ) return 0; /* One column in the result set */ pRes = pEList->a[0].pExpr; if( pRes->op!=TK_COLUMN ) return 0; /* Result is a column */ - if( pRes->iTable!=pSrc->a[0].iCursor ) return 0; /* Not a correlated subq */ - return 1; + assert( pRes->iTable==pSrc->a[0].iCursor ); /* Not a correlated subquery */ + return p; } #endif /* SQLITE_OMIT_SUBQUERY */ @@ -1741,15 +1739,13 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, u32 inFlags, int *prRhsHasNull){ ** satisfy the query. This is preferable to generating a new ** ephemeral table. */ - p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0); - if( pParse->nErr==0 && isCandidateForInOpt(p) ){ + if( pParse->nErr==0 && (p = isCandidateForInOpt(pX))!=0 ){ sqlite3 *db = pParse->db; /* Database connection */ Table *pTab; /* Table . */ Expr *pExpr; /* Expression */ i16 iCol; /* Index of column */ i16 iDb; /* Database idx for pTab */ - assert( p ); /* Because of isCandidateForInOpt(p) */ assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */ assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */ assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */ From 57ebc84a6e2baf82d0f11fab0f94006d15abcb28 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 9 Mar 2016 18:17:42 +0000 Subject: [PATCH 30/57] Fix a problem in fts3/4 that was causing it to discard data cached in-memory if an 'optimize' command is run when there is no data on disk. The usual way this would happen is if the very first transaction that writes to the fts3/4 table also includes an 'optimize' command. FossilOrigin-Name: 79338b991bf01e81d336790ca87a0fa747da4ff3 --- ext/fts3/fts3_write.c | 2 +- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/fts4opt.test | 44 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 24039aef30..3ff481b0b0 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -3195,7 +3195,7 @@ static int fts3SegmentMerge( ** segment. The level of the new segment is equal to the numerically ** greatest segment level currently present in the database for this ** index. The idx of the new segment is always 0. */ - if( csr.nSegment==1 ){ + if( csr.nSegment==1 && 0==fts3SegReaderIsPending(csr.apSegment[0]) ){ rc = SQLITE_DONE; goto finished; } diff --git a/manifest b/manifest index 5189ebea8e..6d3b9274dd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Slight\ssimplification\sto\sthe\squery\soptimizer\slogic\sassociated\swith\sIN\s(SELECT). -D 2016-03-09T15:34:51.959 +C Fix\sa\sproblem\sin\sfts3/4\sthat\swas\scausing\sit\sto\sdiscard\sdata\scached\sin-memory\sif\san\s'optimize'\scommand\sis\srun\swhen\sthere\sis\sno\sdata\son\sdisk.\sThe\susual\sway\sthis\swould\shappen\sis\sif\sthe\svery\sfirst\stransaction\sthat\swrites\sto\sthe\sfts3/4\stable\salso\sincludes\san\s'optimize'\scommand. +D 2016-03-09T18:17:42.821 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -88,7 +88,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 F ext/fts3/fts3_unicode2.c c3d01968d497bd7001e7dc774ba75b372738c057 -F ext/fts3/fts3_write.c fb0456fa1407758f82458417c76fe4b06c86be98 +F ext/fts3/fts3_write.c c3863f23b6b4623c8b9d5cf31c12ce4469f78ca9 F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/fts3/tool/fts3view.c 5d78b668f4e9598af9147f8999632599fb0d9dd5 @@ -755,7 +755,7 @@ F test/fts4merge3.test 8d9ccb4a3d41c4c617a149d6c4b13ad02de797d0 F test/fts4merge4.test d895b1057a7798b67e03455d0fa50e9ea836c47b F test/fts4noti.test 5553d7bb2e20bf4a06b23e849352efc022ce6309 F test/fts4onepass.test 7319d61a2ed1325fc54afd0c060a0513b462303a -F test/fts4opt.test 1901f696214c4e16a995dd7fdd70576fc5c41dbe +F test/fts4opt.test fd6a11684b965e1999564ae763797b7fb9e34c96 F test/fts4unicode.test 27378af76394542cf490cf001d8d1505fe55f6a9 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/func.test ae97561957aba6ca9e3a7b8a13aac41830d701ef @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d91e57e49f23414ec9211b775eb11cd6230a4f96 -R c1ca42221fb7dbc6b010dbeefd096918 -U drh -Z 8017c7a46c10555b3cc0af7ce0a6b14d +P 2c55c3c2950cafdc256ab540f60dc4609b9c354b +R b4dbf73ab3865664cce5c88a4214186d +U dan +Z a31e8746a8bf8afd08aed0fea525a7d3 diff --git a/manifest.uuid b/manifest.uuid index 41eb62d748..190da3e5ed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2c55c3c2950cafdc256ab540f60dc4609b9c354b \ No newline at end of file +79338b991bf01e81d336790ca87a0fa747da4ff3 \ No newline at end of file diff --git a/test/fts4opt.test b/test/fts4opt.test index 1933c57b1b..0d0ed9f4f0 100644 --- a/test/fts4opt.test +++ b/test/fts4opt.test @@ -166,4 +166,48 @@ do_execsql_test 2.8 { SELECT level, count(*) FROM t2_segdir GROUP BY level; } {0 2 1024 2 2048 2 3072 2} +#------------------------------------------------------------------------- +# Check that 'optimize' works when there is data in the in-memory hash +# table, but no segments at all on disk. +# +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE fts USING fts4 (t); + INSERT INTO fts (fts) VALUES ('optimize'); +} +do_execsql_test 3.2 { + INSERT INTO fts(fts) VALUES('integrity-check'); + SELECT count(*) FROM fts_segdir; +} {0} +do_execsql_test 3.3 { + BEGIN; + INSERT INTO fts (rowid, t) VALUES (2, 'test'); + INSERT INTO fts (fts) VALUES ('optimize'); + COMMIT; + SELECT level, idx FROM fts_segdir; +} {0 0} +do_execsql_test 3.4 { + INSERT INTO fts(fts) VALUES('integrity-check'); + SELECT rowid FROM fts WHERE fts MATCH 'test'; +} {2} +do_execsql_test 3.5 { + INSERT INTO fts (fts) VALUES ('optimize'); + INSERT INTO fts(fts) VALUES('integrity-check'); +} +do_test 3.6 { + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {[db total_changes] - $c1} +} {1} +do_test 3.7 { + execsql { INSERT INTO fts (rowid, t) VALUES (3, 'xyz') } + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {([db total_changes] - $c1) > 1} +} {1} +do_test 3.8 { + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {[db total_changes] - $c1} +} {1} + finish_test From 4dbc65b29a61ceab44fd5d0726a5d491f676ebb6 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 9 Mar 2016 20:54:14 +0000 Subject: [PATCH 31/57] Add an incremental optimize capability to fts5. Make the 'merge' command independent of the 'automerge' settings. FossilOrigin-Name: 556671444c03e3afca072d0f5e9bea2657de6fd3 --- ext/fts5/fts5Int.h | 1 + ext/fts5/fts5_config.c | 14 ++++ ext/fts5/fts5_index.c | 112 +++++++++++++++++++++++--------- ext/fts5/fts5_main.c | 6 +- ext/fts5/fts5_test_mi.c | 25 ++++--- ext/fts5/test/fts5_common.tcl | 6 ++ ext/fts5/test/fts5merge.test | 49 +++++++++++--- ext/fts5/test/fts5optimize.test | 41 +++++++++++- manifest | 26 ++++---- manifest.uuid | 2 +- 10 files changed, 213 insertions(+), 69 deletions(-) diff --git a/ext/fts5/fts5Int.h b/ext/fts5/fts5Int.h index af40412167..f9e1567fb6 100644 --- a/ext/fts5/fts5Int.h +++ b/ext/fts5/fts5Int.h @@ -172,6 +172,7 @@ struct Fts5Config { int pgsz; /* Approximate page size used in %_data */ int nAutomerge; /* 'automerge' setting */ int nCrisisMerge; /* Maximum allowed segments per level */ + int nUsermerge; /* 'usermerge' setting */ int nHashSize; /* Bytes of memory for in-memory hash */ char *zRank; /* Name of rank function */ char *zRankArgs; /* Arguments to rank function */ diff --git a/ext/fts5/fts5_config.c b/ext/fts5/fts5_config.c index f49cede129..ccc154c3b4 100644 --- a/ext/fts5/fts5_config.c +++ b/ext/fts5/fts5_config.c @@ -18,6 +18,7 @@ #define FTS5_DEFAULT_PAGE_SIZE 4050 #define FTS5_DEFAULT_AUTOMERGE 4 +#define FTS5_DEFAULT_USERMERGE 4 #define FTS5_DEFAULT_CRISISMERGE 16 #define FTS5_DEFAULT_HASHSIZE (1024*1024) @@ -857,6 +858,18 @@ int sqlite3Fts5ConfigSetValue( } } + else if( 0==sqlite3_stricmp(zKey, "usermerge") ){ + int nUsermerge = -1; + if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){ + nUsermerge = sqlite3_value_int(pVal); + } + if( nUsermerge<2 || nUsermerge>16 ){ + *pbBadkey = 1; + }else{ + pConfig->nUsermerge = nUsermerge; + } + } + else if( 0==sqlite3_stricmp(zKey, "crisismerge") ){ int nCrisisMerge = -1; if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){ @@ -903,6 +916,7 @@ int sqlite3Fts5ConfigLoad(Fts5Config *pConfig, int iCookie){ /* Set default values */ pConfig->pgsz = FTS5_DEFAULT_PAGE_SIZE; pConfig->nAutomerge = FTS5_DEFAULT_AUTOMERGE; + pConfig->nUsermerge = FTS5_DEFAULT_USERMERGE; pConfig->nCrisisMerge = FTS5_DEFAULT_CRISISMERGE; pConfig->nHashSize = FTS5_DEFAULT_HASHSIZE; diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index ac97a7d75f..6f0b2d93cf 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -4179,13 +4179,17 @@ static void fts5IndexMergeLevel( /* ** Do up to nPg pages of automerge work on the index. +** +** Return true if any changes were actually made, or false otherwise. */ -static void fts5IndexMerge( +static int fts5IndexMerge( Fts5Index *p, /* FTS5 backend object */ Fts5Structure **ppStruct, /* IN/OUT: Current structure of index */ - int nPg /* Pages of work to do */ + int nPg, /* Pages of work to do */ + int nMin /* Minimum number of segments to merge */ ){ int nRem = nPg; + int bRet = 0; Fts5Structure *pStruct = *ppStruct; while( nRem>0 && p->rc==SQLITE_OK ){ int iLvl; /* To iterate through levels */ @@ -4216,17 +4220,17 @@ static void fts5IndexMerge( } #endif - if( nBestpConfig->nAutomerge - && pStruct->aLevel[iBestLvl].nMerge==0 - ){ + if( nBestaLevel[iBestLvl].nMerge==0 ){ break; } + bRet = 1; fts5IndexMergeLevel(p, &pStruct, iBestLvl, &nRem); if( p->rc==SQLITE_OK && pStruct->aLevel[iBestLvl].nMerge==0 ){ fts5StructurePromote(p, iBestLvl+1, pStruct); } } *ppStruct = pStruct; + return bRet; } /* @@ -4254,7 +4258,7 @@ static void fts5IndexAutomerge( pStruct->nWriteCounter += nLeaf; nRem = (int)(p->nWorkUnit * nWork * pStruct->nLevel); - fts5IndexMerge(p, ppStruct, nRem); + fts5IndexMerge(p, ppStruct, nRem, p->pConfig->nAutomerge); } } @@ -4474,25 +4478,38 @@ static void fts5IndexFlush(Fts5Index *p){ } } - -int sqlite3Fts5IndexOptimize(Fts5Index *p){ - Fts5Structure *pStruct; +static Fts5Structure *fts5IndexOptimizeStruct( + Fts5Index *p, + Fts5Structure *pStruct +){ Fts5Structure *pNew = 0; - int nSeg = 0; + int nByte = sizeof(Fts5Structure); + int nSeg = pStruct->nSegment; + int i; - assert( p->rc==SQLITE_OK ); - fts5IndexFlush(p); - pStruct = fts5StructureRead(p); - - if( pStruct ){ - assert( pStruct->nSegment==fts5StructureCountSegments(pStruct) ); - nSeg = pStruct->nSegment; - if( nSeg>1 ){ - int nByte = sizeof(Fts5Structure); - nByte += (pStruct->nLevel+1) * sizeof(Fts5StructureLevel); - pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte); + /* Figure out if this structure requires optimization. A structure does + ** not require optimization if either: + ** + ** + it consists of fewer than two segments, or + ** + all segments are on the same level, or + ** + all segments except one are currently inputs to a merge operation. + ** + ** In the first case, return NULL. In the second, increment the ref-count + ** on *pStruct and return a copy of the pointer to it. + */ + if( nSeg<2 ) return 0; + for(i=0; inLevel; i++){ + int nThis = pStruct->aLevel[i].nSeg; + if( nThis==nSeg || (nThis==nSeg-1 && pStruct->aLevel[i].nMerge==nThis) ){ + fts5StructureRef(pStruct); + return pStruct; } + assert( pStruct->aLevel[i].nMerge<=nThis ); } + + nByte += (pStruct->nLevel+1) * sizeof(Fts5StructureLevel); + pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte); + if( pNew ){ Fts5StructureLevel *pLvl; int nByte = nSeg * sizeof(Fts5StructureSegment); @@ -4520,8 +4537,28 @@ int sqlite3Fts5IndexOptimize(Fts5Index *p){ } } - if( pNew ){ - int iLvl = pNew->nLevel-1; + return pNew; +} + +int sqlite3Fts5IndexOptimize(Fts5Index *p){ + Fts5Structure *pStruct; + Fts5Structure *pNew = 0; + int nSeg = 0; + + assert( p->rc==SQLITE_OK ); + fts5IndexFlush(p); + pStruct = fts5StructureRead(p); + + if( pStruct ){ + pNew = fts5IndexOptimizeStruct(p, pStruct); + } + fts5StructureRelease(pStruct); + + if( pNew && pNew->nSegment>0 ){ + int iLvl; + for(iLvl=0; iLvlnLevel; iLvl++){ + if( pNew->aLevel[iLvl].nSeg ) break; + } while( p->rc==SQLITE_OK && pNew->aLevel[iLvl].nSeg>0 ){ int nRem = FTS5_OPT_WORK_UNIT; fts5IndexMergeLevel(p, &pNew, iLvl, &nRem); @@ -4531,20 +4568,31 @@ int sqlite3Fts5IndexOptimize(Fts5Index *p){ fts5StructureRelease(pNew); } - fts5StructureRelease(pStruct); return fts5IndexReturn(p); } +/* +** This is called to implement the special "VALUES('merge', $nMerge)" +** INSERT command. +*/ int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge){ - Fts5Structure *pStruct; - - pStruct = fts5StructureRead(p); - if( pStruct && pStruct->nLevel ){ - fts5IndexMerge(p, &pStruct, nMerge); - fts5StructureWrite(p, pStruct); + Fts5Structure *pStruct = fts5StructureRead(p); + if( pStruct ){ + int nMin = p->pConfig->nUsermerge; + if( nMerge<0 ){ + Fts5Structure *pNew = fts5IndexOptimizeStruct(p, pStruct); + fts5StructureRelease(pStruct); + pStruct = pNew; + nMin = 2; + nMerge = nMerge*-1; + } + if( pStruct && pStruct->nLevel ){ + if( fts5IndexMerge(p, &pStruct, nMerge, nMin) ){ + fts5StructureWrite(p, pStruct); + } + } + fts5StructureRelease(pStruct); } - fts5StructureRelease(pStruct); - return fts5IndexReturn(p); } diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index 28f3f3e62c..dcd131c74a 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -1511,13 +1511,13 @@ static int fts5UpdateMethod( rc = SQLITE_ERROR; } - /* Case 1: DELETE */ + /* DELETE */ else if( nArg==1 ){ i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */ rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0); } - /* Case 2: INSERT */ + /* INSERT */ else if( eType0!=SQLITE_INTEGER ){ /* If this is a REPLACE, first remove the current entry (if any) */ if( eConflict==SQLITE_REPLACE @@ -1529,7 +1529,7 @@ static int fts5UpdateMethod( fts5StorageInsert(&rc, pTab, apVal, pRowid); } - /* Case 2: UPDATE */ + /* UPDATE */ else{ i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */ i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */ diff --git a/ext/fts5/fts5_test_mi.c b/ext/fts5/fts5_test_mi.c index bc6d01f126..a905b85bb9 100644 --- a/ext/fts5/fts5_test_mi.c +++ b/ext/fts5/fts5_test_mi.c @@ -68,18 +68,22 @@ struct Fts5MatchinfoCtx { ** If an error occurs, return NULL and leave an error in the database ** handle (accessible using sqlite3_errcode()/errmsg()). */ -static fts5_api *fts5_api_from_db(sqlite3 *db){ - fts5_api *pRet = 0; +static int fts5_api_from_db(sqlite3 *db, fts5_api **ppApi){ sqlite3_stmt *pStmt = 0; + int rc; - if( SQLITE_OK==sqlite3_prepare(db, "SELECT fts5()", -1, &pStmt, 0) - && SQLITE_ROW==sqlite3_step(pStmt) - && sizeof(pRet)==sqlite3_column_bytes(pStmt, 0) - ){ - memcpy(&pRet, sqlite3_column_blob(pStmt, 0), sizeof(pRet)); + *ppApi = 0; + rc = sqlite3_prepare(db, "SELECT fts5()", -1, &pStmt, 0); + if( rc==SQLITE_OK ){ + if( SQLITE_ROW==sqlite3_step(pStmt) + && sizeof(fts5_api*)==sqlite3_column_bytes(pStmt, 0) + ){ + memcpy(ppApi, sqlite3_column_blob(pStmt, 0), sizeof(fts5_api*)); + } + rc = sqlite3_finalize(pStmt); } - sqlite3_finalize(pStmt); - return pRet; + + return rc; } @@ -399,7 +403,8 @@ int sqlite3Fts5TestRegisterMatchinfo(sqlite3 *db){ /* Extract the FTS5 API pointer from the database handle. The ** fts5_api_from_db() function above is copied verbatim from the ** FTS5 documentation. Refer there for details. */ - pApi = fts5_api_from_db(db); + rc = fts5_api_from_db(db, &pApi); + if( rc!=SQLITE_OK ) return rc; /* If fts5_api_from_db() returns NULL, then either FTS5 is not registered ** with this database handle, or an error (OOM perhaps?) has occurred. diff --git a/ext/fts5/test/fts5_common.tcl b/ext/fts5/test/fts5_common.tcl index 32691d1c81..0f371dcfd9 100644 --- a/ext/fts5/test/fts5_common.tcl +++ b/ext/fts5/test/fts5_common.tcl @@ -159,6 +159,12 @@ proc fts5_aux_test_functions {db} { } } +proc fts5_segcount {tbl} { + set N 0 + foreach n [fts5_level_segs $tbl] { incr N $n } + set N +} + proc fts5_level_segs {tbl} { set sql "SELECT fts5_decode(rowid,block) aS r FROM ${tbl}_data WHERE rowid=10" set ret [list] diff --git a/ext/fts5/test/fts5merge.test b/ext/fts5/test/fts5merge.test index 9dd1ecd026..48e3dce933 100644 --- a/ext/fts5/test/fts5merge.test +++ b/ext/fts5/test/fts5merge.test @@ -45,7 +45,7 @@ proc do_merge1_test {testname nRowPerSeg} { WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<$::nRowPerSeg) INSERT INTO x8 SELECT repeat('x y ', i % 16) FROM ii; - INSERT INTO x8(x8, rank) VALUES('automerge', 2); + INSERT INTO x8(x8, rank) VALUES('usermerge', 2); } for {set tn 1} {[lindex [fts5_level_segs x8] 0]>0} {incr tn} { @@ -84,9 +84,9 @@ proc do_merge2_test {testname nRow} { execsql { INSERT INTO x8 VALUES( rnddoc(($i%16) + 5) ) } while {[not_merged x8]} { execsql { - INSERT INTO x8(x8, rank) VALUES('automerge', 2); + INSERT INTO x8(x8, rank) VALUES('usermerge', 2); INSERT INTO x8(x8, rank) VALUES('merge', 1); - INSERT INTO x8(x8, rank) VALUES('automerge', 16); + INSERT INTO x8(x8, rank) VALUES('usermerge', 16); INSERT INTO x8(x8) VALUES('integrity-check'); } } @@ -104,9 +104,9 @@ do_merge2_test 2.2 10 do_merge2_test 2.3 20 #------------------------------------------------------------------------- -# Test that an auto-merge will complete any merge that has already been +# Test that a merge will complete any merge that has already been # started, even if the number of input segments is less than the current -# value of the 'automerge' configuration parameter. +# value of the 'usermerge' configuration parameter. # db func rnddoc fts5_rnddoc @@ -119,7 +119,7 @@ do_execsql_test 3.1 { } do_test 3.2 { execsql { - INSERT INTO x8(x8, rank) VALUES('automerge', 4); + INSERT INTO x8(x8, rank) VALUES('usermerge', 4); INSERT INTO x8(x8, rank) VALUES('merge', 1); } fts5_level_segs x8 @@ -127,14 +127,14 @@ do_test 3.2 { do_test 3.3 { execsql { - INSERT INTO x8(x8, rank) VALUES('automerge', 2); + INSERT INTO x8(x8, rank) VALUES('usermerge', 2); INSERT INTO x8(x8, rank) VALUES('merge', 1); } fts5_level_segs x8 } {2 1} do_test 3.4 { - execsql { INSERT INTO x8(x8, rank) VALUES('automerge', 4) } + execsql { INSERT INTO x8(x8, rank) VALUES('usermerge', 4) } while {[not_merged x8]} { execsql { INSERT INTO x8(x8, rank) VALUES('merge', 1) } } @@ -176,7 +176,7 @@ foreach {tn pgsz} { INSERT INTO x8 SELECT mydoc() FROM ii; WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) INSERT INTO x8 SELECT mydoc() FROM ii; - INSERT INTO x8(x8, rank) VALUES('automerge', 2); + INSERT INTO x8(x8, rank) VALUES('usermerge', 2); } set expect [mycount] @@ -190,5 +190,36 @@ foreach {tn pgsz} { # db eval {SELECT fts5_decode(rowid, block) AS r FROM x8_data} { puts $r } } +#------------------------------------------------------------------------- +# Test that the 'merge' command does not modify the database if there is +# no work to do. + +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE x9 USING fts5(one, two); + INSERT INTO x9(x9, rank) VALUES('pgsz', 32); + INSERT INTO x9(x9, rank) VALUES('automerge', 2); + INSERT INTO x9(x9, rank) VALUES('usermerge', 2); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); + INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); +} + +do_test 5.2 { + while 1 { + set nChange [db total_changes] + execsql { INSERT INTO x9(x9, rank) VALUES('merge', 1); } + set nChange [expr [db total_changes] - $nChange] + #puts $nChange + if {$nChange<2} break + } +} {} + + + finish_test diff --git a/ext/fts5/test/fts5optimize.test b/ext/fts5/test/fts5optimize.test index 984af8c532..48d4e1dd36 100644 --- a/ext/fts5/test/fts5optimize.test +++ b/ext/fts5/test/fts5optimize.test @@ -37,7 +37,6 @@ foreach {tn nStep} { 3 50 4 500 } { -if {$tn!=4} continue reset_db db func rnddoc rnddoc do_execsql_test 1.$tn.1 { @@ -60,6 +59,46 @@ if {$tn!=4} continue do_execsql_test 1.$tn.5 { INSERT INTO t1(t1) VALUES('integrity-check'); } + + do_test 1.$tn.6 { fts5_segcount t1 } 1 +} + +foreach {tn nStep} { + 1 2 + 2 10 + 3 50 + 4 500 +} { + reset_db + db func rnddoc rnddoc + do_execsql_test 1.$tn.1 { + CREATE VIRTUAL TABLE t1 USING fts5(x, y); + } + do_test 2.$tn.2 { + for {set i 0} {$i < $nStep} {incr i} { + execsql { INSERT INTO t1 VALUES( rnddoc(5), rnddoc(5) ) } + } + } {} + + do_execsql_test 2.$tn.3 { + INSERT INTO t1(t1) VALUES('integrity-check'); + } + + do_test 2.$tn.4 { + execsql { INSERT INTO t1(t1, rank) VALUES('merge', -1) } + while 1 { + set c [db total_changes] + execsql { INSERT INTO t1(t1, rank) VALUES('merge', 1) } + set c [expr [db total_changes]-$c] + if {$c<2} break + } + } {} + + do_execsql_test 2.$tn.5 { + INSERT INTO t1(t1) VALUES('integrity-check'); + } + + do_test 2.$tn.6 { fts5_segcount t1 } 1 } finish_test diff --git a/manifest b/manifest index 6d3b9274dd..590403a1e0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sfts3/4\sthat\swas\scausing\sit\sto\sdiscard\sdata\scached\sin-memory\sif\san\s'optimize'\scommand\sis\srun\swhen\sthere\sis\sno\sdata\son\sdisk.\sThe\susual\sway\sthis\swould\shappen\sis\sif\sthe\svery\sfirst\stransaction\sthat\swrites\sto\sthe\sfts3/4\stable\salso\sincludes\san\s'optimize'\scommand. -D 2016-03-09T18:17:42.821 +C Add\san\sincremental\soptimize\scapability\sto\sfts5.\sMake\sthe\s'merge'\scommand\sindependent\sof\sthe\s'automerge'\ssettings. +D 2016-03-09T20:54:14.606 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -98,17 +98,17 @@ F ext/fts3/unicode/mkunicode.tcl 2debed3f582d77b3fdd0b8830880250021571fd8 F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/fts5.h ff9c2782e8ed890b0de2f697a8d63971939e70c7 -F ext/fts5/fts5Int.h fa7c17e5c3ec9c8690387ff962f9dc6aee75e114 +F ext/fts5/fts5Int.h 59e13423371512df1992532a08fe80518244f96b F ext/fts5/fts5_aux.c daa57fb45216491814520bbb587e97bf81ced458 F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd -F ext/fts5/fts5_config.c 35c5173cae4eb17e82164a7f5aeef56a48903079 +F ext/fts5/fts5_config.c abd3ae1107ca8b8def7445a0a3b70c2e46d05986 F ext/fts5/fts5_expr.c 8e8e4635f655133eb39018072fc0f0942a2c4337 F ext/fts5/fts5_hash.c f3a7217c86eb8f272871be5f6aa1b6798960a337 -F ext/fts5/fts5_index.c 26a4a6112864feb599a6f6144d06a78bb179736a -F ext/fts5/fts5_main.c db24ac714c6c4a1b3c24a1f8c25889f2952148c1 +F ext/fts5/fts5_index.c f7f3c042edf3e6a8984efa95ce1d5305d73bb535 +F ext/fts5/fts5_main.c b8501e1a6a11591c53b18ce7aea7e5386cfb0421 F ext/fts5/fts5_storage.c f8343db90d8c95a4d4b52f6676e354b4649ffd6e F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 -F ext/fts5/fts5_test_mi.c b8d04816428202b2898d4ca38deb1739ac0110ae +F ext/fts5/fts5_test_mi.c 783b86697ebf773c18fc109992426c0173a055bc F ext/fts5/fts5_test_tok.c db08af63673c3a7d39f053b36fd6e065017706be F ext/fts5/fts5_tokenize.c 2ce7b44183538ec46b7907726262ee43ffdd39a8 F ext/fts5/fts5_unicode2.c b450b209b157d598f7b9df9f837afb75a14c24bf @@ -116,7 +116,7 @@ F ext/fts5/fts5_varint.c a5aceacda04dafcbae725413d7a16818ecd65738 F ext/fts5/fts5_vocab.c dba72ca393d71c2588548b51380387f6b44c77a8 F ext/fts5/fts5parse.y 86fe6ba094a47e02fe8be2571539e6833d197764 F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba -F ext/fts5/test/fts5_common.tcl b9b1fed811c0390511cef8b254826ea15d380f4d +F ext/fts5/test/fts5_common.tcl b01c584144b5064f30e6c648145a2dd6bc440841 F ext/fts5/test/fts5aa.test 7e814df4a0e6c22a6fe2d84f210fdc0b5068a084 F ext/fts5/test/fts5ab.test 30325a89453280160106be411bba3acf138e6d1b F ext/fts5/test/fts5ac.test 55cad4275a1f5acabfe14d8442a8046b47e49e5f @@ -162,11 +162,11 @@ F ext/fts5/test/fts5full.test 6f6143af0c6700501d9fd597189dfab1555bb741 F ext/fts5/test/fts5hash.test 06f9309ccb4d5050a131594e9e47d0b21456837d F ext/fts5/test/fts5integrity.test f5e4f8d284385875068ad0f3e894ce43e9de835d F ext/fts5/test/fts5matchinfo.test f7dde99697bcb310ea8faa8eb2714d9f4dfc0e1b -F ext/fts5/test/fts5merge.test 8f3cdba2ec9c5e7e568246e81b700ad37f764367 +F ext/fts5/test/fts5merge.test 9e04a16963e32bf7c51835ce23e58325bbdfb35f F ext/fts5/test/fts5merge2.test a6da3c16d694235938d1939f503cfa53f0943d75 F ext/fts5/test/fts5near.test b214cddb1c1f1bddf45c75af768f20145f7e71cc F ext/fts5/test/fts5onepass.test 7ed9608e258132cb8d55e7c479b08676ad68810c -F ext/fts5/test/fts5optimize.test 42741e7c085ee0a1276140a752d4407d97c2c9f5 +F ext/fts5/test/fts5optimize.test 0f25ce4cc1f78a4cf5dd1247d30135b3f7180a19 F ext/fts5/test/fts5phrase.test f6d1d464da5beb25dc56277aa4f1d6102f0d9a2f F ext/fts5/test/fts5plan.test 6a55ecbac9890765b0e16f8c421c7e0888cfe436 F ext/fts5/test/fts5porter.test 7cdc07bef301d70eebbfa75dcaf45c3680e1d0e1 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2c55c3c2950cafdc256ab540f60dc4609b9c354b -R b4dbf73ab3865664cce5c88a4214186d +P 79338b991bf01e81d336790ca87a0fa747da4ff3 +R a3916c8b307d01845fad235da028d539 U dan -Z a31e8746a8bf8afd08aed0fea525a7d3 +Z 1a31d386083951a3ddfabf8f6c0df92f diff --git a/manifest.uuid b/manifest.uuid index 190da3e5ed..39d9cd0036 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -79338b991bf01e81d336790ca87a0fa747da4ff3 \ No newline at end of file +556671444c03e3afca072d0f5e9bea2657de6fd3 \ No newline at end of file From 6459ca0b8ceb8a8ac6008c810667d7060836b939 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 10 Mar 2016 14:22:42 +0000 Subject: [PATCH 32/57] Remove an unused local variable. FossilOrigin-Name: 3c343c3d012367942037e64a9855b825cb459844 --- ext/fts5/fts5_index.c | 1 - manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 6f0b2d93cf..fc6c8e0f9b 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -4543,7 +4543,6 @@ static Fts5Structure *fts5IndexOptimizeStruct( int sqlite3Fts5IndexOptimize(Fts5Index *p){ Fts5Structure *pStruct; Fts5Structure *pNew = 0; - int nSeg = 0; assert( p->rc==SQLITE_OK ); fts5IndexFlush(p); diff --git a/manifest b/manifest index 590403a1e0..c0ca7ed9bb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\sincremental\soptimize\scapability\sto\sfts5.\sMake\sthe\s'merge'\scommand\sindependent\sof\sthe\s'automerge'\ssettings. -D 2016-03-09T20:54:14.606 +C Remove\san\sunused\slocal\svariable. +D 2016-03-10T14:22:42.064 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -104,7 +104,7 @@ F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd F ext/fts5/fts5_config.c abd3ae1107ca8b8def7445a0a3b70c2e46d05986 F ext/fts5/fts5_expr.c 8e8e4635f655133eb39018072fc0f0942a2c4337 F ext/fts5/fts5_hash.c f3a7217c86eb8f272871be5f6aa1b6798960a337 -F ext/fts5/fts5_index.c f7f3c042edf3e6a8984efa95ce1d5305d73bb535 +F ext/fts5/fts5_index.c 8def6f0ac63b960634674d9dc844244f39b4f25d F ext/fts5/fts5_main.c b8501e1a6a11591c53b18ce7aea7e5386cfb0421 F ext/fts5/fts5_storage.c f8343db90d8c95a4d4b52f6676e354b4649ffd6e F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 79338b991bf01e81d336790ca87a0fa747da4ff3 -R a3916c8b307d01845fad235da028d539 -U dan -Z 1a31d386083951a3ddfabf8f6c0df92f +P 556671444c03e3afca072d0f5e9bea2657de6fd3 +R a2320da0e2fa85ffcb15f59a61bf4023 +U drh +Z c878404512f3f3f9c49842f23ff627b0 diff --git a/manifest.uuid b/manifest.uuid index 39d9cd0036..fba18405da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -556671444c03e3afca072d0f5e9bea2657de6fd3 \ No newline at end of file +3c343c3d012367942037e64a9855b825cb459844 \ No newline at end of file From ecdf20d3a420d3c5d31238cae6422751f8be824c Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 10 Mar 2016 14:28:24 +0000 Subject: [PATCH 33/57] Use #ifdefs to remove code that is unreachable in some configurations, replacing it with an assert(). FossilOrigin-Name: f96ec84d605fd73c323344a753acf35b76307af9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/util.c | 13 +++++++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index c0ca7ed9bb..18172bf6eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunused\slocal\svariable. -D 2016-03-10T14:22:42.064 +C Use\s#ifdefs\sto\sremove\scode\sthat\sis\sunreachable\sin\ssome\sconfigurations,\sreplacing\nit\swith\san\sassert(). +D 2016-03-10T14:28:24.490 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -413,7 +413,7 @@ F src/treeview.c e4b41a37530a191579d3c53142cc44ee2eb99373 F src/trigger.c e14840ee0c3e549e758ec9bf3e4146e166002280 F src/update.c 56b3db7edff0110360a12b76af97c39ebe3ea8b8 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c -F src/util.c 12800a93f0664f41575f96799eb881a786d565e6 +F src/util.c 34ef7be420f82415ec48131404995ddb6ee7502f F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52 F src/vdbe.c 87ae3a5657fefed7875f3eb30e7ababd48013d71 F src/vdbe.h c743791f723049db94f009e3e30958952bc2d512 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 556671444c03e3afca072d0f5e9bea2657de6fd3 -R a2320da0e2fa85ffcb15f59a61bf4023 +P 3c343c3d012367942037e64a9855b825cb459844 +R cc439e49a58b31085f4379adad06b3a4 U drh -Z c878404512f3f3f9c49842f23ff627b0 +Z ed62054916964b4fe2af635a90038c7e diff --git a/manifest.uuid b/manifest.uuid index fba18405da..765f18c2cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3c343c3d012367942037e64a9855b825cb459844 \ No newline at end of file +f96ec84d605fd73c323344a753acf35b76307af9 \ No newline at end of file diff --git a/src/util.c b/src/util.c index 6aead47faa..d6a6f6b954 100644 --- a/src/util.c +++ b/src/util.c @@ -1424,9 +1424,14 @@ u64 sqlite3LogEstToInt(LogEst x){ x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; - if( x>=3 ){ - return x>60 ? (u64)LARGEST_INT64 : (n+8)<<(x-3); - } - return (n+8)>>(3-x); +#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ + defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) + if( x>60 ) return (u64)LARGEST_INT64; +#else + /* If only SQLITE_ENABLE_STAT3_OR_STAT4 is on, then the largest input + ** possible to this routine is 310, resulting in a maximum x of 31 */ + assert( x<=60 ); +#endif + return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x); } #endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */ From 1bb85f3ed342deb13bbe47c24dbd75f47a1e2e15 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 10 Mar 2016 15:12:47 +0000 Subject: [PATCH 34/57] Add tests to cover untested branches in recent fts5 changes. FossilOrigin-Name: fa0033edf6ddf3c6631fa95b343225dbc8ac9429 --- ext/fts5/fts5_index.c | 7 +++---- ext/fts5/test/fts5config.test | 16 ++++++++++++++++ ext/fts5/test/fts5fault8.test | 25 +++++++++++++++++++++++++ ext/fts5/test/fts5merge.test | 19 +++++++++++++++++++ ext/fts5/test/fts5optimize.test | 8 ++++++-- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- 7 files changed, 81 insertions(+), 18 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index fc6c8e0f9b..323e6cefdc 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -4553,11 +4553,10 @@ int sqlite3Fts5IndexOptimize(Fts5Index *p){ } fts5StructureRelease(pStruct); - if( pNew && pNew->nSegment>0 ){ + assert( pNew==0 || pNew->nSegment>0 ); + if( pNew ){ int iLvl; - for(iLvl=0; iLvlnLevel; iLvl++){ - if( pNew->aLevel[iLvl].nSeg ) break; - } + for(iLvl=0; pNew->aLevel[iLvl].nSeg==0; iLvl++){} while( p->rc==SQLITE_OK && pNew->aLevel[iLvl].nSeg>0 ){ int nRem = FTS5_OPT_WORK_UNIT; fts5IndexMergeLevel(p, &pNew, iLvl, &nRem); diff --git a/ext/fts5/test/fts5config.test b/ext/fts5/test/fts5config.test index c30a597242..386d112e7d 100644 --- a/ext/fts5/test/fts5config.test +++ b/ext/fts5/test/fts5config.test @@ -247,5 +247,21 @@ do_catchsql_test 12.1 { INSERT INTO t1(t1, rank) VALUES('rank', NULL);; } {1 {SQL logic error or missing database}} +#------------------------------------------------------------------------- +# errors in the 'usermerge' option +# +do_execsql_test 13.0 { + CREATE VIRTUAL TABLE tt USING fts5(ttt); +} +foreach {tn val} { + 1 -1 + 2 4.2 + 3 17 + 4 1 +} { + set sql "INSERT INTO tt(tt, rank) VALUES('usermerge', $val)" + do_catchsql_test 13.$tn $sql {1 {SQL logic error or missing database}} +} + finish_test diff --git a/ext/fts5/test/fts5fault8.test b/ext/fts5/test/fts5fault8.test index ae5849495b..c613490e54 100644 --- a/ext/fts5/test/fts5fault8.test +++ b/ext/fts5/test/fts5fault8.test @@ -54,7 +54,32 @@ foreach_detail_mode $testprefix { faultsim_test_result {0 {1 3}} {1 SQLITE_NOMEM} } } + } ;# foreach_detail_mode... + +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE x2 USING fts5(a); + INSERT INTO x2(x2, rank) VALUES('crisismerge', 2); + INSERT INTO x2(x2, rank) VALUES('pgsz', 32); + INSERT INTO x2 VALUES('a b c d'); + INSERT INTO x2 VALUES('e f g h'); + INSERT INTO x2 VALUES('i j k l'); + INSERT INTO x2 VALUES('m n o p'); + INSERT INTO x2 VALUES('q r s t'); + INSERT INTO x2 VALUES('u v w x'); + INSERT INTO x2 VALUES('y z a b'); +} +faultsim_save_and_close + +do_faultsim_test 4 -faults oom-* -prep { + faultsim_restore_and_reopen +} -body { + execsql { INSERT INTO x2(x2) VALUES('optimize') } +} -test { + faultsim_test_result {0 {}} {1 SQLITE_NOMEM} +} + + finish_test diff --git a/ext/fts5/test/fts5merge.test b/ext/fts5/test/fts5merge.test index 48e3dce933..73e006a7d2 100644 --- a/ext/fts5/test/fts5merge.test +++ b/ext/fts5/test/fts5merge.test @@ -220,6 +220,25 @@ do_test 5.2 { } {} +#-------------------------------------------------------------------------- +# Test that running 'merge' on an empty database does not cause a +# problem. +# +reset_db +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE g1 USING fts5(a, b); +} +do_execsql_test 6.1 { + INSERT INTO g1(g1, rank) VALUES('merge', 10); +} +do_execsql_test 6.2 { + INSERT INTO g1(g1, rank) VALUES('merge', -10); +} +do_execsql_test 6.3 { + INSERT INTO g1(g1) VALUES('integrity-check'); +} + + finish_test diff --git a/ext/fts5/test/fts5optimize.test b/ext/fts5/test/fts5optimize.test index 48d4e1dd36..3ef6d8a165 100644 --- a/ext/fts5/test/fts5optimize.test +++ b/ext/fts5/test/fts5optimize.test @@ -20,6 +20,12 @@ ifcapable !fts5 { return } +# +# 1.* - Warm body tests for index optimization using ('optimize') +# +# 2.* - Warm body tests for index optimization using ('merge', -1) +# + proc rnddoc {nWord} { set vocab {a b c d e f g h i j k l m n o p q r s t u v w x y z} set nVocab [llength $vocab] @@ -30,7 +36,6 @@ proc rnddoc {nWord} { return $ret } - foreach {tn nStep} { 1 2 2 10 @@ -100,6 +105,5 @@ foreach {tn nStep} { do_test 2.$tn.6 { fts5_segcount t1 } 1 } - finish_test diff --git a/manifest b/manifest index 18172bf6eb..238a295d30 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\s#ifdefs\sto\sremove\scode\sthat\sis\sunreachable\sin\ssome\sconfigurations,\sreplacing\nit\swith\san\sassert(). -D 2016-03-10T14:28:24.490 +C Add\stests\sto\scover\suntested\sbranches\sin\srecent\sfts5\schanges. +D 2016-03-10T15:12:47.687 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -104,7 +104,7 @@ F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd F ext/fts5/fts5_config.c abd3ae1107ca8b8def7445a0a3b70c2e46d05986 F ext/fts5/fts5_expr.c 8e8e4635f655133eb39018072fc0f0942a2c4337 F ext/fts5/fts5_hash.c f3a7217c86eb8f272871be5f6aa1b6798960a337 -F ext/fts5/fts5_index.c 8def6f0ac63b960634674d9dc844244f39b4f25d +F ext/fts5/fts5_index.c d4f0c12e4f04bbc3a06b6da052039f2ce3e45438 F ext/fts5/fts5_main.c b8501e1a6a11591c53b18ce7aea7e5386cfb0421 F ext/fts5/fts5_storage.c f8343db90d8c95a4d4b52f6676e354b4649ffd6e F ext/fts5/fts5_tcl.c f8731e0508299bd43f1a2eff7dbeaac870768966 @@ -136,7 +136,7 @@ F ext/fts5/test/fts5auxdata.test 141a7cbffcceb1bd2799b4b29c183ff8780d586e F ext/fts5/test/fts5bigpl.test 04ee0d7eebbebf17c31f5a0b5c5f9494eac3a0cb F ext/fts5/test/fts5bigtok.test 017a9397b14e7598883a6328ead4a6539b42d59a F ext/fts5/test/fts5columnsize.test a8cfef21ffa1c264b9f670a7d94eeaccb5341c07 -F ext/fts5/test/fts5config.test 8b2bc6dcc0eb06fa2b7dd65b2ce2db09e829e873 +F ext/fts5/test/fts5config.test 7788b9c058074d640dfcdd81d97b6a9480000368 F ext/fts5/test/fts5conflict.test 26f4e46c4d31e16221794832a990dc4e30e18de5 F ext/fts5/test/fts5content.test 9a952c95518a14182dc3b59e3c8fa71cda82a4e1 F ext/fts5/test/fts5corrupt.test c2ad090192708150d50d961278df10ae7a4b8b62 @@ -154,7 +154,7 @@ F ext/fts5/test/fts5fault4.test 532b6dacb963016cbf7003196bd87fb366540277 F ext/fts5/test/fts5fault5.test 10c13a783de3f42a21e3e53e123b62ed0c3a1618 F ext/fts5/test/fts5fault6.test 9682664d679643ac6736e90c225526cc84073cda F ext/fts5/test/fts5fault7.test cb14ea3c1f42394f06f2284abc58eecee6ff8080 -F ext/fts5/test/fts5fault8.test 430837fe6dd0511fd3aea52bd602ac02441bcb58 +F ext/fts5/test/fts5fault8.test 6785af34bd1760de74e2824ea9c161965af78f85 F ext/fts5/test/fts5fault9.test e10e395428a9ea0596ebe752ff7123d16ab78e08 F ext/fts5/test/fts5faultA.test fa5d59c0ff62b7125cd14eee38ded1c46e15a7ea F ext/fts5/test/fts5faultB.test 92ae906284062bf081b6c854afa54dcb1aa9ef88 @@ -162,11 +162,11 @@ F ext/fts5/test/fts5full.test 6f6143af0c6700501d9fd597189dfab1555bb741 F ext/fts5/test/fts5hash.test 06f9309ccb4d5050a131594e9e47d0b21456837d F ext/fts5/test/fts5integrity.test f5e4f8d284385875068ad0f3e894ce43e9de835d F ext/fts5/test/fts5matchinfo.test f7dde99697bcb310ea8faa8eb2714d9f4dfc0e1b -F ext/fts5/test/fts5merge.test 9e04a16963e32bf7c51835ce23e58325bbdfb35f +F ext/fts5/test/fts5merge.test 9f65f090d214ff865c56bef4f864aaa1182af6e3 F ext/fts5/test/fts5merge2.test a6da3c16d694235938d1939f503cfa53f0943d75 F ext/fts5/test/fts5near.test b214cddb1c1f1bddf45c75af768f20145f7e71cc F ext/fts5/test/fts5onepass.test 7ed9608e258132cb8d55e7c479b08676ad68810c -F ext/fts5/test/fts5optimize.test 0f25ce4cc1f78a4cf5dd1247d30135b3f7180a19 +F ext/fts5/test/fts5optimize.test 9d3ac53bb9cae58cb070d795db86bcb2f9fec105 F ext/fts5/test/fts5phrase.test f6d1d464da5beb25dc56277aa4f1d6102f0d9a2f F ext/fts5/test/fts5plan.test 6a55ecbac9890765b0e16f8c421c7e0888cfe436 F ext/fts5/test/fts5porter.test 7cdc07bef301d70eebbfa75dcaf45c3680e1d0e1 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3c343c3d012367942037e64a9855b825cb459844 -R cc439e49a58b31085f4379adad06b3a4 -U drh -Z ed62054916964b4fe2af635a90038c7e +P f96ec84d605fd73c323344a753acf35b76307af9 +R 051c67540d0eafc760e9e2909fb96246 +U dan +Z d3ddde89c58a1d5ab316ef215efd6168 diff --git a/manifest.uuid b/manifest.uuid index 765f18c2cc..74d9440081 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f96ec84d605fd73c323344a753acf35b76307af9 \ No newline at end of file +fa0033edf6ddf3c6631fa95b343225dbc8ac9429 \ No newline at end of file From a0ca3bc854908494190f5a2d727e5269dbe48d3e Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 10 Mar 2016 19:08:44 +0000 Subject: [PATCH 35/57] Check for PDB files prior to attempting to copy them in the MSVC batch build tool. FossilOrigin-Name: d7c20f04e69fb1848b2e2f3b04fbd56e06c7c854 --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/build-all-msvc.bat | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 238a295d30..5ec513ed1c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sto\scover\suntested\sbranches\sin\srecent\sfts5\schanges. -D 2016-03-10T15:12:47.687 +C Check\sfor\sPDB\sfiles\sprior\sto\sattempting\sto\scopy\sthem\sin\sthe\sMSVC\sbatch\sbuild\stool. +D 2016-03-10T19:08:44.973 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -1374,7 +1374,7 @@ F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 629d87562e0487c386db630033931d12d62e6372 F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91 F tool/addopcodes.tcl 2b089684eb8b7d0db64cf9d8e6d2fe1b6d279e8d -F tool/build-all-msvc.bat 55be1cf8545dabd69df2ba6b3de6868da0c26f52 x +F tool/build-all-msvc.bat 3e4e4043b53f1aede4308e0d2567bbd773614630 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/cg_anno.tcl 692ce4b8693d59e3a3de77ca97f4139ecfa641b0 x F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f96ec84d605fd73c323344a753acf35b76307af9 -R 051c67540d0eafc760e9e2909fb96246 -U dan -Z d3ddde89c58a1d5ab316ef215efd6168 +P fa0033edf6ddf3c6631fa95b343225dbc8ac9429 +R 306b8c821d3092af90856b15d0070f67 +U mistachkin +Z c66ddc08ff47a327984a1b8fcbda8cec diff --git a/manifest.uuid b/manifest.uuid index 74d9440081..b9cc10f12d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa0033edf6ddf3c6631fa95b343225dbc8ac9429 \ No newline at end of file +d7c20f04e69fb1848b2e2f3b04fbd56e06c7c854 \ No newline at end of file diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index c96708cef5..ae8b76af5a 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -665,11 +665,13 @@ FOR %%P IN (%PLATFORMS%) DO ( REM are prevented from doing so. REM IF NOT DEFINED NOSYMBOLS ( - %__ECHO% XCOPY "%DLL_PDB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS% + IF EXIST "%DLL_PDB_FILE_NAME%" ( + %__ECHO% XCOPY "%DLL_PDB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS% - IF ERRORLEVEL 1 ( - ECHO Failed to copy "%DLL_PDB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\". - GOTO errors + IF ERRORLEVEL 1 ( + ECHO Failed to copy "%DLL_PDB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\". + GOTO errors + ) ) ) @@ -722,11 +724,13 @@ FOR %%P IN (%PLATFORMS%) DO ( REM unless we are prevented from doing so. REM IF NOT DEFINED NOSYMBOLS ( - %__ECHO% XCOPY "%EXE_PDB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS% + IF EXIST "%EXE_PDB_FILE_NAME%" ( + %__ECHO% XCOPY "%EXE_PDB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS% - IF ERRORLEVEL 1 ( - ECHO Failed to copy "%EXE_PDB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\". - GOTO errors + IF ERRORLEVEL 1 ( + ECHO Failed to copy "%EXE_PDB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\". + GOTO errors + ) ) ) ) From 811f17bac031aec31626304edb95313ba3a0217b Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 11 Mar 2016 14:30:18 +0000 Subject: [PATCH 36/57] Update spellfix1_scriptcode() to output 215 (latin) for pure numeric text. FossilOrigin-Name: df44308b862e932ff0ad25b6328d13be22047b96 --- ext/misc/spellfix.c | 10 ++++++++-- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/spellfix3.test | 11 ++++++++++- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index 5734d04f41..b5859ea2c8 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -1734,6 +1734,7 @@ static void scriptCodeSqlFunc( int c, sz; int scriptMask = 0; int res; + int seenDigit = 0; # define SCRIPT_LATIN 0x0001 # define SCRIPT_CYRILLIC 0x0002 # define SCRIPT_GREEK 0x0004 @@ -1744,8 +1745,12 @@ static void scriptCodeSqlFunc( c = utf8Read(zIn, nIn, &sz); zIn += sz; nIn -= sz; - if( c<0x02af && (c>=0x80 || midClass[c&0x7f]=0x80 || midClass[c&0x7f]='0' && c<='9' ){ + seenDigit = 1; + } }else if( c>=0x0400 && c<=0x04ff ){ scriptMask |= SCRIPT_CYRILLIC; }else if( c>=0x0386 && c<=0x03ce ){ @@ -1756,6 +1761,7 @@ static void scriptCodeSqlFunc( scriptMask |= SCRIPT_ARABIC; } } + if( scriptMask==0 && seenDigit ) scriptMask = SCRIPT_LATIN; switch( scriptMask ){ case 0: res = 999; break; case SCRIPT_LATIN: res = 215; break; diff --git a/manifest b/manifest index 5ec513ed1c..b0746bb445 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Check\sfor\sPDB\sfiles\sprior\sto\sattempting\sto\scopy\sthem\sin\sthe\sMSVC\sbatch\sbuild\stool. -D 2016-03-10T19:08:44.973 +C Update\sspellfix1_scriptcode()\sto\soutput\s215\s(latin)\sfor\spure\snumeric\stext. +D 2016-03-11T14:30:18.667 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -214,7 +214,7 @@ F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a F ext/misc/series.c e11e534ada797d5b816d7e7a93c022306563ca35 F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 -F ext/misc/spellfix.c 194b5fc3a9a63cb6c5680d8f713800012bddca7c +F ext/misc/spellfix.c 598bbc45516227701558becdd38f4e6fe8e97cc2 F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512 F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e @@ -1059,7 +1059,7 @@ F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b F test/speedtest1.c 1478cb3fb64ad30f291ddca87ca9dbd72ff552aa F test/spellfix.test f9c1f431e2c096c8775fec032952320c0e4700db F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 -F test/spellfix3.test f7bf7b3482971473d32b6b00f6944c5c066cff97 +F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test a74ee2a3740b9f9c2437c246d8fb77354862a142 F test/sqllog.test 6af6cb0b09f4e44e1917e06ce85be7670302517a @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fa0033edf6ddf3c6631fa95b343225dbc8ac9429 -R 306b8c821d3092af90856b15d0070f67 -U mistachkin -Z c66ddc08ff47a327984a1b8fcbda8cec +P d7c20f04e69fb1848b2e2f3b04fbd56e06c7c854 +R 6aa12144d3c644bf9edbd83316218d69 +U drh +Z c13ed9f7b14004f5942c430b85f3af01 diff --git a/manifest.uuid b/manifest.uuid index b9cc10f12d..12423c25d8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d7c20f04e69fb1848b2e2f3b04fbd56e06c7c854 \ No newline at end of file +df44308b862e932ff0ad25b6328d13be22047b96 \ No newline at end of file diff --git a/test/spellfix3.test b/test/spellfix3.test index ce002edd4f..e24ea31ee7 100644 --- a/test/spellfix3.test +++ b/test/spellfix3.test @@ -35,9 +35,18 @@ do_execsql_test 140 { } {160} do_execsql_test 200 { SELECT spellfix1_scriptcode('+3.14159'); -} {999} +} {215} do_execsql_test 210 { SELECT spellfix1_scriptcode('And God said: "Да будет свет"'); } {998} +do_execsql_test 220 { + SELECT spellfix1_scriptcode('+3.14159 light'); +} {215} +do_execsql_test 230 { + SELECT spellfix1_scriptcode('+3.14159 свет'); +} {220} +do_execsql_test 240 { + SELECT spellfix1_scriptcode('וַיֹּ֥אמֶר +3.14159'); +} {125} finish_test From e1f1ffa55acfad0770ee0a4828515decb658610b Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 11 Mar 2016 15:25:13 +0000 Subject: [PATCH 37/57] Tweak the amalgamation autoconf files so that the --disable-static-shell option works again. FossilOrigin-Name: 83efcdebfa255cd0663ecc6b74eb99183e2f3a10 --- autoconf/Makefile.am | 5 +++-- autoconf/configure.ac | 2 +- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/autoconf/Makefile.am b/autoconf/Makefile.am index 7b6934adde..cca23ba67d 100644 --- a/autoconf/Makefile.am +++ b/autoconf/Makefile.am @@ -6,8 +6,9 @@ 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) -DSQLITE_ENABLE_EXPLAIN_COMMENTS diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 9492530680..f86a39c37b 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -130,7 +130,7 @@ AC_ARG_ENABLE(static-shell, [AS_HELP_STRING( [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 + EXTRA_SHELL_OBJ=sqlite3-sqlite3.$OBJEXT else EXTRA_SHELL_OBJ=libsqlite3.la fi diff --git a/manifest b/manifest index b0746bb445..5e5214e2d2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sspellfix1_scriptcode()\sto\soutput\s215\s(latin)\sfor\spure\snumeric\stext. -D 2016-03-11T14:30:18.667 +C Tweak\sthe\samalgamation\sautoconf\sfiles\sso\sthat\sthe\s--disable-static-shell\soption\sworks\sagain. +D 2016-03-11T15:25:13.462 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -10,11 +10,11 @@ F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 -F autoconf/Makefile.am 4b8bd7896fffb6b22a57747f1f98cba1da9108ae +F autoconf/Makefile.am 42f7eb1fb2b06ddd6c6adab3e4388cc0a237ba40 F autoconf/Makefile.msc b8ada5177e6f39c126a88295af5ad0255e08d280 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt 4f04b0819303aabaa35fff5f7b257fb0c1ef95f1 -F autoconf/configure.ac 72a5e42beb090b32bca580285dc0ab3c4670adb8 +F autoconf/configure.ac d807b567f73a2b0986ccdd206b782cecb4d08fff F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d7c20f04e69fb1848b2e2f3b04fbd56e06c7c854 -R 6aa12144d3c644bf9edbd83316218d69 -U drh -Z c13ed9f7b14004f5942c430b85f3af01 +P df44308b862e932ff0ad25b6328d13be22047b96 +R 19b1fa38a58d00a667be85fd411c2202 +U dan +Z bd858a2f3f6240bb0acfbf97ee308bf8 diff --git a/manifest.uuid b/manifest.uuid index 12423c25d8..d06900f0e6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -df44308b862e932ff0ad25b6328d13be22047b96 \ No newline at end of file +83efcdebfa255cd0663ecc6b74eb99183e2f3a10 \ No newline at end of file From ffbb02a36169fddc4eec4dc156b1b23bb1c2744b Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 11 Mar 2016 23:07:30 +0000 Subject: [PATCH 38/57] Do not allow the use of WAL mode with nolock=1 because it does not work. FossilOrigin-Name: 74f5d3b07f6e5e977858c73957c6f9337ae3ca3e --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/pager.c | 1 + test/nolock.test | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 5e5214e2d2..eb0ce7dd6e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Tweak\sthe\samalgamation\sautoconf\sfiles\sso\sthat\sthe\s--disable-static-shell\soption\sworks\sagain. -D 2016-03-11T15:25:13.462 +C Do\snot\sallow\sthe\suse\sof\sWAL\smode\swith\snolock=1\sbecause\sit\sdoes\snot\swork. +D 2016-03-11T23:07:30.911 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -336,7 +336,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c f5bac8e74aaefc4ea520e43b4540793c3b8a9e8f F src/os_win.c f0d7aa603eb6262143d7169a222aea07c4fca91d F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca -F src/pager.c 2d950142528e5d9b291a1160443d7ade0d90700d +F src/pager.c 38718a019ca762ba4f6795425d5a54db70d1790d F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56 F src/parse.y 5ea8c81c5c41b27887f41b4a7e1c58470d7d3821 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df @@ -915,7 +915,7 @@ F test/multiplex4.test e8ae4c4bd70606a5727743241f13b5701990abe4 F test/mutex1.test e0a44072d98189003deae4b091106f085d94bea8 F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660 F test/nan.test e9648b9d007c7045242af35e11a984d4b169443a -F test/nolock.test 0540dd96f39b8876e3ffdd8814fad0ea425efeee +F test/nolock.test 96e922d2d3db71c2dd6557c98e8027a28277b415 F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161 F test/notify3.test 10ff25cde502e72a92053a2f215d64bece4ef934 @@ -1455,7 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P df44308b862e932ff0ad25b6328d13be22047b96 -R 19b1fa38a58d00a667be85fd411c2202 -U dan -Z bd858a2f3f6240bb0acfbf97ee308bf8 +P 83efcdebfa255cd0663ecc6b74eb99183e2f3a10 +R 95ba30529f9bfc1f4da2d6ab93334cdc +U drh +Z 5b477c118f77a96b5b851b408af856c1 diff --git a/manifest.uuid b/manifest.uuid index d06900f0e6..3b0b773e3e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -83efcdebfa255cd0663ecc6b74eb99183e2f3a10 \ No newline at end of file +74f5d3b07f6e5e977858c73957c6f9337ae3ca3e \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 316a5e8ec0..c18b3a32f7 100644 --- a/src/pager.c +++ b/src/pager.c @@ -7167,6 +7167,7 @@ int sqlite3PagerWalCallback(Pager *pPager){ */ int sqlite3PagerWalSupported(Pager *pPager){ const sqlite3_io_methods *pMethods = pPager->fd->pMethods; + if( pPager->noLock ) return 0; return pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap); } diff --git a/test/nolock.test b/test/nolock.test index 331af08ad7..fdaef6ef07 100644 --- a/test/nolock.test +++ b/test/nolock.test @@ -182,4 +182,36 @@ do_test nolock-3.12 { db2 close db close tvfs delete + +# 2016-03-11: Make sure all works when transitioning to WAL mode under nolock. +# +do_test nolock-4.1 { + forcedelete test.db + sqlite3 db file:test.db?nolock=1 -uri 1 + db eval { + PRAGMA journal_mode=WAL; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('youngling'); + SELECT * FROM t1; + } +} {delete youngling} +db close + +do_test nolock-4.2 { + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA journal_mode=WAL; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('catbird'); + SELECT * FROM t1; + } +} {wal catbird} +do_test nolock-4.3 { + db close + sqlite3 db file:test.db?nolock=1 -uri 1 + set rc [catch {db eval {SELECT * FROM t1}} msg] + lappend rc $msg +} {1 {unable to open database file}} + finish_test From e8c20120ce388253bcf5671b2aaf77348305272d Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 12 Mar 2016 16:32:16 +0000 Subject: [PATCH 39/57] Fix handling of strings that contain zero tokens in fts5. And other problems found by fuzzing. FossilOrigin-Name: 72b3ff0f0df83e62adda6584b4281cf086d45e45 --- ext/fts5/fts5Int.h | 6 ++ ext/fts5/fts5_config.c | 4 +- ext/fts5/fts5_expr.c | 150 ++++++++++++++++++++++++++--------- ext/fts5/fts5parse.y | 2 +- ext/fts5/test/fts5eb.test | 12 +-- ext/fts5/test/fts5fuzz1.test | 89 +++++++++++++++++++++ manifest | 23 +++--- manifest.uuid | 2 +- 8 files changed, 232 insertions(+), 56 deletions(-) create mode 100644 ext/fts5/test/fts5fuzz1.test diff --git a/ext/fts5/fts5Int.h b/ext/fts5/fts5Int.h index f9e1567fb6..35f15abbaf 100644 --- a/ext/fts5/fts5Int.h +++ b/ext/fts5/fts5Int.h @@ -701,6 +701,12 @@ Fts5ExprNode *sqlite3Fts5ParseNode( Fts5ExprNearset *pNear ); +Fts5ExprNode *sqlite3Fts5ParseImplicitAnd( + Fts5Parse *pParse, + Fts5ExprNode *pLeft, + Fts5ExprNode *pRight +); + Fts5ExprPhrase *sqlite3Fts5ParseTerm( Fts5Parse *pParse, Fts5ExprPhrase *pPhrase, diff --git a/ext/fts5/fts5_config.c b/ext/fts5/fts5_config.c index ccc154c3b4..17fc43e011 100644 --- a/ext/fts5/fts5_config.c +++ b/ext/fts5/fts5_config.c @@ -442,7 +442,9 @@ static const char *fts5ConfigGobbleWord( *pbQuoted = 1; }else{ zRet = fts5ConfigSkipBareword(zIn); - zOut[zRet-zIn] = '\0'; + if( zRet ){ + zOut[zRet-zIn] = '\0'; + } } } diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index d3f801b022..153d1c6472 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -1268,6 +1268,8 @@ static int fts5ExprNodeFirst(Fts5Expr *pExpr, Fts5ExprNode *pNode){ if( Fts5NodeIsString(pNode) ){ /* Initialize all term iterators in the NEAR object. */ rc = fts5ExprNearInitAll(pExpr, pNode); + }else if( pNode->xNext==0 ){ + pNode->bEof = 1; }else{ int i; int nEof = 0; @@ -1319,23 +1321,22 @@ static int fts5ExprNodeFirst(Fts5Expr *pExpr, Fts5ExprNode *pNode){ */ int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){ Fts5ExprNode *pRoot = p->pRoot; - int rc = SQLITE_OK; - if( pRoot->xNext ){ - p->pIndex = pIdx; - p->bDesc = bDesc; - rc = fts5ExprNodeFirst(p, pRoot); + int rc; /* Return code */ - /* If not at EOF but the current rowid occurs earlier than iFirst in - ** the iteration order, move to document iFirst or later. */ - if( pRoot->bEof==0 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0 ){ - rc = fts5ExprNodeNext(p, pRoot, 1, iFirst); - } + p->pIndex = pIdx; + p->bDesc = bDesc; + rc = fts5ExprNodeFirst(p, pRoot); - /* If the iterator is not at a real match, skip forward until it is. */ - while( pRoot->bNomatch ){ - assert( pRoot->bEof==0 && rc==SQLITE_OK ); - rc = fts5ExprNodeNext(p, pRoot, 0, 0); - } + /* If not at EOF but the current rowid occurs earlier than iFirst in + ** the iteration order, move to document iFirst or later. */ + if( pRoot->bEof==0 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0 ){ + rc = fts5ExprNodeNext(p, pRoot, 1, iFirst); + } + + /* If the iterator is not at a real match, skip forward until it is. */ + while( pRoot->bNomatch ){ + assert( pRoot->bEof==0 && rc==SQLITE_OK ); + rc = fts5ExprNodeNext(p, pRoot, 0, 0); } return rc; } @@ -1476,8 +1477,7 @@ static int fts5ParseTokenize( /* If an error has already occurred, this is a no-op */ if( pCtx->rc!=SQLITE_OK ) return pCtx->rc; - assert( pPhrase==0 || pPhrase->nTerm>0 ); - if( pPhrase && (tflags & FTS5_TOKEN_COLOCATED) ){ + if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){ Fts5ExprTerm *pSyn; int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1; pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte); @@ -1578,7 +1578,7 @@ Fts5ExprPhrase *sqlite3Fts5ParseTerm( pParse->rc = rc; fts5ExprPhraseFree(sCtx.pPhrase); sCtx.pPhrase = 0; - }else if( sCtx.pPhrase ){ + }else{ if( pAppend==0 ){ if( (pParse->nPhrase % 8)==0 ){ @@ -1595,9 +1595,14 @@ Fts5ExprPhrase *sqlite3Fts5ParseTerm( pParse->nPhrase++; } + if( sCtx.pPhrase==0 ){ + /* This happens when parsing a token or quoted phrase that contains + ** no token characters at all. (e.g ... MATCH '""'). */ + sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase)); + }else if( sCtx.pPhrase->nTerm ){ + sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = bPrefix; + } pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase; - assert( sCtx.pPhrase->nTerm>0 ); - sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = bPrefix; } return sCtx.pPhrase; @@ -1693,23 +1698,25 @@ void sqlite3Fts5ParseSetDistance( Fts5ExprNearset *pNear, Fts5Token *p ){ - int nNear = 0; - int i; - if( p->n ){ - for(i=0; in; i++){ - char c = (char)p->p[i]; - if( c<'0' || c>'9' ){ - sqlite3Fts5ParseError( - pParse, "expected integer, got \"%.*s\"", p->n, p->p - ); - return; + if( pNear ){ + int nNear = 0; + int i; + if( p->n ){ + for(i=0; in; i++){ + char c = (char)p->p[i]; + if( c<'0' || c>'9' ){ + sqlite3Fts5ParseError( + pParse, "expected integer, got \"%.*s\"", p->n, p->p + ); + return; + } + nNear = nNear * 10 + (p->p[i] - '0'); } - nNear = nNear * 10 + (p->p[i] - '0'); + }else{ + nNear = FTS5_DEFAULT_NEARDIST; } - }else{ - nNear = FTS5_DEFAULT_NEARDIST; + pNear->nNear = nNear; } - pNear->nNear = nNear; } /* @@ -1896,10 +1903,14 @@ Fts5ExprNode *sqlite3Fts5ParseNode( int iPhrase; for(iPhrase=0; iPhrasenPhrase; iPhrase++){ pNear->apPhrase[iPhrase]->pNode = pRet; + if( pNear->apPhrase[iPhrase]->nTerm==0 ){ + pRet->xNext = 0; + pRet->eType = FTS5_EOF; + } } if( pParse->pConfig->eDetail!=FTS5_DETAIL_FULL - && (pNear->nPhrase!=1 || pNear->apPhrase[0]->nTerm!=1) + && (pNear->nPhrase!=1 || pNear->apPhrase[0]->nTerm>1) ){ assert( pParse->rc==SQLITE_OK ); pParse->rc = SQLITE_ERROR; @@ -1928,6 +1939,70 @@ Fts5ExprNode *sqlite3Fts5ParseNode( return pRet; } +Fts5ExprNode *sqlite3Fts5ParseImplicitAnd( + Fts5Parse *pParse, /* Parse context */ + Fts5ExprNode *pLeft, /* Left hand child expression */ + Fts5ExprNode *pRight /* Right hand child expression */ +){ + Fts5ExprNode *pRet = 0; + Fts5ExprNode *pPrev; + + if( pParse->rc ){ + sqlite3Fts5ParseNodeFree(pLeft); + sqlite3Fts5ParseNodeFree(pRight); + }else{ + + assert( pLeft->eType==FTS5_STRING + || pLeft->eType==FTS5_TERM + || pLeft->eType==FTS5_EOF + || pLeft->eType==FTS5_AND + ); + assert( pRight->eType==FTS5_STRING + || pRight->eType==FTS5_TERM + || pRight->eType==FTS5_EOF + ); + + if( pLeft->eType==FTS5_AND ){ + pPrev = pLeft->apChild[pLeft->nChild-1]; + }else{ + pPrev = pLeft; + } + assert( pPrev->eType==FTS5_STRING + || pPrev->eType==FTS5_TERM + || pPrev->eType==FTS5_EOF + ); + + if( pRight->eType==FTS5_EOF ){ + assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] ); + sqlite3Fts5ParseNodeFree(pRight); + pRet = pLeft; + pParse->nPhrase--; + } + else if( pPrev->eType==FTS5_EOF ){ + Fts5ExprPhrase **ap; + + if( pPrev==pLeft ){ + pRet = pRight; + }else{ + pLeft->apChild[pLeft->nChild-1] = pRight; + pRet = pLeft; + } + + ap = &pParse->apPhrase[pParse->nPhrase-1-pRight->pNear->nPhrase]; + assert( ap[0]==pPrev->pNear->apPhrase[0] ); + memmove(ap, &ap[1], sizeof(Fts5ExprPhrase*)*pRight->pNear->nPhrase); + pParse->nPhrase--; + + sqlite3Fts5ParseNodeFree(pPrev); + } + else{ + pRet = sqlite3Fts5ParseNode(pParse, FTS5_AND, pLeft, pRight, 0); + } + } + + return pRet; +} + static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){ int nByte = 0; Fts5ExprTerm *p; @@ -2062,6 +2137,9 @@ static char *fts5ExprPrintTcl( static char *fts5ExprPrint(Fts5Config *pConfig, Fts5ExprNode *pExpr){ char *zRet = 0; + if( pExpr->eType==0 ){ + return sqlite3_mprintf("\"\""); + }else if( pExpr->eType==FTS5_STRING || pExpr->eType==FTS5_TERM ){ Fts5ExprNearset *pNear = pExpr->pNear; int i; @@ -2122,7 +2200,7 @@ static char *fts5ExprPrint(Fts5Config *pConfig, Fts5ExprNode *pExpr){ zRet = 0; }else{ int e = pExpr->apChild[i]->eType; - int b = (e!=FTS5_STRING && e!=FTS5_TERM); + int b = (e!=FTS5_STRING && e!=FTS5_TERM && e!=FTS5_EOF); zRet = fts5PrintfAppend(zRet, "%s%s%z%s", (i==0 ? "" : zOp), (b?"(":""), z, (b?")":"") diff --git a/ext/fts5/fts5parse.y b/ext/fts5/fts5parse.y index 2bdf4b09b2..1607d3846a 100644 --- a/ext/fts5/fts5parse.y +++ b/ext/fts5/fts5parse.y @@ -104,7 +104,7 @@ expr(A) ::= exprlist(X). {A = X;} exprlist(A) ::= cnearset(X). {A = X;} exprlist(A) ::= exprlist(X) cnearset(Y). { - A = sqlite3Fts5ParseNode(pParse, FTS5_AND, X, Y, 0); + A = sqlite3Fts5ParseImplicitAnd(pParse, X, Y); } cnearset(A) ::= nearset(X). { diff --git a/ext/fts5/test/fts5eb.test b/ext/fts5/test/fts5eb.test index 8205396047..69418aae63 100644 --- a/ext/fts5/test/fts5eb.test +++ b/ext/fts5/test/fts5eb.test @@ -33,12 +33,12 @@ foreach {tn expr res} { 1 {abc} {"abc"} 2 {abc ""} {"abc"} 3 {""} {} - 4 {abc OR ""} {"abc"} - 5 {abc NOT ""} {"abc"} - 6 {abc AND ""} {"abc"} - 7 {"" OR abc} {"abc"} - 8 {"" NOT abc} {"abc"} - 9 {"" AND abc} {"abc"} + 4 {abc OR ""} {"abc" OR ""} + 5 {abc NOT ""} {"abc" NOT ""} + 6 {abc AND ""} {"abc" AND ""} + 7 {"" OR abc} {"" OR "abc"} + 8 {"" NOT abc} {"" NOT "abc"} + 9 {"" AND abc} {"" AND "abc"} 10 {abc + "" + def} {"abc" + "def"} 11 {abc "" def} {"abc" AND "def"} 12 {r+e OR w} {"r" + "e" OR "w"} diff --git a/ext/fts5/test/fts5fuzz1.test b/ext/fts5/test/fts5fuzz1.test new file mode 100644 index 0000000000..638620d025 --- /dev/null +++ b/ext/fts5/test/fts5fuzz1.test @@ -0,0 +1,89 @@ +# 2014 June 17 +# +# 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 script is testing the FTS5 module. +# + +source [file join [file dirname [info script]] fts5_common.tcl] +return_if_no_fts5 +set testprefix fts5fuzz1 + + +#------------------------------------------------------------------------- +reset_db +do_catchsql_test 1.1 { + CREATE VIRTUAL TABLE f1 USING fts5(a b); +} {/1 {parse error in.*}/} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.1 { + CREATE VIRTUAL TABLE f1 USING fts5(a, b); + INSERT INTO f1 VALUES('a b', 'c d'); + INSERT INTO f1 VALUES('e f', 'a b'); +} + +do_execsql_test 2.2.1 { + SELECT rowid FROM f1('""'); +} {} + +do_execsql_test 2.2.2 { + SELECT rowid FROM f1('"" AND a'); +} {} + + +do_execsql_test 2.2.3 { + SELECT rowid FROM f1('"" a'); +} {1 2} + +do_execsql_test 2.2.4 { + SELECT rowid FROM f1('"" OR a'); +} {1 2} + +do_execsql_test 2.3 { + SELECT a, b FROM f1('NEAR("")'); +} {} + +do_execsql_test 2.4 { + SELECT a, b FROM f1('NEAR("", 5)'); +} {} + +do_execsql_test 2.5 { + SELECT a, b FROM f1('NEAR("" c, 5)'); +} {} + +do_execsql_test 2.6 { + SELECT a, b FROM f1('NEAR("" c d, 5)'); +} {} + +do_execsql_test 2.7 { + SELECT a, b FROM f1('NEAR(c d, 5)'); +} {{a b} {c d}} + +do_execsql_test 2.8 { + SELECT rowid FROM f1('NEAR("a" "b", 5)'); +} {1 2} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.2 { + CREATE VIRTUAL TABLE f2 USING fts5(o, t, tokenize="ascii separators abc"); + SELECT * FROM f2('a+4'); +} {} + + + + + +finish_test + + diff --git a/manifest b/manifest index eb0ce7dd6e..b9bfda53ca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallow\sthe\suse\sof\sWAL\smode\swith\snolock=1\sbecause\sit\sdoes\snot\swork. -D 2016-03-11T23:07:30.911 +C Fix\shandling\sof\sstrings\sthat\scontain\szero\stokens\sin\sfts5.\sAnd\sother\sproblems\sfound\sby\sfuzzing. +D 2016-03-12T16:32:16.002 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -98,11 +98,11 @@ F ext/fts3/unicode/mkunicode.tcl 2debed3f582d77b3fdd0b8830880250021571fd8 F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/fts5.h ff9c2782e8ed890b0de2f697a8d63971939e70c7 -F ext/fts5/fts5Int.h 59e13423371512df1992532a08fe80518244f96b +F ext/fts5/fts5Int.h 4060504b7979601d99e1385c2b5713036854979a F ext/fts5/fts5_aux.c daa57fb45216491814520bbb587e97bf81ced458 F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd -F ext/fts5/fts5_config.c abd3ae1107ca8b8def7445a0a3b70c2e46d05986 -F ext/fts5/fts5_expr.c 8e8e4635f655133eb39018072fc0f0942a2c4337 +F ext/fts5/fts5_config.c 5af9c360e99669d29f06492c370892394aba0857 +F ext/fts5/fts5_expr.c c4166ba0de2e87c444a7eedc8623e32653138ca0 F ext/fts5/fts5_hash.c f3a7217c86eb8f272871be5f6aa1b6798960a337 F ext/fts5/fts5_index.c d4f0c12e4f04bbc3a06b6da052039f2ce3e45438 F ext/fts5/fts5_main.c b8501e1a6a11591c53b18ce7aea7e5386cfb0421 @@ -114,7 +114,7 @@ F ext/fts5/fts5_tokenize.c 2ce7b44183538ec46b7907726262ee43ffdd39a8 F ext/fts5/fts5_unicode2.c b450b209b157d598f7b9df9f837afb75a14c24bf F ext/fts5/fts5_varint.c a5aceacda04dafcbae725413d7a16818ecd65738 F ext/fts5/fts5_vocab.c dba72ca393d71c2588548b51380387f6b44c77a8 -F ext/fts5/fts5parse.y 86fe6ba094a47e02fe8be2571539e6833d197764 +F ext/fts5/fts5parse.y fcc5e92e570d38cab38488b2109cbf67468923b2 F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba F ext/fts5/test/fts5_common.tcl b01c584144b5064f30e6c648145a2dd6bc440841 F ext/fts5/test/fts5aa.test 7e814df4a0e6c22a6fe2d84f210fdc0b5068a084 @@ -146,7 +146,7 @@ F ext/fts5/test/fts5detail.test ef5c690535a797413acaf5ad9b8ab5d49972df69 F ext/fts5/test/fts5dlidx.test 13871a14641017ae42f6f1055a8067bafd44cb3d F ext/fts5/test/fts5doclist.test 8edb5b57e5f144030ed74ec00ef6fa4294fed79b F ext/fts5/test/fts5ea.test b01e3a18cdfabbff8104a96a5242a06a68a998a0 -F ext/fts5/test/fts5eb.test 021aa80b7ac09b964249aa32ced9ee908703e4aa +F ext/fts5/test/fts5eb.test c516ae0c934be6fd29ec95ea8b5f11f461311535 F ext/fts5/test/fts5fault1.test e09040d3e17b8c0837101e8c79c8a874c4376fb7 F ext/fts5/test/fts5fault2.test d8c6c7f916ccbdfc10b2c69530e9dd3bc8313232 F ext/fts5/test/fts5fault3.test d6e9577d4312e331a913c72931bf131704efc8f3 @@ -159,6 +159,7 @@ F ext/fts5/test/fts5fault9.test e10e395428a9ea0596ebe752ff7123d16ab78e08 F ext/fts5/test/fts5faultA.test fa5d59c0ff62b7125cd14eee38ded1c46e15a7ea F ext/fts5/test/fts5faultB.test 92ae906284062bf081b6c854afa54dcb1aa9ef88 F ext/fts5/test/fts5full.test 6f6143af0c6700501d9fd597189dfab1555bb741 +F ext/fts5/test/fts5fuzz1.test 7a6411c39959d8f4cb8f11e840a787e74a3bfbef F ext/fts5/test/fts5hash.test 06f9309ccb4d5050a131594e9e47d0b21456837d F ext/fts5/test/fts5integrity.test f5e4f8d284385875068ad0f3e894ce43e9de835d F ext/fts5/test/fts5matchinfo.test f7dde99697bcb310ea8faa8eb2714d9f4dfc0e1b @@ -1455,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 83efcdebfa255cd0663ecc6b74eb99183e2f3a10 -R 95ba30529f9bfc1f4da2d6ab93334cdc -U drh -Z 5b477c118f77a96b5b851b408af856c1 +P 74f5d3b07f6e5e977858c73957c6f9337ae3ca3e +R 561f4a7c15c16c270cfb03e11b79c482 +U dan +Z 78cc445fb6679cc3e05486871c5dafe8 diff --git a/manifest.uuid b/manifest.uuid index 3b0b773e3e..00db2d08b1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74f5d3b07f6e5e977858c73957c6f9337ae3ca3e \ No newline at end of file +72b3ff0f0df83e62adda6584b4281cf086d45e45 \ No newline at end of file From 5cf98f101e1a475ed4572d405edf56c5244162d4 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 12 Mar 2016 19:33:47 +0000 Subject: [PATCH 40/57] Fix a problem handling 'NEAR("" token)' in fts5 found by fuzzing. FossilOrigin-Name: 10a827ae5f3f322af836c15e581fdc958a433a5a --- ext/fts5/fts5_expr.c | 15 +++++++++++++++ ext/fts5/test/fts5fuzz1.test | 4 ++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index 153d1c6472..26ee3f9472 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -1445,6 +1445,21 @@ Fts5ExprNearset *sqlite3Fts5ParseNearset( sqlite3Fts5ParseNearsetFree(pNear); sqlite3Fts5ParsePhraseFree(pPhrase); }else{ + if( pRet->nPhrase>0 ){ + Fts5ExprPhrase *pLast = pRet->apPhrase[pRet->nPhrase-1]; + assert( pLast==pParse->apPhrase[pParse->nPhrase-2] ); + if( pPhrase->nTerm==0 ){ + fts5ExprPhraseFree(pPhrase); + pRet->nPhrase--; + pParse->nPhrase--; + pPhrase = pLast; + }else if( pLast->nTerm==0 ){ + fts5ExprPhraseFree(pLast); + pParse->apPhrase[pParse->nPhrase-2] = pPhrase; + pParse->nPhrase--; + pRet->nPhrase--; + } + } pRet->apPhrase[pRet->nPhrase++] = pPhrase; } return pRet; diff --git a/ext/fts5/test/fts5fuzz1.test b/ext/fts5/test/fts5fuzz1.test index 638620d025..326229181d 100644 --- a/ext/fts5/test/fts5fuzz1.test +++ b/ext/fts5/test/fts5fuzz1.test @@ -59,11 +59,11 @@ do_execsql_test 2.4 { do_execsql_test 2.5 { SELECT a, b FROM f1('NEAR("" c, 5)'); -} {} +} {{a b} {c d}} do_execsql_test 2.6 { SELECT a, b FROM f1('NEAR("" c d, 5)'); -} {} +} {{a b} {c d}} do_execsql_test 2.7 { SELECT a, b FROM f1('NEAR(c d, 5)'); diff --git a/manifest b/manifest index b9bfda53ca..4616625054 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\shandling\sof\sstrings\sthat\scontain\szero\stokens\sin\sfts5.\sAnd\sother\sproblems\sfound\sby\sfuzzing. -D 2016-03-12T16:32:16.002 +C Fix\sa\sproblem\shandling\s'NEAR(""\stoken)'\sin\sfts5\sfound\sby\sfuzzing. +D 2016-03-12T19:33:47.637 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -102,7 +102,7 @@ F ext/fts5/fts5Int.h 4060504b7979601d99e1385c2b5713036854979a F ext/fts5/fts5_aux.c daa57fb45216491814520bbb587e97bf81ced458 F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd F ext/fts5/fts5_config.c 5af9c360e99669d29f06492c370892394aba0857 -F ext/fts5/fts5_expr.c c4166ba0de2e87c444a7eedc8623e32653138ca0 +F ext/fts5/fts5_expr.c f11757a251346df38c04fd67d0703fbb0c084ef7 F ext/fts5/fts5_hash.c f3a7217c86eb8f272871be5f6aa1b6798960a337 F ext/fts5/fts5_index.c d4f0c12e4f04bbc3a06b6da052039f2ce3e45438 F ext/fts5/fts5_main.c b8501e1a6a11591c53b18ce7aea7e5386cfb0421 @@ -159,7 +159,7 @@ F ext/fts5/test/fts5fault9.test e10e395428a9ea0596ebe752ff7123d16ab78e08 F ext/fts5/test/fts5faultA.test fa5d59c0ff62b7125cd14eee38ded1c46e15a7ea F ext/fts5/test/fts5faultB.test 92ae906284062bf081b6c854afa54dcb1aa9ef88 F ext/fts5/test/fts5full.test 6f6143af0c6700501d9fd597189dfab1555bb741 -F ext/fts5/test/fts5fuzz1.test 7a6411c39959d8f4cb8f11e840a787e74a3bfbef +F ext/fts5/test/fts5fuzz1.test 74b638ca214b91614cadb2de14e6269385819e99 F ext/fts5/test/fts5hash.test 06f9309ccb4d5050a131594e9e47d0b21456837d F ext/fts5/test/fts5integrity.test f5e4f8d284385875068ad0f3e894ce43e9de835d F ext/fts5/test/fts5matchinfo.test f7dde99697bcb310ea8faa8eb2714d9f4dfc0e1b @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 74f5d3b07f6e5e977858c73957c6f9337ae3ca3e -R 561f4a7c15c16c270cfb03e11b79c482 +P 72b3ff0f0df83e62adda6584b4281cf086d45e45 +R f6701c1b7c325b06b9e793bf0b9b6f39 U dan -Z 78cc445fb6679cc3e05486871c5dafe8 +Z ac91e536ca766cb3c7d727597fcc6975 diff --git a/manifest.uuid b/manifest.uuid index 00db2d08b1..c16d8c43cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72b3ff0f0df83e62adda6584b4281cf086d45e45 \ No newline at end of file +10a827ae5f3f322af836c15e581fdc958a433a5a \ No newline at end of file From 7d85774da81c3352df1a53ff3634e96b0403a6af Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 14 Mar 2016 12:16:23 +0000 Subject: [PATCH 41/57] Fix a memory leak in fts5 that could occur following a syntax error in a query expression. FossilOrigin-Name: 54b8968e335760105206b894672213c1d56771a4 --- ext/fts5/fts5_expr.c | 2 ++ ext/fts5/test/fts5fuzz1.test | 8 ++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index 26ee3f9472..1e9be8117d 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -258,6 +258,8 @@ int sqlite3Fts5ExprNew( pNew->nPhrase = sParse.nPhrase; sParse.apPhrase = 0; } + }else{ + sqlite3Fts5ParseNodeFree(sParse.pExpr); } sqlite3_free(sParse.apPhrase); diff --git a/ext/fts5/test/fts5fuzz1.test b/ext/fts5/test/fts5fuzz1.test index 326229181d..599d7bcc89 100644 --- a/ext/fts5/test/fts5fuzz1.test +++ b/ext/fts5/test/fts5fuzz1.test @@ -82,8 +82,12 @@ do_execsql_test 3.2 { - +#------------------------------------------------------------------------- +reset_db +do_catchsql_test 4.1 { + CREATE VIRTUAL TABLE f2 USING fts5(o, t); + SELECT * FROM f2('(8 AND 9)`AND 10'); +} {1 {fts5: syntax error near "`"}} finish_test - diff --git a/manifest b/manifest index 4616625054..437c838595 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\shandling\s'NEAR(""\stoken)'\sin\sfts5\sfound\sby\sfuzzing. -D 2016-03-12T19:33:47.637 +C Fix\sa\smemory\sleak\sin\sfts5\sthat\scould\soccur\sfollowing\sa\ssyntax\serror\sin\sa\squery\sexpression. +D 2016-03-14T12:16:23.063 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -102,7 +102,7 @@ F ext/fts5/fts5Int.h 4060504b7979601d99e1385c2b5713036854979a F ext/fts5/fts5_aux.c daa57fb45216491814520bbb587e97bf81ced458 F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd F ext/fts5/fts5_config.c 5af9c360e99669d29f06492c370892394aba0857 -F ext/fts5/fts5_expr.c f11757a251346df38c04fd67d0703fbb0c084ef7 +F ext/fts5/fts5_expr.c be309fb227003c931107bfcc12d5be4f2fd2bb8c F ext/fts5/fts5_hash.c f3a7217c86eb8f272871be5f6aa1b6798960a337 F ext/fts5/fts5_index.c d4f0c12e4f04bbc3a06b6da052039f2ce3e45438 F ext/fts5/fts5_main.c b8501e1a6a11591c53b18ce7aea7e5386cfb0421 @@ -159,7 +159,7 @@ F ext/fts5/test/fts5fault9.test e10e395428a9ea0596ebe752ff7123d16ab78e08 F ext/fts5/test/fts5faultA.test fa5d59c0ff62b7125cd14eee38ded1c46e15a7ea F ext/fts5/test/fts5faultB.test 92ae906284062bf081b6c854afa54dcb1aa9ef88 F ext/fts5/test/fts5full.test 6f6143af0c6700501d9fd597189dfab1555bb741 -F ext/fts5/test/fts5fuzz1.test 74b638ca214b91614cadb2de14e6269385819e99 +F ext/fts5/test/fts5fuzz1.test bece4695fc169b61ab236ada7931c6e4942cbef9 F ext/fts5/test/fts5hash.test 06f9309ccb4d5050a131594e9e47d0b21456837d F ext/fts5/test/fts5integrity.test f5e4f8d284385875068ad0f3e894ce43e9de835d F ext/fts5/test/fts5matchinfo.test f7dde99697bcb310ea8faa8eb2714d9f4dfc0e1b @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 72b3ff0f0df83e62adda6584b4281cf086d45e45 -R f6701c1b7c325b06b9e793bf0b9b6f39 +P 10a827ae5f3f322af836c15e581fdc958a433a5a +R 044bc4807e350ab5b23a4e059317d425 U dan -Z ac91e536ca766cb3c7d727597fcc6975 +Z 7cd8dbc9719c56da8d0f172ae33ba6b2 diff --git a/manifest.uuid b/manifest.uuid index c16d8c43cd..d8fc8d0201 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -10a827ae5f3f322af836c15e581fdc958a433a5a \ No newline at end of file +54b8968e335760105206b894672213c1d56771a4 \ No newline at end of file From d5704a8961a237d07ad8c58ec550e439bf7e9ca9 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 13:42:29 +0000 Subject: [PATCH 42/57] Run TCL tests in a subdirectory "testdir". FossilOrigin-Name: f632bba0d6ad3edc60f4127380ce8320378dac42 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/analyzer1.test | 9 ++++++--- test/tester.tcl | 13 ++++++++++++- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 437c838595..be4618cf04 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sleak\sin\sfts5\sthat\scould\soccur\sfollowing\sa\ssyntax\serror\sin\sa\squery\sexpression. -D 2016-03-14T12:16:23.063 +C Run\sTCL\stests\sin\sa\ssubdirectory\s"testdir". +D 2016-03-14T13:42:29.333 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -460,7 +460,7 @@ F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93 F test/analyzeD.test 42af58de25a6436502e43006e9e59e2d71bcb0cf F test/analyzeE.test 8684e8ac5722fb97c251887ad97e5d496a98af1d F test/analyzeF.test 5d1fe1024ba2dfea3c18bede8c1ccef8aba1ab34 -F test/analyzer1.test 498e2ff4b62740c2751c3a2f8b744fe26689fae9 +F test/analyzer1.test 459fa02c445ddbf0101a3bad47b34290a35f2e49 F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 @@ -1085,7 +1085,7 @@ F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl 750365ff97047ded5f2d6e28df82a998f7c66ae0 +F test/tester.tcl 5e4888b6bfa9862716531c085a7d450d80427884 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 10a827ae5f3f322af836c15e581fdc958a433a5a -R 044bc4807e350ab5b23a4e059317d425 -U dan -Z 7cd8dbc9719c56da8d0f172ae33ba6b2 +P 54b8968e335760105206b894672213c1d56771a4 +R 51c96c83fefb55fe62e20e36b1c079f2 +U drh +Z ad4f0a6837143665327a52812ce6dad2 diff --git a/manifest.uuid b/manifest.uuid index d8fc8d0201..837a8076f0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -54b8968e335760105206b894672213c1d56771a4 \ No newline at end of file +f632bba0d6ad3edc60f4127380ce8320378dac42 \ No newline at end of file diff --git a/test/analyzer1.test b/test/analyzer1.test index ac46704fba..51b5f8b6af 100644 --- a/test/analyzer1.test +++ b/test/analyzer1.test @@ -25,9 +25,12 @@ if {$tcl_platform(platform)=="windows"} { set PROG "./sqlite3_analyzer" } if {![file exe $PROG]} { - puts "analyzer1 cannot run because $PROG is not available" - finish_test - return + set PROG [file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $PROG]] + if {![file exe $PROG]} { + puts "analyzer1 cannot run because $PROG is not available" + finish_test + return + } } db close forcedelete test.db test.db-journal test.db-wal diff --git a/test/tester.tcl b/test/tester.tcl index 231cef5333..e8d41fd4a2 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -411,6 +411,8 @@ if {[info exists cmdlinearg]==0} { # --match=$pattern # --verbose=$val # --output=$filename + # -q Reduce output + # --testdir=$dir Run tests in subdirectory $dir # --help # set cmdlinearg(soft-heap-limit) 0 @@ -425,6 +427,7 @@ if {[info exists cmdlinearg]==0} { set cmdlinearg(match) "" set cmdlinearg(verbose) "" set cmdlinearg(output) "" + set cmdlinearg(testdir) "testdir" set leftover [list] foreach a $argv { @@ -498,6 +501,9 @@ if {[info exists cmdlinearg]==0} { error "option --verbose= must be set to a boolean or to \"file\"" } } + {^-+testdir=.*$} { + foreach {dummy cmdlinearg(testdir)} [split $a =] break + } {.*help.*} { print_help_and_quit } @@ -507,10 +513,15 @@ if {[info exists cmdlinearg]==0} { } default { - lappend leftover $a + lappend leftover [file normalize $a] } } } + set cmdlinearg(TESTFIXTURE_HOME) [pwd] + if {$cmdlinearg(testdir)!=""} { + file mkdir $cmdlinearg(testdir) + cd $cmdlinearg(testdir) + } set argv $leftover # Install the malloc layer used to inject OOM errors. And the 'automatic' From bea14132cf8f814e52de30676f098c94a50c49b9 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 14:28:43 +0000 Subject: [PATCH 43/57] Normalize the $testdir and $argv0 paths so that they continue to work in the testing subdirectory. FossilOrigin-Name: 19225b8130f1640772fc54250583b571a89063b6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/tester.tcl | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index be4618cf04..8f5aa6a6b2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Run\sTCL\stests\sin\sa\ssubdirectory\s"testdir". -D 2016-03-14T13:42:29.333 +C Normalize\sthe\s$testdir\sand\s$argv0\spaths\sso\sthat\sthey\scontinue\sto\swork\nin\sthe\stesting\ssubdirectory. +D 2016-03-14T14:28:43.708 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -1085,7 +1085,7 @@ F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl 5e4888b6bfa9862716531c085a7d450d80427884 +F test/tester.tcl 91d34b1d829a25b63ad79160fafce8d626f433ef F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 54b8968e335760105206b894672213c1d56771a4 -R 51c96c83fefb55fe62e20e36b1c079f2 +P f632bba0d6ad3edc60f4127380ce8320378dac42 +R 22b406abedcbf80fe60cfc67f5d3bedf U drh -Z ad4f0a6837143665327a52812ce6dad2 +Z 43e678777243a6003b283ca0fdf3c95b diff --git a/manifest.uuid b/manifest.uuid index 837a8076f0..63fbc091c0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f632bba0d6ad3edc60f4127380ce8320378dac42 \ No newline at end of file +19225b8130f1640772fc54250583b571a89063b6 \ No newline at end of file diff --git a/test/tester.tcl b/test/tester.tcl index e8d41fd4a2..d8b37579a6 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -517,7 +517,9 @@ if {[info exists cmdlinearg]==0} { } } } + set testdir [file normalize $testdir] set cmdlinearg(TESTFIXTURE_HOME) [pwd] + set argv0 [file normalize $argv0] if {$cmdlinearg(testdir)!=""} { file mkdir $cmdlinearg(testdir) cd $cmdlinearg(testdir) From e500f65a2c4b1d5df8053c33bc697721cf7733f3 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 14:59:35 +0000 Subject: [PATCH 44/57] More file pathname normalization. FossilOrigin-Name: fa8c12921f8361f1889724bb7c5f7eca9c48b075 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/tester.tcl | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 8f5aa6a6b2..5c365e1771 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Normalize\sthe\s$testdir\sand\s$argv0\spaths\sso\sthat\sthey\scontinue\sto\swork\nin\sthe\stesting\ssubdirectory. -D 2016-03-14T14:28:43.708 +C More\sfile\spathname\snormalization. +D 2016-03-14T14:59:35.248 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -1085,7 +1085,7 @@ F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl 91d34b1d829a25b63ad79160fafce8d626f433ef +F test/tester.tcl 8fbf071b23ec66ce9bb8607fc92fdc4326393697 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f632bba0d6ad3edc60f4127380ce8320378dac42 -R 22b406abedcbf80fe60cfc67f5d3bedf +P 19225b8130f1640772fc54250583b571a89063b6 +R e6d4ff0cfaea5c603741eca2f2c0aea1 U drh -Z 43e678777243a6003b283ca0fdf3c95b +Z f2a7315c22032835cedc7ee778272809 diff --git a/manifest.uuid b/manifest.uuid index 63fbc091c0..4c4029ef69 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -19225b8130f1640772fc54250583b571a89063b6 \ No newline at end of file +fa8c12921f8361f1889724bb7c5f7eca9c48b075 \ No newline at end of file diff --git a/test/tester.tcl b/test/tester.tcl index d8b37579a6..6dc507f70e 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -457,6 +457,7 @@ if {[info exists cmdlinearg]==0} { } {^-+binarylog=.+$} { foreach {dummy cmdlinearg(binarylog)} [split $a =] break + set cmdlinearg(binarylog) [file normalize $cmdlinearg(binarylog)] } {^-+soak=.+$} { foreach {dummy cmdlinearg(soak)} [split $a =] break @@ -489,6 +490,7 @@ if {[info exists cmdlinearg]==0} { {^-+output=.+$} { foreach {dummy cmdlinearg(output)} [split $a =] break + set cmdlinearg(output) [file normalize $cmdlinearg(output)] if {$cmdlinearg(verbose)==""} { set cmdlinearg(verbose) 2 } From de503eb166ce4c0f4a392ce2084e1de2741f6d61 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 14 Mar 2016 15:43:03 +0000 Subject: [PATCH 45/57] Fix the backcompat.test script so that it works with the --testdir test option. FossilOrigin-Name: f7480e33eb82f2eae219d17ce46cd2d4edac07d2 --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- test/backcompat.test | 3 ++- test/bc_common.tcl | 5 +++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 8cf8ea024d..73224a31d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Run\sTCL\stests\sin\sthe\s"testdir"\ssubdirectory. -D 2016-03-14T15:03:54.569 +C Fix\sthe\sbackcompat.test\sscript\sso\sthat\sit\sworks\swith\sthe\s--testdir\stest\soption. +D 2016-03-14T15:43:03.210 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -484,7 +484,7 @@ F test/autoindex5.test 96f084a5e6024ea07cace5888df3223f3ea86990 F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 -F test/backcompat.test 28403f43d11624e696c5ef134c7c7d81015cd19e +F test/backcompat.test 3e64cedda754c778ef6bbe417b6e7a295e662a4d F test/backup.test b79299a536a4c6d919094786595b95be56d02014 F test/backup2.test 34986ef926ea522911a51dfdb2f8e99b7b75ebcf F test/backup4.test 2a2e4a64388090b152de753fd9e123f28f6a3bd4 @@ -493,7 +493,7 @@ F test/backup_ioerr.test 4c3c7147cee85b024ecf6e150e090c32fdbb5135 F test/backup_malloc.test 7162d604ec2b4683c4b3799a48657fb8b5e2d450 F test/badutf.test d5360fc31f643d37a973ab0d8b4fb85799c3169f F test/badutf2.test f5bc7f2d280670ecd79b9cf4f0f1760c607fe51f -F test/bc_common.tcl 3eda41ef9cda7d5f6c205462c96228b301da4191 +F test/bc_common.tcl b5e42d80305be95697e6370e015af571e5333a1c F test/bestindex1.test d5ba89a7941a941476d8d69be39b146aaed3614c F test/bestindex2.test 4a06b8922ab2fd09434870da8d1cdf525aaf7060 F test/between.test 34d375fb5ce1ae283ffe82b6b233e9f38e84fc6c @@ -1456,8 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 54b8968e335760105206b894672213c1d56771a4 fa8c12921f8361f1889724bb7c5f7eca9c48b075 -R e6d4ff0cfaea5c603741eca2f2c0aea1 -T +closed fa8c12921f8361f1889724bb7c5f7eca9c48b075 -U drh -Z 3e9e43a77139e0aba2725db0c4d642ac +P 90e0cc7b0be31ee2f155c2c053b0cbac584f6154 +R 02e42b4c9a3b088e9b811e95ac0b8895 +U dan +Z adf33e3278f777c691b4da9ad8602fb1 diff --git a/manifest.uuid b/manifest.uuid index 365f26434f..352d970249 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -90e0cc7b0be31ee2f155c2c053b0cbac584f6154 \ No newline at end of file +f7480e33eb82f2eae219d17ce46cd2d4edac07d2 \ No newline at end of file diff --git a/test/backcompat.test b/test/backcompat.test index fe8a83f0a6..87ffc4b3ea 100644 --- a/test/backcompat.test +++ b/test/backcompat.test @@ -85,7 +85,8 @@ proc do_allbackcompat_test {script} { set nErr [set_test_counter errors] foreach dir {0 1} { - set bintag [string map {testfixture {}} $bin] + set bintag $bin + regsub {.*testfixture\.} $bintag {} bintag set bintag [string map {\.exe {}} $bintag] if {$bintag == ""} {set bintag self} set ::bcname ".$bintag.$dir." diff --git a/test/bc_common.tcl b/test/bc_common.tcl index 78010dfa46..c47f99681f 100644 --- a/test/bc_common.tcl +++ b/test/bc_common.tcl @@ -7,7 +7,7 @@ proc bc_find_binaries {zCaption} { # against. # set binaries [list] - set self [file tail [info nameofexec]] + set self [info nameofexec] set pattern "$self?*" if {$::tcl_platform(platform)=="windows"} { set pattern [string map {\.exe {}} $pattern] @@ -52,7 +52,8 @@ proc do_bc_test {bin script} { code1 { sqlite3 db test.db } code2 { sqlite3 db test.db } - set bintag [string map {testfixture {}} $bin] + set bintag $bin + regsub {.*testfixture\.} $bintag {} bintag set bintag [string map {\.exe {}} $bintag] if {$bintag == ""} {set bintag self} set saved_prefix $::testprefix From 7bd6b49a3e03818b60e58b5aa0eeacd29a0b643a Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 16:16:43 +0000 Subject: [PATCH 46/57] Test script changes to support testing the SQLite Encryption Extension. FossilOrigin-Name: 1c70aa5c014fc48ab06215992a61c6f92490abe4 --- manifest | 22 ++++++++++++---------- manifest.uuid | 2 +- test/autovacuum.test | 17 ++++++++++++++--- test/e_uri.test | 2 +- test/superlock.test | 1 + test/walbak.test | 1 + 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 8cf8ea024d..320c150381 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Run\sTCL\stests\sin\sthe\s"testdir"\ssubdirectory. -D 2016-03-14T15:03:54.569 +C Test\sscript\schanges\sto\ssupport\stesting\sthe\sSQLite\sEncryption\sExtension. +D 2016-03-14T16:16:43.649 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -481,7 +481,7 @@ F test/autoindex2.test 12ef578928102baaa0dc23ad397601a2f4ecb0df F test/autoindex3.test a3be0d1a53a7d2edff208a5e442312957047e972 F test/autoindex4.test 49d3cd791a9baa16fb461d7ea3de80d019a819cf F test/autoindex5.test 96f084a5e6024ea07cace5888df3223f3ea86990 -F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 +F test/autovacuum.test 92c24eedbdb68e49f3fb71f26f9ce6d8988cac15 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 F test/backcompat.test 28403f43d11624e696c5ef134c7c7d81015cd19e @@ -616,7 +616,7 @@ F test/e_select.test 52692ff3849541e828ad4661fe3773a9b8711763 F test/e_select2.test aceb80ab927d46fba5ce7586ebabf23e2bb0604f F test/e_totalchanges.test b12ee5809d3e63aeb83238dd501a7bca7fd72c10 F test/e_update.test f46c2554d915c9197548681e8d8c33a267e84528 -F test/e_uri.test eed3eb41b22d051a1164110dacdc778899126e14 +F test/e_uri.test 25385396082b67fd02ae0038b95a3b3575fe0519 F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9 F test/e_wal.test ae9a593207a77d711443ee69ffe081fda9243625 F test/e_walauto.test 280714ddf14e1a47dcbc59d515cd0b026dfd5567 @@ -1072,7 +1072,7 @@ F test/subquery2.test 438f8a7da1457277b22e4176510f7659b286995f F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 -F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2 +F test/superlock.test 168011a6730aee70c28ea8d5e1c0592de4026f79 F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test 2f607e1821aa3af3c5c53b58835c05e511c95899 F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c @@ -1314,7 +1314,7 @@ F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd F test/wal8.test 75c42e1bc4545c277fed212f8fc9b7723cd02216 F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe -F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877 +F test/walbak.test 8f4466e574dcd3a41cad3f25c45dc15aa74959d8 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 F test/walblock.test be48f3a75eff0b4456209f26b3ce186c2015497d F test/walcksum.test bb234a1bb42248b3515d992b719708015c384278 @@ -1456,8 +1456,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 54b8968e335760105206b894672213c1d56771a4 fa8c12921f8361f1889724bb7c5f7eca9c48b075 -R e6d4ff0cfaea5c603741eca2f2c0aea1 -T +closed fa8c12921f8361f1889724bb7c5f7eca9c48b075 +P 90e0cc7b0be31ee2f155c2c053b0cbac584f6154 +R 923bd9deb3676f2e6a04ffc9c99e77ab +T *branch * see-testing +T *sym-see-testing * +T -sym-trunk * U drh -Z 3e9e43a77139e0aba2725db0c4d642ac +Z 56d0f9475e233b620a1fb1bf6022de74 diff --git a/manifest.uuid b/manifest.uuid index 365f26434f..7f70b633fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -90e0cc7b0be31ee2f155c2c053b0cbac584f6154 \ No newline at end of file +1c70aa5c014fc48ab06215992a61c6f92490abe4 \ No newline at end of file diff --git a/test/autovacuum.test b/test/autovacuum.test index 9ee2cd0fa8..5c14ed85d3 100644 --- a/test/autovacuum.test +++ b/test/autovacuum.test @@ -269,7 +269,7 @@ do_test autovacuum-2.4.3 { } {3 4 5 6 7 8 9 10} # Right now there are 5 free pages in the database. Consume and then free -# a 520 pages. Then create 520 tables. This ensures that at least some of the +# all 520 pages. Then create 520 tables. This ensures that at least some of the # desired root-pages reside on the second free-list trunk page, and that the # trunk itself is required at some point. do_test autovacuum-2.4.4 { @@ -280,9 +280,20 @@ do_test autovacuum-2.4.4 { } {} set root_page_list [list] set pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1] + +# unusable_pages +# These are either the pending_byte page or the pointer map pages +# +unset -nocomplain unusable_page +if {[sqlite3 -has-codec]} { + array set unusable_page {205 1 408 1} +} else { + array set unusable_page {207 1 412 1} +} +set unusable_page($pending_byte_page) 1 + for {set i 3} {$i<=532} {incr i} { - # 207 and 412 are pointer-map pages. - if { $i!=207 && $i!=412 && $i != $pending_byte_page} { + if {![info exists unusable_page($i)]} { lappend root_page_list $i } } diff --git a/test/e_uri.test b/test/e_uri.test index 7a7f2559ec..95b53f1d6b 100644 --- a/test/e_uri.test +++ b/test/e_uri.test @@ -13,7 +13,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix e_uri - +do_not_use_codec db close proc parse_uri {uri} { diff --git a/test/superlock.test b/test/superlock.test index 8199d5218d..1e4a4a78d9 100644 --- a/test/superlock.test +++ b/test/superlock.test @@ -15,6 +15,7 @@ source $testdir/tester.tcl source $testdir/lock_common.tcl set testprefix superlock +do_not_use_codec # Test organization: # diff --git a/test/walbak.test b/test/walbak.test index 303a628a84..8d4ee01175 100644 --- a/test/walbak.test +++ b/test/walbak.test @@ -127,6 +127,7 @@ do_test walbak-2.1 { } } {} do_test walbak-2.2 { + forcedelete abc.db db backup abc.db sqlite3 db2 abc.db string compare [sig db] [sig db2] From af3906a7980c6aff862d3af7e4d329a2789fca9c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 17:05:04 +0000 Subject: [PATCH 47/57] Many test cases fixed to work with encryption. FossilOrigin-Name: d866fffb8b1af5003a8730ce7029d1edddb24d46 --- manifest | 47 ++++++++++++++---------------- manifest.uuid | 2 +- test/backup4.test | 5 ++++ test/close.test | 4 +++ test/corrupt3.test | 7 ++--- test/corrupt4.test | 7 ++--- test/corrupt6.test | 7 ++--- test/corrupt7.test | 7 ++--- test/corruptE.test | 7 ++--- test/corruptG.test | 7 ++--- test/corruptH.test | 8 ++--- test/corruptI.test | 8 ++--- test/corruptJ.test | 8 ++--- test/crash8.test | 1 + test/e_vacuum.test | 58 +++++++++++++++++++------------------ test/eqp.test | 66 ++++++++++++++++++++++-------------------- test/incrblob.test | 10 +++---- test/incrblob_err.test | 4 +-- test/tester.tcl | 7 +++++ 19 files changed, 141 insertions(+), 129 deletions(-) diff --git a/manifest b/manifest index 320c150381..4ca965b914 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\sscript\schanges\sto\ssupport\stesting\sthe\sSQLite\sEncryption\sExtension. -D 2016-03-14T16:16:43.649 +C Many\stest\scases\sfixed\sto\swork\swith\sencryption. +D 2016-03-14T17:05:04.050 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -487,7 +487,7 @@ F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 F test/backcompat.test 28403f43d11624e696c5ef134c7c7d81015cd19e F test/backup.test b79299a536a4c6d919094786595b95be56d02014 F test/backup2.test 34986ef926ea522911a51dfdb2f8e99b7b75ebcf -F test/backup4.test 2a2e4a64388090b152de753fd9e123f28f6a3bd4 +F test/backup4.test 8f6fd48e0dfde77b9a3bb26dc471ede3e101df32 F test/backup5.test ee5da6d7fe5082f5b9b0bbfa31d016f52412a2e4 F test/backup_ioerr.test 4c3c7147cee85b024ecf6e150e090c32fdbb5135 F test/backup_malloc.test 7162d604ec2b4683c4b3799a48657fb8b5e2d450 @@ -528,7 +528,7 @@ F test/capi3e.test 3d49c01ef2a1a55f41d73cba2b23b5059ec460fe F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3 F test/cffault.test aadc1f61f8811cb600e3e069acbf8796f472a096 F test/check.test 85a84bfc4be0e83f668747211c7cd45a6721d485 -F test/close.test 340bd24cc58b16c6bc01967402755027c37eb815 +F test/close.test 83947daf3b700631f90f4850ddaab455be4af73d F test/closure01.test b1703ba40639cfc9b295cf478d70739415eec6a4 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 F test/collate1.test 08c18e7512a5a32c97938854263fa15362eeb846 @@ -549,23 +549,23 @@ F test/conflict3.test dec0634c0f31dec9a4b01c63063e939f0cd21b6b F test/contrib01.test 2a1cbc0f2f48955d7d073f725765da6fbceda6b4 F test/corrupt.test 141c39ea650c1365e85a49e402fa05cb9617fb97 F test/corrupt2.test cb787825d761b0f869764d6990531382840de872 -F test/corrupt3.test 4b548d0bbe2933bc81d3f54099a05fc4d28aff18 -F test/corrupt4.test b99652079d542b21f4965f6248703b983e40fe80 +F test/corrupt3.test e676f478fe602915d721472811f6f410b75ddc7e +F test/corrupt4.test 8d1d86b850fcc43e417450454f2044e52d55778a F test/corrupt5.test 8ead52af76006f3286e9396cb41898018ccea107 -F test/corrupt6.test 269548d19427ac554c830763b1c5ea54a0252f80 -F test/corrupt7.test e4fa6d6584276679cc1d20c4e58beb9559a4eb85 +F test/corrupt6.test fc6a891716139665dae0073b6945e3670bf92568 +F test/corrupt7.test b036f94bda4b0b23a2919bf717046ce9ecca4543 F test/corrupt8.test 2399dfe40d2c0c63af86706e30f3e6302a8d0516 F test/corrupt9.test 730a3db08d4ab9aa43392ea30d9c2b4879cbff85 F test/corruptA.test 53e56dafd180addcdadb402244b8cb9771d2ba26 F test/corruptB.test 73a8d6c0b9833697ecf16b63e3c5c05c945b5dec F test/corruptC.test 0c46574f8d4f27ecc799b1b5c4cbf9b1817bce9a F test/corruptD.test b3c205fac7952b1de645ce44bb02335cd9e3e040 -F test/corruptE.test be8e5088c369fc7979c662cd644efdaafc0f7f6d +F test/corruptE.test 82ccf4f8f543fdbedd4aa42c709cb077f7374c62 F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 -F test/corruptG.test 1ab3bf97ee7bdba70e0ff3ba2320657df55d1804 -F test/corruptH.test 99ad81a4bda7cc078c589ef7542ecbc64e453c80 -F test/corruptI.test 347babbf970e7947e3f91dccf7a1bec28a1bab04 -F test/corruptJ.test 9e29e7a81ee3b6ac50f77ea7a9e2f3fa03f32d91 +F test/corruptG.test adf79b669cbfd19e28c8191a610d083ae53a6d51 +F test/corruptH.test 79801d97ec5c2f9f3c87739aa1ec2eb786f96454 +F test/corruptI.test 075fe1d75aa1d84e2949be56b6264376c41502e4 +F test/corruptJ.test 4d5ccc4bf959464229a836d60142831ef76a5aa4 F test/cost.test 1eedbfd868f806f3fa08ff072b04cf270dcf61c8 F test/count.test cb2e0f934c6eb33670044520748d2ecccd46259c F test/coveridxscan.test b629e896b14df2f000a99b8d170d80589c46562c @@ -576,7 +576,7 @@ F test/crash4.test fe2821baf37168dc59dd733dcf7dba2a401487bc F test/crash5.test 05dd3aa9dbb751a22d5cdaf22a9c49b6667aa219 F test/crash6.test 4c56f1e40d0291e1110790a99807aa875b1647ba F test/crash7.test 1a194c4900a255258cf94b7fcbfd29536db572df -F test/crash8.test 61442a9964ab6b124fc5254e4258b45747842e6f +F test/crash8.test a63907617d8e74fb54b4bff23eca8a4435625245 F test/crashM.test d95f59046fa749b0d0822edf18a717788c8f318d F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8 @@ -617,7 +617,7 @@ F test/e_select2.test aceb80ab927d46fba5ce7586ebabf23e2bb0604f F test/e_totalchanges.test b12ee5809d3e63aeb83238dd501a7bca7fd72c10 F test/e_update.test f46c2554d915c9197548681e8d8c33a267e84528 F test/e_uri.test 25385396082b67fd02ae0038b95a3b3575fe0519 -F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9 +F test/e_vacuum.test 4d5b391384bb7d56bb9337d956f08035332421fc F test/e_wal.test ae9a593207a77d711443ee69ffe081fda9243625 F test/e_walauto.test 280714ddf14e1a47dcbc59d515cd0b026dfd5567 F test/e_walckpt.test 28c371a6bb5e5fe7f31679c1df1763a19d19e8a0 @@ -626,7 +626,7 @@ F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea F test/enc2.test 83437a79ba1545a55fb549309175c683fb334473 F test/enc3.test 6807f7a7740a00361ca8d0ccd66bc60c8dc5f2b6 F test/enc4.test c8f1ce3618508fd0909945beb8b8831feef2c020 -F test/eqp.test 85873fa5816c48915c82c4e74cb5c35a5b48160f +F test/eqp.test 3fe051af50921284189d1970eb653f9fcf5117d2 F test/errmsg.test f31592a594b44ee121371d25ddd5d63497bb3401 F test/eval.test a64c9105d6ff163df7cf09d6ac29cdad5922078c F test/exclusive.test f48243eaf40e0957215501a12f510a8644d13a02 @@ -790,11 +790,11 @@ F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068 F test/in5.test acc710c12af118df5f8645eaba9479f5619eed81 -F test/incrblob.test e81846d214f3637622620fbde7cd526781cfe328 +F test/incrblob.test 8a6d31ba3243d7c00cebf0b0d9ff533410e8b412 F test/incrblob2.test a5ce5ed1d0b01e2ed347245a21170372528af0a5 F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4 F test/incrblob4.test f26502a5697893e5acea268c910f16478c2f0fab -F test/incrblob_err.test af1f12ba60d220c9752073ff2bda2ad59e88960d +F test/incrblob_err.test 69f9247fed50278d48ea710d1a8f9cdb09e4c0b8 F test/incrblobfault.test 280474078f6da9e732cd2a215d3d854969014b6e F test/incrcorrupt.test 6c567fbf870aa9e91866fe52ce6f200cd548939a F test/incrvacuum.test d2a6ddf5e429720b5fe502766af747915ccf6c32 @@ -1085,7 +1085,7 @@ F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl 8fbf071b23ec66ce9bb8607fc92fdc4326393697 +F test/tester.tcl d6dee24773e20320ab64d39bb5ce6e1a91b6029e F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1456,10 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 90e0cc7b0be31ee2f155c2c053b0cbac584f6154 -R 923bd9deb3676f2e6a04ffc9c99e77ab -T *branch * see-testing -T *sym-see-testing * -T -sym-trunk * +P 1c70aa5c014fc48ab06215992a61c6f92490abe4 +R ac90bb020079fb64a047783b4d5bc228 U drh -Z 56d0f9475e233b620a1fb1bf6022de74 +Z 40fa5f4f9bc49db4a476fd7c95e3e453 diff --git a/manifest.uuid b/manifest.uuid index 7f70b633fd..de29d5f426 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c70aa5c014fc48ab06215992a61c6f92490abe4 \ No newline at end of file +d866fffb8b1af5003a8730ce7029d1edddb24d46 \ No newline at end of file diff --git a/test/backup4.test b/test/backup4.test index 417df80e55..2756995c3a 100644 --- a/test/backup4.test +++ b/test/backup4.test @@ -23,6 +23,11 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix backup4 +# The codec logic does not work for zero-length database files. A database +# file must contain at least one page in order to be recognized as an +# encrypted database. +do_not_use_codec + #------------------------------------------------------------------------- # At one point this test was failing because [db] was using an out of # date schema in test case 1.2. diff --git a/test/close.test b/test/close.test index d5d6391ae5..1b789bc776 100644 --- a/test/close.test +++ b/test/close.test @@ -17,6 +17,10 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix close +# This module bypasses the "-key" logic in tester.tcl, so it cannot run +# with the codec enabled. +do_not_use_codec + do_execsql_test 1.0 { CREATE TABLE t1(x); INSERT INTO t1 VALUES('one'); diff --git a/test/corrupt3.test b/test/corrupt3.test index 436a466189..85139420b8 100644 --- a/test/corrupt3.test +++ b/test/corrupt3.test @@ -18,10 +18,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} # These tests deal with corrupt database files # diff --git a/test/corrupt4.test b/test/corrupt4.test index 24db60fd52..55969c6a8c 100644 --- a/test/corrupt4.test +++ b/test/corrupt4.test @@ -18,10 +18,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} # These tests deal with corrupt database files # diff --git a/test/corrupt6.test b/test/corrupt6.test index 7d90c4a3ba..dd773c9265 100644 --- a/test/corrupt6.test +++ b/test/corrupt6.test @@ -19,10 +19,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} # These tests deal with corrupt database files # diff --git a/test/corrupt7.test b/test/corrupt7.test index 7ebebd94e7..aa66cc7ece 100644 --- a/test/corrupt7.test +++ b/test/corrupt7.test @@ -19,10 +19,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} # These tests deal with corrupt database files # diff --git a/test/corruptE.test b/test/corruptE.test index 78cabbec8e..54aa420f43 100644 --- a/test/corruptE.test +++ b/test/corruptE.test @@ -18,10 +18,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} # These tests deal with corrupt database files # diff --git a/test/corruptG.test b/test/corruptG.test index af920edf41..94480340a7 100644 --- a/test/corruptG.test +++ b/test/corruptG.test @@ -14,10 +14,9 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix corruptG -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} # These tests deal with corrupt database files # diff --git a/test/corruptH.test b/test/corruptH.test index 0e1a1d4429..9ba7522422 100644 --- a/test/corruptH.test +++ b/test/corruptH.test @@ -14,10 +14,10 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix corruptH -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + database_may_be_corrupt # The corruption migrations tested by the code in this file are not detected diff --git a/test/corruptI.test b/test/corruptI.test index 9f46efb744..cdcb94201e 100644 --- a/test/corruptI.test +++ b/test/corruptI.test @@ -19,10 +19,10 @@ if {[permutation]=="mmap"} { return } -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + database_may_be_corrupt # Initialize the database. diff --git a/test/corruptJ.test b/test/corruptJ.test index c08e628e2d..732adb085c 100644 --- a/test/corruptJ.test +++ b/test/corruptJ.test @@ -22,10 +22,10 @@ if {[permutation]=="mmap"} { return } -# Do not use a codec for tests in this file, as the database file is -# manipulated directly using tcl scripts (using the [hexio_write] command). -# -do_not_use_codec +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + database_may_be_corrupt # Initialize the database. diff --git a/test/crash8.test b/test/crash8.test index 930834a962..f3b6f6e244 100644 --- a/test/crash8.test +++ b/test/crash8.test @@ -25,6 +25,7 @@ ifcapable !crashtest { finish_test return } +do_not_use_codec do_test crash8-1.1 { execsql { diff --git a/test/e_vacuum.test b/test/e_vacuum.test index 99b31aaca4..1113a1fb6e 100644 --- a/test/e_vacuum.test +++ b/test/e_vacuum.test @@ -159,35 +159,37 @@ do_test e_vacuum-1.3.1.2 { execsql { PRAGMA page_size ; PRAGMA auto_vacuum } } {1024 1} -# EVIDENCE-OF: R-08570-19916 However, when not in write-ahead log mode, -# the page_size and/or auto_vacuum properties of an existing database -# may be changed by using the page_size and/or pragma auto_vacuum -# pragmas and then immediately VACUUMing the database. -# -do_test e_vacuum-1.3.2.1 { - execsql { PRAGMA journal_mode = delete } - execsql { PRAGMA page_size = 2048 } - execsql { PRAGMA auto_vacuum = NONE } - execsql VACUUM - execsql { PRAGMA page_size ; PRAGMA auto_vacuum } -} {2048 0} - -# EVIDENCE-OF: R-48521-51450 When in write-ahead log mode, only the -# auto_vacuum support property can be changed using VACUUM. -# -ifcapable wal { -do_test e_vacuum-1.3.3.1 { - execsql { PRAGMA journal_mode = wal } - execsql { PRAGMA page_size ; PRAGMA auto_vacuum } -} {2048 0} -do_test e_vacuum-1.3.3.2 { - execsql { PRAGMA page_size = 1024 } - execsql { PRAGMA auto_vacuum = FULL } - execsql VACUUM - execsql { PRAGMA page_size ; PRAGMA auto_vacuum } -} {2048 1} +if {![nonzero_reserved_bytes]} { + # EVIDENCE-OF: R-08570-19916 However, when not in write-ahead log mode, + # the page_size and/or auto_vacuum properties of an existing database + # may be changed by using the page_size and/or pragma auto_vacuum + # pragmas and then immediately VACUUMing the database. + # + do_test e_vacuum-1.3.2.1 { + execsql { PRAGMA journal_mode = delete } + execsql { PRAGMA page_size = 2048 } + execsql { PRAGMA auto_vacuum = NONE } + execsql VACUUM + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 0} + + # EVIDENCE-OF: R-48521-51450 When in write-ahead log mode, only the + # auto_vacuum support property can be changed using VACUUM. + # + ifcapable wal { + do_test e_vacuum-1.3.3.1 { + execsql { PRAGMA journal_mode = wal } + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 0} + do_test e_vacuum-1.3.3.2 { + execsql { PRAGMA page_size = 1024 } + execsql { PRAGMA auto_vacuum = FULL } + execsql VACUUM + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 1} + } } - + # EVIDENCE-OF: R-38001-03952 VACUUM only works on the main database. It # is not possible to VACUUM an attached database file. forcedelete test.db2 diff --git a/test/eqp.test b/test/eqp.test index 046088c9c5..c955a80c21 100644 --- a/test/eqp.test +++ b/test/eqp.test @@ -516,45 +516,47 @@ det 5.13 "SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1" { } -#------------------------------------------------------------------------- -# The following tests - eqp-6.* - test that the example C code on -# documentation page eqp.html works. The C code is duplicated in test1.c -# and wrapped in Tcl command [print_explain_query_plan] -# -set boilerplate { - proc explain_query_plan {db sql} { - set stmt [sqlite3_prepare_v2 db $sql -1 DUMMY] - print_explain_query_plan $stmt - sqlite3_finalize $stmt +if {![nonzero_reserved_bytes]} { + #------------------------------------------------------------------------- + # The following tests - eqp-6.* - test that the example C code on + # documentation page eqp.html works. The C code is duplicated in test1.c + # and wrapped in Tcl command [print_explain_query_plan] + # + set boilerplate { + proc explain_query_plan {db sql} { + set stmt [sqlite3_prepare_v2 db $sql -1 DUMMY] + print_explain_query_plan $stmt + sqlite3_finalize $stmt + } + sqlite3 db test.db + explain_query_plan db {%SQL%} + db close + exit } - sqlite3 db test.db - explain_query_plan db {%SQL%} - db close - exit -} - -# Do a "Print Explain Query Plan" test. -proc do_peqp_test {tn sql res} { - set fd [open script.tcl w] - puts $fd [string map [list %SQL% $sql] $::boilerplate] - close $fd - - uplevel do_test $tn [list { - set fd [open "|[info nameofexec] script.tcl"] - set data [read $fd] + + # Do a "Print Explain Query Plan" test. + proc do_peqp_test {tn sql res} { + set fd [open script.tcl w] + puts $fd [string map [list %SQL% $sql] $::boilerplate] close $fd - set data - }] [list $res] -} - -do_peqp_test 6.1 { - SELECT a, b FROM t1 EXCEPT SELECT d, 99 FROM t2 ORDER BY 1 -} [string trimleft { + + uplevel do_test $tn [list { + set fd [open "|[info nameofexec] script.tcl"] + set data [read $fd] + close $fd + set data + }] [list $res] + } + + do_peqp_test 6.1 { + SELECT a, b FROM t1 EXCEPT SELECT d, 99 FROM t2 ORDER BY 1 + } [string trimleft { 1 0 0 SCAN TABLE t1 USING COVERING INDEX i2 2 0 0 SCAN TABLE t2 2 0 0 USE TEMP B-TREE FOR ORDER BY 0 0 0 COMPOUND SUBQUERIES 1 AND 2 (EXCEPT) }] +} #------------------------------------------------------------------------- # The following tests - eqp-7.* - test that queries that use the OP_Count diff --git a/test/incrblob.test b/test/incrblob.test index 4277e5c4c1..44182287ec 100644 --- a/test/incrblob.test +++ b/test/incrblob.test @@ -384,7 +384,7 @@ ifcapable vtab { ifcapable attach { do_test incrblob-5.1 { forcedelete test2.db test2.db-journal - set ::size [expr [file size [info script]]] + set ::size [expr [file size $::cmdlinearg(INFO_SCRIPT)]] execsql { ATTACH 'test2.db' AS aux; CREATE TABLE aux.files(name, text); @@ -392,16 +392,16 @@ ifcapable attach { } set fd [db incrblob aux files text 1] fconfigure $fd -translation binary - set fd2 [open [info script]] + set fd2 [open $::cmdlinearg(INFO_SCRIPT)] fconfigure $fd2 -translation binary puts -nonewline $fd [read $fd2] close $fd close $fd2 set ::text [db one {select text from aux.files}] string length $::text - } [file size [info script]] + } [file size $::cmdlinearg(INFO_SCRIPT)] do_test incrblob-5.2 { - set fd2 [open [info script]] + set fd2 [open $::cmdlinearg(INFO_SCRIPT)] fconfigure $fd2 -translation binary set ::data [read $fd2] close $fd2 @@ -576,7 +576,7 @@ foreach {tn arg} {1 "" 2 -readonly} { } -set fd [open [info script]] +set fd [open $::cmdlinearg(INFO_SCRIPT)] fconfigure $fd -translation binary set ::data [read $fd 14000] close $fd diff --git a/test/incrblob_err.test b/test/incrblob_err.test index a08bea3e4e..0db8b0dcba 100644 --- a/test/incrblob_err.test +++ b/test/incrblob_err.test @@ -24,12 +24,12 @@ ifcapable {!incrblob || !memdebug || !tclvar} { source $testdir/malloc_common.tcl unset -nocomplain ::fd ::data -set ::fd [open [info script]] +set ::fd [open $::cmdlinearg(INFO_SCRIPT)] set ::data [read $::fd] close $::fd do_malloc_test 1 -tclprep { - set bytes [file size [info script]] + set bytes [file size $::cmdlinearg(INFO_SCRIPT)] execsql { CREATE TABLE blobs(k, v BLOB); INSERT INTO blobs VALUES(1, zeroblob($::bytes)); diff --git a/test/tester.tcl b/test/tester.tcl index 6dc507f70e..3a881138e2 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -374,6 +374,12 @@ proc do_not_use_codec {} { reset_db } +# Return true if the "reserved_bytes" integer on database files is non-zero. +# +proc nonzero_reserved_bytes {} { + return [sqlite3 -has-codec] +} + # Print a HELP message and exit # proc print_help_and_quit {} { @@ -521,6 +527,7 @@ if {[info exists cmdlinearg]==0} { } set testdir [file normalize $testdir] set cmdlinearg(TESTFIXTURE_HOME) [pwd] + set cmdlinearg(INFO_SCRIPT) [file normalize [info script]] set argv0 [file normalize $argv0] if {$cmdlinearg(testdir)!=""} { file mkdir $cmdlinearg(testdir) From 7da56b4f65ceb4cecb5bd5f1a167e00b393d9889 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 18:34:42 +0000 Subject: [PATCH 48/57] Many more test cases fixed. Only a few remain. FossilOrigin-Name: 99b9d7eef68fd6d5c9eecb5fbe3dfe002c1ca4a8 --- manifest | 46 ++++++++-------- manifest.uuid | 2 +- test/e_walauto.test | 5 ++ test/incrblob.test | 13 +++-- test/io.test | 2 +- test/memsubsys1.test | 2 +- test/mmap1.test | 6 ++- test/mmap3.test | 3 ++ test/nan.test | 80 +++++++++++++-------------- test/pageropt.test | 1 + test/pragma.test | 126 ++++++++++++++++++++++--------------------- test/pragma3.test | 1 + test/stat.test | 4 ++ test/tclsqlite.test | 5 +- test/tkt4018.test | 1 + test/wal.test | 2 + test/wal5.test | 1 + test/wal8.test | 1 + test/walbak.test | 1 + test/walro.test | 2 +- 20 files changed, 167 insertions(+), 137 deletions(-) diff --git a/manifest b/manifest index 4ca965b914..ae6b61c7de 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Many\stest\scases\sfixed\sto\swork\swith\sencryption. -D 2016-03-14T17:05:04.050 +C Many\smore\stest\scases\sfixed.\s\sOnly\sa\sfew\sremain. +D 2016-03-14T18:34:42.199 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -619,7 +619,7 @@ F test/e_update.test f46c2554d915c9197548681e8d8c33a267e84528 F test/e_uri.test 25385396082b67fd02ae0038b95a3b3575fe0519 F test/e_vacuum.test 4d5b391384bb7d56bb9337d956f08035332421fc F test/e_wal.test ae9a593207a77d711443ee69ffe081fda9243625 -F test/e_walauto.test 280714ddf14e1a47dcbc59d515cd0b026dfd5567 +F test/e_walauto.test 248af31e73c98df23476a22bdb815524c9dc3ba8 F test/e_walckpt.test 28c371a6bb5e5fe7f31679c1df1763a19d19e8a0 F test/e_walhook.test 4c0613a0c76e7a9d5c4c211e1b4cbcc1143914df F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea @@ -790,7 +790,7 @@ F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068 F test/in5.test acc710c12af118df5f8645eaba9479f5619eed81 -F test/incrblob.test 8a6d31ba3243d7c00cebf0b0d9ff533410e8b412 +F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 F test/incrblob2.test a5ce5ed1d0b01e2ed347245a21170372528af0a5 F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4 F test/incrblob4.test f26502a5697893e5acea268c910f16478c2f0fab @@ -821,7 +821,7 @@ F test/instr.test 737bbf80685232033f3abedc6ae92f75860b5dd2 F test/intarray.test 066b7d7ac38d25bf96f87f1b017bfc687551cdd4 F test/interrupt.test dfe9a67a94b0b2d8f70545ba1a6cca10780d71cc F test/intpkey.test 7506090fc08e028712a8bf47e5f54111947e3844 -F test/io.test 3a7abcef18727cc0f2399e04b0e8903eccae50f8 +F test/io.test f95bca1783b01ea7761671560d023360d2dfa4cc F test/ioerr.test 2a24bd6ed5a8b062e64bfe1f6cf94fb25e92210d F test/ioerr2.test 2593563599e2cc6b6b4fcf5878b177bdd5d8df26 F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd @@ -889,7 +889,7 @@ F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test c1f2a343ad14398d5d6debda6ea33e80d0dafcc7 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 -F test/memsubsys1.test d2b2d6ca37890b26703a2258df8fd66f9869da02 +F test/memsubsys1.test 0311bfb4edd2615e3aa56c7a9cf44574e4229077 F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc @@ -904,9 +904,9 @@ F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test edd0b63e2ee29a256900b0514f6fff27e19e9bb2 F test/misc8.test 21ac9d35a5e110279ae9e1588b8914f54de1c60b F test/misuse.test 3c34719944ba045cc6c188a4852ba04680728912 -F test/mmap1.test 44a5ff1c1bcc7dcf2de50227d1f997e75a8ef1ae +F test/mmap1.test d2cfc1635171c434dcff0ece2f1c8e0a658807ce F test/mmap2.test 9d6dd9ddb4ad2379f29cc78f38ce1e63ed418022 -F test/mmap3.test c92273e16eb8d23c1d55c9815b446bb72ef0512e +F test/mmap3.test b3c297e78e6a8520aafcc1a8f140535594c9086e F test/mmap4.test 2e2b4e32555b58da15176e6fe750f17c9dcf7f93 F test/mmapfault.test d4c9eff9cd8c2dc14bc43e71e042f175b0a26fe3 F test/multiplex.test efd015ca0b5b4a57dc9535b8feb1273eebeadb60 @@ -915,7 +915,7 @@ F test/multiplex3.test d228f59eac91839a977eac19f21d053f03e4d101 F test/multiplex4.test e8ae4c4bd70606a5727743241f13b5701990abe4 F test/mutex1.test e0a44072d98189003deae4b091106f085d94bea8 F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660 -F test/nan.test e9648b9d007c7045242af35e11a984d4b169443a +F test/nan.test dacc57f80859c06a433d30839336fe227d2038b3 F test/nolock.test 96e922d2d3db71c2dd6557c98e8027a28277b415 F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161 @@ -944,16 +944,16 @@ F test/pager4.test a122e9e6925d5b23b31e3dfef8c6a44bbf19590e F test/pagerfault.test ae9ee0db5a30aecda9db8290ce3dd12e5f7bbaa1 F test/pagerfault2.test caf4c7facb914fd3b03a17b31ae2b180c8d6ca1f F test/pagerfault3.test 1003fcda009bf48a8e22a516e193b6ef0dd1bbd8 -F test/pageropt.test 6b8f6a123a5572c195ad4ae40f2987007923bbd6 +F test/pageropt.test f8d840f0fed84854dbd12b4c17fb3506eeb8224c F test/pagesize.test 5769fc62d8c890a83a503f67d47508dfdc543305 F test/parser1.test 222b5cbf3e2e659fec1bf7d723488c8b9c94f1d0 F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff F test/permutations.test 64abe58d53cde4adcfb881e37aa5ea1b2a980e58 -F test/pragma.test 507ac7ef2ea5682241ea0ef041799ca70bb5e0bf +F test/pragma.test afbf028be1c35b68f57db8eb015c4a3c59d8f28e F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f -F test/pragma3.test 6f849ccffeee7e496d2f2b5e74152306c0b8757c +F test/pragma3.test 3f1984a04657331f838df5c519b443c2088df922 F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc F test/printf2.test 0b61566dd1c0f0b802f59dffa228c5dc5aa6b054 F test/progress.test ebab27f670bd0d4eb9d20d49cef96e68141d92fb @@ -1064,7 +1064,7 @@ F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33 F test/sqldiff1.test 8f6bc7c6a5b3585d350d779c6078869ba402f8f5 F test/sqllimits1.test a74ee2a3740b9f9c2437c246d8fb77354862a142 F test/sqllog.test 6af6cb0b09f4e44e1917e06ce85be7670302517a -F test/stat.test acc91e80517fff447ae8adcfd953cfdaa5efc0af +F test/stat.test b65bad7120c52583b8f0054d99eff80718119a77 F test/statfault.test f525a7bf633e50afd027700e9a486090684b1ac1 F test/stmt.test 64844332db69cf1a735fcb3e11548557fc95392f F test/subquery.test d7268d193dd33d5505df965399d3a594e76ae13f @@ -1081,7 +1081,7 @@ F test/tabfunc01.test f977868fa8bb7beb4b2072883190411653473906 F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 -F test/tclsqlite.test 7fb866443c7deceed22b63948ccd6f76b52ad054 +F test/tclsqlite.test c6d9f546f79d15d0134c1e06583fb3ee0c3afad3 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 @@ -1237,7 +1237,7 @@ F test/tkt3929.test cdf67acf5aa936ec4ffead81db87f8a71fe40e59 F test/tkt3935.test e15261fedb9e30a4305a311da614a5d8e693c767 F test/tkt3992.test f3e7d548ac26f763b47bc0f750da3d03c81071da F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd -F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1 +F test/tkt4018.test 18dbc6617f7a4b90e938d1bd6d26ad18daafaf08 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/tpch01.test 04adbf8d8300fa60a222f28d901abd76e7be6dd4 F test/trace.test 6f676313e3ebd2a50585036d2f212a3319dd5836 @@ -1303,18 +1303,18 @@ F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad -F test/wal.test 0148c8b3421a25fdb4d9c160e84a681d0646371b +F test/wal.test 613efec03e517e1775d86b993a54877d2e29a477 F test/wal2.test 25ae059e900dbb584e0775627e45415ba5940df1 F test/wal3.test 5dd734147f1f8f958c5261a1f2775d346d7013ce F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c -F test/wal5.test 88b5d9a6a3d1532497ee9f4296f010d66f07e33c +F test/wal5.test 22cb252502c5ff851925add2ca8a7e2af012e1d6 F test/wal6.test a9d6aa635b9d63607dabdc11406f5f96ca986635 F test/wal64k.test 163655ecd2cb8afef4737cac2a40fdd2eeaf20b8 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd -F test/wal8.test 75c42e1bc4545c277fed212f8fc9b7723cd02216 +F test/wal8.test d9df3fba4caad5854ed69ed673c68482514203c8 F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe -F test/walbak.test 8f4466e574dcd3a41cad3f25c45dc15aa74959d8 +F test/walbak.test 018d4e5a3d45c6298d11b99f09a8ef6876527946 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434 F test/walblock.test be48f3a75eff0b4456209f26b3ce186c2015497d F test/walcksum.test bb234a1bb42248b3515d992b719708015c384278 @@ -1328,7 +1328,7 @@ F test/walnoshm.test 84ca10c544632a756467336b7c3b864d493ee496 F test/waloverwrite.test dad2f26567f1b45174e54fbf9a8dc1cb876a7f03 F test/walpersist.test 8c6b7e3ec1ba91b5e4dc4e0921d6d3f87cd356a6 F test/walprotocol.test 059cb75484a1ecf6357a2c1b3324b8156749221e -F test/walro.test 34422d1d95aaff0388f0791ec20edb34e2a3ed57 +F test/walro.test 4ab7ac01b77c2f894235c699d59e3e3c7f15a160 F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test c05c68d4dc2700a982f89133ce103a1a84cc285f F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c70aa5c014fc48ab06215992a61c6f92490abe4 -R ac90bb020079fb64a047783b4d5bc228 +P d866fffb8b1af5003a8730ce7029d1edddb24d46 +R 3cbc3d8762ef570c005be926f5a219e3 U drh -Z 40fa5f4f9bc49db4a476fd7c95e3e453 +Z 5481496fbfdbf0fce1abf7df1c171e0c diff --git a/manifest.uuid b/manifest.uuid index de29d5f426..fd9549389f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d866fffb8b1af5003a8730ce7029d1edddb24d46 \ No newline at end of file +99b9d7eef68fd6d5c9eecb5fbe3dfe002c1ca4a8 \ No newline at end of file diff --git a/test/e_walauto.test b/test/e_walauto.test index 093b13f940..7665b1bf73 100644 --- a/test/e_walauto.test +++ b/test/e_walauto.test @@ -24,6 +24,11 @@ if {$tcl_platform(os) == "OpenBSD"} { return } +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + + proc read_nbackfill {} { seek $::shmfd 96 binary scan [read $::shmfd 4] n nBackfill diff --git a/test/incrblob.test b/test/incrblob.test index 44182287ec..c56689ee1b 100644 --- a/test/incrblob.test +++ b/test/incrblob.test @@ -126,6 +126,11 @@ foreach AutoVacuumMode [list 0 1] { execsql "PRAGMA mmap_size = 0" execsql "PRAGMA auto_vacuum = $AutoVacuumMode" + # Extra value added to size answers + set ib2_extra 0 + if {$AutoVacuumMode} {incr ib2_extra} + if {[nonzero_reserved_bytes]} {incr ib2_extra} + do_test incrblob-2.$AutoVacuumMode.1 { set ::str [string repeat abcdefghij 2900] execsql { @@ -136,7 +141,7 @@ foreach AutoVacuumMode [list 0 1] { COMMIT; } expr [file size test.db]/1024 - } [expr 31 + $AutoVacuumMode] + } [expr 31 + $ib2_extra] ifcapable autovacuum { do_test incrblob-2.$AutoVacuumMode.2 { @@ -163,7 +168,7 @@ foreach AutoVacuumMode [list 0 1] { # sqlite uses the ptrmap pages to avoid reading the other pages. # nRead db - } [expr $AutoVacuumMode ? 4 : 30] + } [expr $AutoVacuumMode ? 4 : 30+$ib2_extra] do_test incrblob-2.$AutoVacuumMode.4 { string range [db one {SELECT v FROM blobs}] end-19 end @@ -187,7 +192,7 @@ foreach AutoVacuumMode [list 0 1] { # sqlite uses the ptrmap pages to avoid reading the other pages. # nRead db - } [expr $AutoVacuumMode ? 4 : 30] + } [expr $AutoVacuumMode ? 4 : 30 + $ib2_extra] # Pages 1 (the write-counter) and 32 (the blob data) were written. do_test incrblob-2.$AutoVacuumMode.6 { @@ -210,7 +215,7 @@ foreach AutoVacuumMode [list 0 1] { do_test incrblob-2.$AutoVacuumMode.9 { nRead db - } [expr $AutoVacuumMode ? 4 : 30] + } [expr $AutoVacuumMode ? 4 : 30 + $ib2_extra] } sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) diff --git a/test/io.test b/test/io.test index c5086c10ec..e1af808a3f 100644 --- a/test/io.test +++ b/test/io.test @@ -424,7 +424,7 @@ ifcapable pager_pragmas { # The COMMIT requires a single fsync() - to the database file. execsql { COMMIT } list [file size test.db] [nSync] - } {39936 1} + } "[expr {[nonzero_reserved_bytes]?40960:39936}] 1" } #---------------------------------------------------------------------- diff --git a/test/memsubsys1.test b/test/memsubsys1.test index 8265ce6317..e9a4cf08a8 100644 --- a/test/memsubsys1.test +++ b/test/memsubsys1.test @@ -255,7 +255,7 @@ do_test memsubsys1-7.4 { } 0 do_test memsubsys1-7.5 { set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] - expr {$maxreq<4100} + expr {$maxreq<4100 + 4200*[nonzero_reserved_bytes]} } 1 do_test memsubsys1-7.6 { set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] diff --git a/test/mmap1.test b/test/mmap1.test index 199a058754..c7c72c0ab2 100644 --- a/test/mmap1.test +++ b/test/mmap1.test @@ -88,7 +88,7 @@ foreach {t mmap_size nRead c2init} { sql2 { DELETE FROM t1 WHERE rowid%2; } do_test $t.$tn.2 { sql1 "SELECT count(*) FROM t1; PRAGMA integrity_check ; PRAGMA page_count" - } {16 ok 42} + } "16 ok [expr {42+[nonzero_reserved_bytes]}]" # Have connection 2 grow the file. Check connection 1 can still read it. sql2 { INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1 } @@ -104,7 +104,9 @@ foreach {t mmap_size nRead c2init} { # Check that the number of pages read by connection 1 indicates that the # "PRAGMA mmap_size" command worked. - do_test $t.$tn.5 { nRead db } $nRead + if {[nonzero_reserved_bytes]==0} { + do_test $t.$tn.5 { nRead db } $nRead + } } } diff --git a/test/mmap3.test b/test/mmap3.test index 07b5152968..184dda5f86 100644 --- a/test/mmap3.test +++ b/test/mmap3.test @@ -19,6 +19,9 @@ ifcapable !mmap||!vtab { source $testdir/lock_common.tcl set testprefix mmap3 +# A codec shuts down memory-mapped I/O +if {[nonzero_reserved_bytes]} {finish_test; return;} + do_test mmap3-1.0 { load_static_extension db wholenumber db eval { diff --git a/test/nan.test b/test/nan.test index df3f65b8e6..27fa04a351 100644 --- a/test/nan.test +++ b/test/nan.test @@ -151,45 +151,47 @@ sqlite3_finalize $::STMT # Then it reads the value of the database to verify it is converted into # NULL. # -do_test nan-3.1 { - db eval { - DELETE FROM t1; - INSERT INTO t1 VALUES(0.5); - PRAGMA auto_vacuum=OFF; - PRAGMA page_size=1024; - VACUUM; - } - hexio_read test.db 2040 8 -} {3FE0000000000000} -do_test nan-3.2 { - db eval { - SELECT x, typeof(x) FROM t1 - } -} {0.5 real} -do_test nan-3.3 { - db close - hexio_write test.db 2040 FFF8000000000000 - sqlite3 db test.db - db eval {SELECT x, typeof(x) FROM t1} -} {{} null} -do_test nan-3.4 { - db close - hexio_write test.db 2040 7FF8000000000000 - sqlite3 db test.db - db eval {SELECT x, typeof(x) FROM t1} -} {{} null} -do_test nan-3.5 { - db close - hexio_write test.db 2040 FFFFFFFFFFFFFFFF - sqlite3 db test.db - db eval {SELECT x, typeof(x) FROM t1} -} {{} null} -do_test nan-3.6 { - db close - hexio_write test.db 2040 7FFFFFFFFFFFFFFF - sqlite3 db test.db - db eval {SELECT x, typeof(x) FROM t1} -} {{} null} +if {![nonzero_reserved_bytes]} { + do_test nan-3.1 { + db eval { + DELETE FROM t1; + INSERT INTO t1 VALUES(0.5); + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + VACUUM; + } + hexio_read test.db 2040 8 + } {3FE0000000000000} + do_test nan-3.2 { + db eval { + SELECT x, typeof(x) FROM t1 + } + } {0.5 real} + do_test nan-3.3 { + db close + hexio_write test.db 2040 FFF8000000000000 + sqlite3 db test.db + db eval {SELECT x, typeof(x) FROM t1} + } {{} null} + do_test nan-3.4 { + db close + hexio_write test.db 2040 7FF8000000000000 + sqlite3 db test.db + db eval {SELECT x, typeof(x) FROM t1} + } {{} null} + do_test nan-3.5 { + db close + hexio_write test.db 2040 FFFFFFFFFFFFFFFF + sqlite3 db test.db + db eval {SELECT x, typeof(x) FROM t1} + } {{} null} + do_test nan-3.6 { + db close + hexio_write test.db 2040 7FFFFFFFFFFFFFFF + sqlite3 db test.db + db eval {SELECT x, typeof(x) FROM t1} + } {{} null} +} # Verify that the sqlite3AtoF routine is able to handle extreme # numbers. diff --git a/test/pageropt.test b/test/pageropt.test index 7191661ba5..f8f5c71892 100644 --- a/test/pageropt.test +++ b/test/pageropt.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +do_not_use_codec ifcapable {!pager_pragmas||secure_delete||direct_read} { finish_test diff --git a/test/pragma.test b/test/pragma.test index befa5cf548..acbe74599e 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -1741,73 +1741,75 @@ forcedelete data_dir } ;# endif windows database_may_be_corrupt +if {![nonzero_reserved_bytes]} { -do_test 21.1 { - # Create a corrupt database in testerr.db. And a non-corrupt at test.db. - # - db close - forcedelete test.db - sqlite3 db test.db - execsql { - PRAGMA page_size = 1024; - PRAGMA auto_vacuum = 0; - CREATE TABLE t1(a PRIMARY KEY, b); - INSERT INTO t1 VALUES(1, 1); - } - for {set i 0} {$i < 10} {incr i} { - execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } - } - db close - forcecopy test.db testerr.db - hexio_write testerr.db 15000 [string repeat 55 100] -} {100} - -set mainerr {*** in database main *** + do_test 21.1 { + # Create a corrupt database in testerr.db. And a non-corrupt at test.db. + # + db close + forcedelete test.db + sqlite3 db test.db + execsql { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 1); + } + for {set i 0} {$i < 10} {incr i} { + execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } + } + db close + forcecopy test.db testerr.db + hexio_write testerr.db 15000 [string repeat 55 100] + } {100} + + set mainerr {*** in database main *** Multiple uses for byte 672 of page 15} -set auxerr {*** in database aux *** + set auxerr {*** in database aux *** Multiple uses for byte 672 of page 15} - -set mainerr {/{\*\*\* in database main \*\*\* + + set mainerr {/{\*\*\* in database main \*\*\* Multiple uses for byte 672 of page 15}.*/} -set auxerr {/{\*\*\* in database aux \*\*\* + set auxerr {/{\*\*\* in database aux \*\*\* Multiple uses for byte 672 of page 15}.*/} - -do_test 22.2 { - catch { db close } - sqlite3 db testerr.db - execsql { PRAGMA integrity_check } -} $mainerr - -do_test 22.3.1 { - catch { db close } - sqlite3 db test.db - execsql { - ATTACH 'testerr.db' AS 'aux'; - PRAGMA integrity_check; - } -} $auxerr -do_test 22.3.2 { - execsql { PRAGMA main.integrity_check; } -} {ok} -do_test 22.3.3 { - execsql { PRAGMA aux.integrity_check; } -} $auxerr - -do_test 22.4.1 { - catch { db close } - sqlite3 db testerr.db - execsql { - ATTACH 'test.db' AS 'aux'; - PRAGMA integrity_check; - } -} $mainerr -do_test 22.4.2 { - execsql { PRAGMA main.integrity_check; } -} $mainerr -do_test 22.4.3 { - execsql { PRAGMA aux.integrity_check; } -} {ok} - + + do_test 22.2 { + catch { db close } + sqlite3 db testerr.db + execsql { PRAGMA integrity_check } + } $mainerr + + do_test 22.3.1 { + catch { db close } + sqlite3 db test.db + execsql { + ATTACH 'testerr.db' AS 'aux'; + PRAGMA integrity_check; + } + } $auxerr + do_test 22.3.2 { + execsql { PRAGMA main.integrity_check; } + } {ok} + do_test 22.3.3 { + execsql { PRAGMA aux.integrity_check; } + } $auxerr + + do_test 22.4.1 { + catch { db close } + sqlite3 db testerr.db + execsql { + ATTACH 'test.db' AS 'aux'; + PRAGMA integrity_check; + } + } $mainerr + do_test 22.4.2 { + execsql { PRAGMA main.integrity_check; } + } $mainerr + do_test 22.4.3 { + execsql { PRAGMA aux.integrity_check; } + } {ok} +} + db close forcedelete test.db test.db-wal test.db-journal sqlite3 db test.db diff --git a/test/pragma3.test b/test/pragma3.test index b7ea4d3fc6..1a67d72350 100644 --- a/test/pragma3.test +++ b/test/pragma3.test @@ -15,6 +15,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +do_not_use_codec do_execsql_test pragma3-100 { PRAGMA data_version; diff --git a/test/stat.test b/test/stat.test index 288153dbb3..95586e94bc 100644 --- a/test/stat.test +++ b/test/stat.test @@ -21,6 +21,10 @@ ifcapable !vtab||!compound { return } +# This module uses hard-coded results that depend on exact measurements of +# pages sizes at the byte level, and hence will not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} set ::asc 1 proc a_string {n} { string range [string repeat [incr ::asc]. $n] 1 $n } diff --git a/test/tclsqlite.test b/test/tclsqlite.test index 8d7fea0d2a..d5c078de15 100644 --- a/test/tclsqlite.test +++ b/test/tclsqlite.test @@ -22,10 +22,9 @@ source $testdir/tester.tcl # Check the error messages generated by tclsqlite # +set r "sqlite_orig HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" if {[sqlite3 -has-codec]} { - set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?" -} else { - set r "sqlite_orig HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" + append r " ?-key CODECKEY?" } do_test tcl-1.1 { set v [catch {sqlite3 bogus} msg] diff --git a/test/tkt4018.test b/test/tkt4018.test index 2bc41d47aa..77582a5c41 100644 --- a/test/tkt4018.test +++ b/test/tkt4018.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +do_not_use_codec proc testsql {sql} { set fd [open tf_main.tcl w] diff --git a/test/wal.test b/test/wal.test index 92b65e66ba..bb164bb76a 100644 --- a/test/wal.test +++ b/test/wal.test @@ -1378,6 +1378,7 @@ do_test wal-21.3 { #------------------------------------------------------------------------- # Test reading and writing of databases with different page-sizes. # +incr ::do_not_use_codec foreach pgsz {512 1024 2048 4096 8192 16384 32768 65536} { do_multiclient_test tn [string map [list %PGSZ% $pgsz] { do_test wal-22.%PGSZ%.$tn.1 { @@ -1398,6 +1399,7 @@ foreach pgsz {512 1024 2048 4096 8192 16384 32768 65536} { } {0} }] } +incr ::do_not_use_codec -1 #------------------------------------------------------------------------- # Test that when 1 or more pages are recovered from a WAL file, diff --git a/test/wal5.test b/test/wal5.test index 360d9c911e..0f6dcfa6a7 100644 --- a/test/wal5.test +++ b/test/wal5.test @@ -18,6 +18,7 @@ source $testdir/tester.tcl source $testdir/lock_common.tcl source $testdir/wal_common.tcl ifcapable !wal {finish_test ; return } +do_not_use_codec set testprefix wal5 diff --git a/test/wal8.test b/test/wal8.test index 0682fce35b..3e5a0c2617 100644 --- a/test/wal8.test +++ b/test/wal8.test @@ -27,6 +27,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix wal8 ifcapable !wal {finish_test ; return } +do_not_use_codec db close forcedelete test.db test.db-wal diff --git a/test/walbak.test b/test/walbak.test index 8d4ee01175..0e0f999534 100644 --- a/test/walbak.test +++ b/test/walbak.test @@ -240,6 +240,7 @@ foreach {tn setup} { } } { + if {$tn==4 && [sqlite3 -has-codec]} continue foreach f [glob -nocomplain test.db*] { forcedelete $f } eval $setup diff --git a/test/walro.test b/test/walro.test index 6d920b1e24..f46e44d4cb 100644 --- a/test/walro.test +++ b/test/walro.test @@ -212,7 +212,7 @@ do_multiclient_test tn { INSERT INTO t2 SELECT x||y, y||x FROM t2; } file size test.db-wal - } {147800} + } [expr {[nonzero_reserved_bytes]?148848:147800}] do_test 1.4.4.2 { csql1 { SELECT * FROM t1 } } {0 {a b c d e f g h i j k l 1 2 3 4 5 6}} From 4a8a64672348245df8244997144d2db3f362d852 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 20:49:24 +0000 Subject: [PATCH 49/57] Changing page size using VACUUM or backup is not allowed with a codec attached. FossilOrigin-Name: 92be06c1a828d56652fa5269a3029f8cb029b2cd --- manifest | 14 ++++---- manifest.uuid | 2 +- test/pager1.test | 85 +++++++++++++++++++++++++++++++-------------- test/superlock.test | 24 +++++++++---- 4 files changed, 83 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index 0391aaeca7..3b3c5f3c3b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\stest\sscript\sfixes\sfrom\strunk. -D 2016-03-14T18:42:04.674 +C Changing\spage\ssize\susing\sVACUUM\sor\sbackup\sis\snot\sallowed\swith\sa\scodec\sattached. +D 2016-03-14T20:49:24.177 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -937,7 +937,7 @@ F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3 F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f -F test/pager1.test f49df1a8b0e38b9ee3a7dd2ab4d427507b7314ce +F test/pager1.test 841868017e9dd3cb459b8d78862091a7d9cff21d F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71 F test/pager3.test 3856d9c80839be0668efee1b74811b1b7f7fc95f F test/pager4.test a122e9e6925d5b23b31e3dfef8c6a44bbf19590e @@ -1072,7 +1072,7 @@ F test/subquery2.test 438f8a7da1457277b22e4176510f7659b286995f F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 -F test/superlock.test 168011a6730aee70c28ea8d5e1c0592de4026f79 +F test/superlock.test ec94f0556b6488d97f71c79f9061ae08d9ab8f12 F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test 2f607e1821aa3af3c5c53b58835c05e511c95899 F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 99b9d7eef68fd6d5c9eecb5fbe3dfe002c1ca4a8 f7480e33eb82f2eae219d17ce46cd2d4edac07d2 -R a4b3be370b53beddc257d6f309680c72 +P ea1d2cddd59192251ee5fd912b190cded4959879 +R 24275616ba2669073b7ddeb77ba67682 U drh -Z 068814209d932469f07bb4748200130f +Z 86d93a0053c6301f416af4041023113a diff --git a/manifest.uuid b/manifest.uuid index 873981d4c5..ca6831f8bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ea1d2cddd59192251ee5fd912b190cded4959879 \ No newline at end of file +92be06c1a828d56652fa5269a3029f8cb029b2cd \ No newline at end of file diff --git a/test/pager1.test b/test/pager1.test index bc9ad83fd4..c25c837b67 100644 --- a/test/pager1.test +++ b/test/pager1.test @@ -1396,26 +1396,47 @@ do_test pager1-9.3.1 { execsql { PRAGMA page_size = 1024 } for {set ii 0} {$ii < 4} {incr ii} { execsql "CREATE TABLE t${ii}(a, b)" } } {} -do_test pager1-9.3.2 { - sqlite3 db2 test.db2 - - execsql { - PRAGMA page_size = 4096; - PRAGMA synchronous = OFF; - CREATE TABLE t1(a, b); - CREATE TABLE t2(a, b); - } db2 - - sqlite3_backup B db2 main db main - B step 30 - list [B step 10000] [B finish] -} {SQLITE_DONE SQLITE_OK} -do_test pager1-9.3.3 { - db2 close - db close - tv delete - file size test.db2 -} [file size test.db] +if {[nonzero_reserved_bytes]} { + # backup with a page size changes is not possible with the codec + # + do_test pager1-9.3.2codec { + sqlite3 db2 test.db2 + execsql { + PRAGMA page_size = 4096; + PRAGMA synchronous = OFF; + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + } db2 + sqlite3_backup B db2 main db main + B step 30 + list [B step 10000] [B finish] + } {SQLITE_READONLY SQLITE_READONLY} + do_test pager1-9.3.3codec { + db2 close + db close + tv delete + file size test.db2 + } [file size test.db2] +} else { + do_test pager1-9.3.2 { + sqlite3 db2 test.db2 + execsql { + PRAGMA page_size = 4096; + PRAGMA synchronous = OFF; + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + } db2 + sqlite3_backup B db2 main db main + B step 30 + list [B step 10000] [B finish] + } {SQLITE_DONE SQLITE_OK} + do_test pager1-9.3.3 { + db2 close + db close + tv delete + file size test.db2 + } [file size test.db] +} do_test pager1-9.4.1 { faultsim_delete_and_reopen @@ -2447,13 +2468,23 @@ do_test pager1-29.1 { } file size test.db } [expr 1024*3] -do_test pager1-29.2 { - execsql { - PRAGMA page_size = 4096; - VACUUM; - } - file size test.db -} [expr 4096*3] +if {[nonzero_reserved_bytes]} { + # VACUUM with size changes is not possible with the codec. + do_test pager1-29.2 { + catchsql { + PRAGMA page_size = 4096; + VACUUM; + } + } {1 {attempt to write a readonly database}} +} else { + do_test pager1-29.2 { + execsql { + PRAGMA page_size = 4096; + VACUUM; + } + file size test.db + } [expr 4096*3] +} #------------------------------------------------------------------------- # Test that if an empty database file (size 0 bytes) is opened in diff --git a/test/superlock.test b/test/superlock.test index 1e4a4a78d9..704b0677a1 100644 --- a/test/superlock.test +++ b/test/superlock.test @@ -239,13 +239,23 @@ db_swap test.db2 test.db do_catchsql_test 6.9 { SELECT * FROM t1 } {0 {1 2 3 4}} do_catchsql_test 6.10 { SELECT * FROM t2 } {1 {no such table: t2}} -do_execsql_test 6.11 { - PRAGMA journal_mode = delete; - PRAGMA page_size = 512; - VACUUM; - PRAGMA journal_mode = wal; - INSERT INTO t1 VALUES(5, 6); -} {delete wal} +if {[nonzero_reserved_bytes]} { + # Vacuum with a size change is not allowed with the codec + do_execsql_test 6.11codec { + PRAGMA journal_mode = delete; + VACUUM; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(5, 6); + } {delete wal} +} else { + do_execsql_test 6.11 { + PRAGMA journal_mode = delete; + PRAGMA page_size = 512; + VACUUM; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(5, 6); + } {delete wal} +} db_swap test.db2 test.db do_catchsql_test 6.12 { SELECT * FROM t1 } {1 {no such table: t1}} From a580936383cd6fd971b9895bca635b1aa6d72ac3 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 14 Mar 2016 21:26:25 +0000 Subject: [PATCH 50/57] Fix the permutations.test script so that it works again. FossilOrigin-Name: 9f194f90c07d5415b1d6bb10ec049f74999d6885 --- manifest | 13 ++++++------- manifest.uuid | 2 +- test/permutations.test | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 7a5dde7ec7..056a1fb6f3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\stest\sscripts\sso\sthat\sthey\swork\swith\sSEE. -D 2016-03-14T21:12:26.457 +C Fix\sthe\spermutations.test\sscript\sso\sthat\sit\sworks\sagain. +D 2016-03-14T21:26:25.596 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -950,7 +950,7 @@ F test/parser1.test 222b5cbf3e2e659fec1bf7d723488c8b9c94f1d0 F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff -F test/permutations.test 64abe58d53cde4adcfb881e37aa5ea1b2a980e58 +F test/permutations.test af8067e4b6d684518956f8e2a744f42bde99014d F test/pragma.test afbf028be1c35b68f57db8eb015c4a3c59d8f28e F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 3f1984a04657331f838df5c519b443c2088df922 @@ -1456,8 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f7480e33eb82f2eae219d17ce46cd2d4edac07d2 92be06c1a828d56652fa5269a3029f8cb029b2cd -R 24275616ba2669073b7ddeb77ba67682 -T +closed 92be06c1a828d56652fa5269a3029f8cb029b2cd +P f4693ba4bbd9738b45012cf507fc0d7b6d04b7ee +R b91725f8858bc448d609dcaeb28fa81e U drh -Z d1492fd2b8bf4cccc192885ce03fdf82 +Z 51ddcfc985bc0e936856bdb8a64dca36 diff --git a/manifest.uuid b/manifest.uuid index 39aab6c8e0..bac1f45a16 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f4693ba4bbd9738b45012cf507fc0d7b6d04b7ee \ No newline at end of file +9f194f90c07d5415b1d6bb10ec049f74999d6885 \ No newline at end of file diff --git a/test/permutations.test b/test/permutations.test index 6c02af8fbe..37736feb81 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -1068,12 +1068,12 @@ proc help {} { exit -1 } -if {[info script] == $argv0} { +if {[file tail $argv0] == "permutations.test"} { proc main {argv} { if {[llength $argv]==0} { help } else { - set suite [lindex $argv 0] + set suite [file tail [lindex $argv 0]] if {[info exists ::testspec($suite)]==0} help set extra "" if {[llength $argv]>1} { set extra [list -files [lrange $argv 1 end]] } From 089555c8e9fabb1b19db0ad03b5b31936af7a98f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 15 Mar 2016 09:55:44 +0000 Subject: [PATCH 51/57] Fix the shellN.test test scripts so that they work with the --testdir option. FossilOrigin-Name: 051c61ebae921b70f843c55aacf046a9922cc187 --- manifest | 24 ++++++++++++------------ manifest.uuid | 2 +- test/shell1.test | 10 +--------- test/shell2.test | 10 +--------- test/shell3.test | 10 +--------- test/shell4.test | 10 +--------- test/shell5.test | 10 +--------- test/tester.tcl | 18 ++++++++++++++++++ 8 files changed, 36 insertions(+), 58 deletions(-) diff --git a/manifest b/manifest index 056a1fb6f3..c36b917a58 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\spermutations.test\sscript\sso\sthat\sit\sworks\sagain. -D 2016-03-14T21:26:25.596 +C Fix\sthe\sshellN.test\stest\sscripts\sso\sthat\sthey\swork\swith\sthe\s--testdir\soption. +D 2016-03-15T09:55:44.853 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -1025,11 +1025,11 @@ F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/shared_err.test 2f2aee20db294b9924e81f6ccbe60f19e21e8506 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test a45b424ec23a4b946848ff9e1af5186c677162ab -F test/shell2.test 12b8bf901b0e3a8ac58cf5c0c63a0a388d4d1862 -F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 -F test/shell4.test f43e250139dc5dc5f0f2ec1752c50284a1ede102 -F test/shell5.test c04e9f9f948305706b88377c464c7f08ce7479f9 +F test/shell1.test e7dac9830b7d80432be9cebfae06eff9c18675f5 +F test/shell2.test 2e7a32c9ee03c6398478637d72416d5b9ebd9777 +F test/shell3.test c39453d3012a39ffec944566eca8a6bda10a2284 +F test/shell4.test 69995ee1cc278eb149aa8746ce1f935f4eaf98b9 +F test/shell5.test 50a732c1c2158b1cd62cf53975ce1ea7ce6b9dc9 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5 F test/shrink.test 1b4330b1fd9e818c04726d45cb28db73087535ce @@ -1085,7 +1085,7 @@ F test/tclsqlite.test c6d9f546f79d15d0134c1e06583fb3ee0c3afad3 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 -F test/tester.tcl d6dee24773e20320ab64d39bb5ce6e1a91b6029e +F test/tester.tcl 859a7ccbe5bd65f0f8b524cd51c318d3edcd3008 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f4693ba4bbd9738b45012cf507fc0d7b6d04b7ee -R b91725f8858bc448d609dcaeb28fa81e -U drh -Z 51ddcfc985bc0e936856bdb8a64dca36 +P 9f194f90c07d5415b1d6bb10ec049f74999d6885 +R 50980fd60bfbb727ae154c36fe3906ce +U dan +Z f0681fd41f2ae1a8be1bbfb650e8fc11 diff --git a/manifest.uuid b/manifest.uuid index bac1f45a16..77d14b9109 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f194f90c07d5415b1d6bb10ec049f74999d6885 \ No newline at end of file +051c61ebae921b70f843c55aacf046a9922cc187 \ No newline at end of file diff --git a/test/shell1.test b/test/shell1.test index 1b9ea1d383..1f1f3de320 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -21,15 +21,7 @@ # set testdir [file dirname $argv0] source $testdir/tester.tcl -if {$tcl_platform(platform)=="windows"} { - set CLI "sqlite3.exe" -} else { - set CLI "./sqlite3" -} -if {![file executable $CLI]} { - finish_test - return -} +set CLI [test_find_cli] db close forcedelete test.db test.db-journal test.db-wal sqlite3 db test.db diff --git a/test/shell2.test b/test/shell2.test index 616610bd4b..9388b719b3 100644 --- a/test/shell2.test +++ b/test/shell2.test @@ -20,15 +20,7 @@ # set testdir [file dirname $argv0] source $testdir/tester.tcl -if {$tcl_platform(platform)=="windows"} { - set CLI "sqlite3.exe" -} else { - set CLI "./sqlite3" -} -if {![file executable $CLI]} { - finish_test - return -} +set CLI [test_find_cli] db close forcedelete test.db test.db-journal test.db-wal sqlite3 db test.db diff --git a/test/shell3.test b/test/shell3.test index ce1fd4ecb5..3ded8f5ccd 100644 --- a/test/shell3.test +++ b/test/shell3.test @@ -21,15 +21,7 @@ # set testdir [file dirname $argv0] source $testdir/tester.tcl -if {$tcl_platform(platform)=="windows"} { - set CLI "sqlite3.exe" -} else { - set CLI "./sqlite3" -} -if {![file executable $CLI]} { - finish_test - return -} +set CLI [test_find_cli] db close forcedelete test.db test.db-journal test.db-wal sqlite3 db test.db diff --git a/test/shell4.test b/test/shell4.test index 18e7d7fdf6..3e4ae55816 100644 --- a/test/shell4.test +++ b/test/shell4.test @@ -21,15 +21,7 @@ # set testdir [file dirname $argv0] source $testdir/tester.tcl -if {$tcl_platform(platform)=="windows"} { - set CLI "sqlite3.exe" -} else { - set CLI "./sqlite3" -} -if {![file executable $CLI]} { - finish_test - return -} +set CLI [test_find_cli] db close forcedelete test.db test.db-journal test.db-wal sqlite3 db test.db diff --git a/test/shell5.test b/test/shell5.test index b921accca5..bb2511a525 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -21,15 +21,7 @@ # set testdir [file dirname $argv0] source $testdir/tester.tcl -if {$tcl_platform(platform)=="windows"} { - set CLI "sqlite3.exe" -} else { - set CLI "./sqlite3" -} -if {![file executable $CLI]} { - finish_test - return -} +set CLI [test_find_cli] db close forcedelete test.db test.db-journal test.db-wal diff --git a/test/tester.tcl b/test/tester.tcl index 3a881138e2..1c83e34c0d 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -2136,6 +2136,24 @@ proc test_restore_config_pagecache {} { sqlite3 db test.db } +# Find the name of the 'shell' executable (e.g. "sqlite3.exe") to use for +# the tests in shell[1-5].test. If no such executable can be found, invoke +# [finish_test ; return] in the callers context. +# +proc test_find_cli {} { + if {$::tcl_platform(platform)=="windows"} { + set ret "sqlite3.exe" + } else { + set ret "sqlite3" + } + set ret [file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $ret]] + if {![file executable $ret]} { + finish_test + return -code return + } + return $ret +} + # If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set # to non-zero, then set the global variable $AUTOVACUUM to 1. set AUTOVACUUM $sqlite_options(default_autovacuum) From 82f525406af6e0ca6887a82c8bb561fac610fa59 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 15 Mar 2016 12:37:08 +0000 Subject: [PATCH 52/57] More test-case changes so that everything works when the reserved_bytes value in the header is non-zero. FossilOrigin-Name: 2fd095b14b03a508169bba710d2e8e2addf4b8f5 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- test/corrupt2.test | 44 +++++++++++++++++++++++--------------------- test/filefmt.test | 16 ++++++++++------ test/pageropt.test | 4 ++++ test/wal5.test | 6 +++--- 6 files changed, 51 insertions(+), 41 deletions(-) diff --git a/manifest b/manifest index c36b917a58..5b830ffdfa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sshellN.test\stest\sscripts\sso\sthat\sthey\swork\swith\sthe\s--testdir\soption. -D 2016-03-15T09:55:44.853 +C More\stest-case\schanges\sso\sthat\severything\sworks\swhen\sthe\sreserved_bytes\nvalue\sin\sthe\sheader\sis\snon-zero. +D 2016-03-15T12:37:08.820 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -548,7 +548,7 @@ F test/conflict2.test bb0b94cf7196c64a3cbd815c66d3ee98c2fecd9c F test/conflict3.test dec0634c0f31dec9a4b01c63063e939f0cd21b6b F test/contrib01.test 2a1cbc0f2f48955d7d073f725765da6fbceda6b4 F test/corrupt.test 141c39ea650c1365e85a49e402fa05cb9617fb97 -F test/corrupt2.test cb787825d761b0f869764d6990531382840de872 +F test/corrupt2.test e4964cee73dda57a90958e0087a6b388b1d9cb58 F test/corrupt3.test e676f478fe602915d721472811f6f410b75ddc7e F test/corrupt4.test 8d1d86b850fcc43e417450454f2044e52d55778a F test/corrupt5.test 8ead52af76006f3286e9396cb41898018ccea107 @@ -638,7 +638,7 @@ F test/extension01.test 00d13cec817f331a687a243e0e5a2d87b0e358c9 F test/extraquick.test cb254400bd42bfb777ff675356aabf3287978f79 F test/fallocate.test 3e979af17dfa7e5e9dda5eba1a696c04fa9d47f7 F test/filectrl.test 7c13f96457435238da99aff7343ad6a3a4885787 -F test/filefmt.test cb34663f126cbc2d358af552dcaf5c72769b0146 +F test/filefmt.test e4edbdc637ca9576ccf4337a3cce627d9df7a56c F test/fkey1.test 13e3d48236a2b9f5c5ebd232eef9b3ab682a8a2c F test/fkey2.test f3d27ecba480a348c328965d154214719bb158a9 F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49 @@ -944,7 +944,7 @@ F test/pager4.test a122e9e6925d5b23b31e3dfef8c6a44bbf19590e F test/pagerfault.test ae9ee0db5a30aecda9db8290ce3dd12e5f7bbaa1 F test/pagerfault2.test caf4c7facb914fd3b03a17b31ae2b180c8d6ca1f F test/pagerfault3.test 1003fcda009bf48a8e22a516e193b6ef0dd1bbd8 -F test/pageropt.test f8d840f0fed84854dbd12b4c17fb3506eeb8224c +F test/pageropt.test 84e4cc5cbca285357f7906e99b21be4f2bf5abc0 F test/pagesize.test 5769fc62d8c890a83a503f67d47508dfdc543305 F test/parser1.test 222b5cbf3e2e659fec1bf7d723488c8b9c94f1d0 F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b @@ -1307,7 +1307,7 @@ F test/wal.test 613efec03e517e1775d86b993a54877d2e29a477 F test/wal2.test 25ae059e900dbb584e0775627e45415ba5940df1 F test/wal3.test 5dd734147f1f8f958c5261a1f2775d346d7013ce F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c -F test/wal5.test 22cb252502c5ff851925add2ca8a7e2af012e1d6 +F test/wal5.test 9c11da7aeccd83a46d79a556ad11a18d3cb15aa9 F test/wal6.test a9d6aa635b9d63607dabdc11406f5f96ca986635 F test/wal64k.test 163655ecd2cb8afef4737cac2a40fdd2eeaf20b8 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9f194f90c07d5415b1d6bb10ec049f74999d6885 -R 50980fd60bfbb727ae154c36fe3906ce -U dan -Z f0681fd41f2ae1a8be1bbfb650e8fc11 +P 051c61ebae921b70f843c55aacf046a9922cc187 +R 1b522ee9926e242e3422d1eddaaf0fbf +U drh +Z 3fc58440746cd83f06c07d7c16cdd74a diff --git a/manifest.uuid b/manifest.uuid index 77d14b9109..e76d63af73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -051c61ebae921b70f843c55aacf046a9922cc187 \ No newline at end of file +2fd095b14b03a508169bba710d2e8e2addf4b8f5 \ No newline at end of file diff --git a/test/corrupt2.test b/test/corrupt2.test index 9bd29cf90f..efeb26bc8a 100644 --- a/test/corrupt2.test +++ b/test/corrupt2.test @@ -346,27 +346,29 @@ ifcapable autovacuum { } {1 {database disk image is malformed}} } - corruption_test -sqlprep { - PRAGMA auto_vacuum = 1; - PRAGMA page_size = 1024; - CREATE TABLE t1(a INTEGER PRIMARY KEY, b); - INSERT INTO t1 VALUES(1, randomblob(2500)); - DELETE FROM t1 WHERE a = 1; - } -corrupt { - set nAppend [expr 1024*207 - [file size corrupt.db]] - set fd [open corrupt.db r+] - seek $fd 0 end - puts -nonewline $fd [string repeat x $nAppend] - close $fd - hexio_write corrupt.db 28 00000000 - } -test { - do_test corrupt2-6.4 { - catchsql " - $::presql - BEGIN EXCLUSIVE; - COMMIT; - " - } {1 {database disk image is malformed}} + if {![nonzero_reserved_bytes]} { + corruption_test -sqlprep { + PRAGMA auto_vacuum = 1; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + set nAppend [expr 1024*207 - [file size corrupt.db]] + set fd [open corrupt.db r+] + seek $fd 0 end + puts -nonewline $fd [string repeat x $nAppend] + close $fd + hexio_write corrupt.db 28 00000000 + } -test { + do_test corrupt2-6.4 { + catchsql " + $::presql + BEGIN EXCLUSIVE; + COMMIT; + " + } {1 {database disk image is malformed}} + } } } diff --git a/test/filefmt.test b/test/filefmt.test index 2df1424436..087a955c39 100644 --- a/test/filefmt.test +++ b/test/filefmt.test @@ -144,9 +144,11 @@ do_execsql_test filefmt-2.1.1 { CREATE TABLE t2(a); INSERT INTO t2 VALUES(1); } {} -do_test filefmt-2.1.2 { - hexio_read test.db 28 4 -} {00000009} +if {![nonzero_reserved_bytes]} { + do_test filefmt-2.1.2 { + hexio_read test.db 28 4 + } {00000009} +} do_test filefmt-2.1.3 { sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } @@ -170,9 +172,11 @@ do_execsql_test filefmt-2.2.1 { CREATE TABLE t2(a); INSERT INTO t2 VALUES(1); } {} -do_test filefmt-2.2.2 { - hexio_read test.db 28 4 -} {00000009} +if {![nonzero_reserved_bytes]} { + do_test filefmt-2.2.2 { + hexio_read test.db 28 4 + } {00000009} +} do_test filefmt-2.2.3 { sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } diff --git a/test/pageropt.test b/test/pageropt.test index f8f5c71892..f58b8ee781 100644 --- a/test/pageropt.test +++ b/test/pageropt.test @@ -23,6 +23,10 @@ ifcapable {!pager_pragmas||secure_delete||direct_read} { return } +# A non-zero reserved_bytes value changes the number of pages in the +# database file, which messes up the results in this test. +if {[nonzero_reserved_bytes]} {finish_test; return;} + # Run the SQL statement supplied by the argument and return # the results. Prepend four integers to the beginning of the # result which are diff --git a/test/wal5.test b/test/wal5.test index 0f6dcfa6a7..50c517286a 100644 --- a/test/wal5.test +++ b/test/wal5.test @@ -141,13 +141,13 @@ foreach {testprefix do_wal_checkpoint} { do_test 1.$tn.7 { reopen_all list [db_page_count] [wal_page_count] $::nBusyHandler - } {7 0 0} + } [expr {[nonzero_reserved_bytes]?"/# # 0/":"7 0 0"}] do_test 1.$tn.8 { sql2 { BEGIN ; SELECT x FROM t1 } } {1 2 3 4 5} do_test 1.$tn.9 { sql1 { INSERT INTO t1 VALUES(6, zeroblob(1200)) } list [db_page_count] [wal_page_count] $::nBusyHandler - } {7 5 0} + } [expr {[nonzero_reserved_bytes]?"/# # #/":"7 5 0"}] do_test 1.$tn.10 { sql3 { BEGIN ; SELECT x FROM t1 } } {1 2 3 4 5 6} set ::busy_handler_script { @@ -158,7 +158,7 @@ foreach {testprefix do_wal_checkpoint} { do_test 1.$tn.11 { code1 { do_wal_checkpoint db -mode restart } list [db_page_count] [wal_page_count] $::nBusyHandler - } {10 5 8} + } [expr {[nonzero_reserved_bytes]?"/# # #/":"10 5 8"}] do_test 1.$tn.12 { set ::db_file_size } 10 } From 0ff47e9e1b74e270648cac1ea72f9bcf4e35031d Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 15 Mar 2016 17:52:12 +0000 Subject: [PATCH 53/57] Implement FROM-clause subqueries as co-routines whenever they are guaranteed to be the outer-most loop of the join. FossilOrigin-Name: c7bae50bdccb5bcf3bc22e8ac5bb6725ef13db39 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 20 +++++++++++++++++--- test/select4.test | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 5b830ffdfa..61ece923e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\stest-case\schanges\sso\sthat\severything\sworks\swhen\sthe\sreserved_bytes\nvalue\sin\sthe\sheader\sis\snon-zero. -D 2016-03-15T12:37:08.820 +C Implement\sFROM-clause\ssubqueries\sas\sco-routines\swhenever\sthey\sare\sguaranteed\nto\sbe\sthe\souter-most\sloop\sof\sthe\sjoin. +D 2016-03-15T17:52:12.224 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -350,7 +350,7 @@ F src/printf.c 63e6fb12bbe702dd664dc3703776c090383a5a26 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c b8f7174e5f8c33c44ded3a25a973d0bb89228c20 F src/rowset.c 9fe4b3ad7cc00944386bb600233d8f523de07a6e -F src/select.c 137b31daa84d57d67847bf621bb54f3353e2077b +F src/select.c 6dd2097bb158efe3b8d68683dcc3b4a49e907a34 F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 0235586b3fb639e85998d495c90f007657fd82af F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -999,7 +999,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test 453631158540e5f685b81cac5b7e8bd8c6b4c5fc +F test/select4.test d926792a5e4d88fef0ddcddeb45d27ce75f7296c F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 95e370c42d47c3c52377d05e9ffc01ccff7c1f61 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 051c61ebae921b70f843c55aacf046a9922cc187 -R 1b522ee9926e242e3422d1eddaaf0fbf +P 2fd095b14b03a508169bba710d2e8e2addf4b8f5 +R dae03fc18d1aaaa839efcf6d42490a7e U drh -Z 3fc58440746cd83f06c07d7c16cdd74a +Z 042547ad8e59422492ad781582901ed5 diff --git a/manifest.uuid b/manifest.uuid index e76d63af73..b2a61f89c1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2fd095b14b03a508169bba710d2e8e2addf4b8f5 \ No newline at end of file +c7bae50bdccb5bcf3bc22e8ac5bb6725ef13db39 \ No newline at end of file diff --git a/src/select.c b/src/select.c index c9bc389b2f..a62581efc1 100644 --- a/src/select.c +++ b/src/select.c @@ -4970,10 +4970,24 @@ int sqlite3Select( } /* Generate code to implement the subquery + ** + ** The subquery is implemented as a co-routine if all of these are true: + ** (1) The subquery is guaranteed to be the outer loop (so that it + ** does not need to be computed more than once) + ** (2) The ALL keyword after SELECT is omitted. (Applications are + ** allowed to say "SELECT ALL" instead of just "SELECT" to disable + ** the use of co-routines.) + ** (3) Co-routines are not disabled using sqlite3_test_control() + ** with SQLITE_TESTCTRL_OPTIMIZATIONS. + ** + ** TODO: Are there other reasons beside (1) to use a co-routine + ** implementation? */ - if( pTabList->nSrc==1 - && (p->selFlags & SF_All)==0 - && OptimizationEnabled(db, SQLITE_SubqCoroutine) + if( i==0 + && (pTabList->nSrc==1 + || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0) /* (1) */ + && (p->selFlags & SF_All)==0 /* (2) */ + && OptimizationEnabled(db, SQLITE_SubqCoroutine) /* (3) */ ){ /* Implement a co-routine that will return a single row of the result ** set on each invocation. diff --git a/test/select4.test b/test/select4.test index be8d0e0ab1..1f29f29073 100644 --- a/test/select4.test +++ b/test/select4.test @@ -12,7 +12,6 @@ # focus of this file is testing UNION, INTERSECT and EXCEPT operators # in SELECT statements. # -# $Id: select4.test,v 1.30 2009/04/16 00:24:24 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -936,4 +935,40 @@ do_execsql_test select4-15.1 { ORDER BY 1; } {1 33 456 2 33 789} +# Enhancement (2016-03-15): Use a co-routine for subqueries if the +# subquery is guaranteed to be the outer-most query +# +do_execsql_test select4-16.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, + PRIMARY KEY(a,b DESC)) WITHOUT ROWID; + + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c,d) + SELECT x%10, x/10, x, printf('xyz%dabc',x) FROM c; + + SELECT t3.c FROM + (SELECT a,max(b) AS m FROM t1 WHERE a>=5 GROUP BY a) AS t2 + JOIN t1 AS t3 + WHERE t2.a=t3.a AND t2.m=t3.b + ORDER BY t3.a; +} {95 96 97 98 99} +do_execsql_test select4-16.2 { + SELECT t3.c FROM + (SELECT a,max(b) AS m FROM t1 WHERE a>=5 GROUP BY a) AS t2 + CROSS JOIN t1 AS t3 + WHERE t2.a=t3.a AND t2.m=t3.b + ORDER BY t3.a; +} {95 96 97 98 99} +do_execsql_test select4-16.3 { + SELECT t3.c FROM + (SELECT a,max(b) AS m FROM t1 WHERE a>=5 GROUP BY a) AS t2 + LEFT JOIN t1 AS t3 + WHERE t2.a=t3.a AND t2.m=t3.b + ORDER BY t3.a; +} {95 96 97 98 99} + + + + finish_test From b7b91068ee0e5bc18d8f490056dd20f79a2f4d27 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 15 Mar 2016 19:10:39 +0000 Subject: [PATCH 54/57] In the Win32 VFS, use SQLITE_FCNTL_LAST_ERRNO instead of (the older) SQLITE_LAST_ERRNO. FossilOrigin-Name: 9463762c437488970a87093ef13131c39b2adadc --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_win.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 61ece923e2..e0adb2742c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Implement\sFROM-clause\ssubqueries\sas\sco-routines\swhenever\sthey\sare\sguaranteed\nto\sbe\sthe\souter-most\sloop\sof\sthe\sjoin. -D 2016-03-15T17:52:12.224 +C In\sthe\sWin32\sVFS,\suse\sSQLITE_FCNTL_LAST_ERRNO\sinstead\sof\s(the\solder)\sSQLITE_LAST_ERRNO. +D 2016-03-15T19:10:39.513 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -335,7 +335,7 @@ F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_unix.c f5bac8e74aaefc4ea520e43b4540793c3b8a9e8f -F src/os_win.c f0d7aa603eb6262143d7169a222aea07c4fca91d +F src/os_win.c cbf8c442a0d818d05bcf40b093cb3ebad435b9be F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 38718a019ca762ba4f6795425d5a54db70d1790d F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2fd095b14b03a508169bba710d2e8e2addf4b8f5 -R dae03fc18d1aaaa839efcf6d42490a7e -U drh -Z 042547ad8e59422492ad781582901ed5 +P c7bae50bdccb5bcf3bc22e8ac5bb6725ef13db39 +R 46123ac548d09b6e0ffa37ea5d80c14d +U mistachkin +Z d90a9a53fb7ea7a50e56b06b4f7c6bc4 diff --git a/manifest.uuid b/manifest.uuid index b2a61f89c1..14d2985670 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c7bae50bdccb5bcf3bc22e8ac5bb6725ef13db39 \ No newline at end of file +9463762c437488970a87093ef13131c39b2adadc \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index af6b1c814c..6ff50c554b 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -3257,7 +3257,7 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){ OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); return SQLITE_OK; } - case SQLITE_LAST_ERRNO: { + case SQLITE_FCNTL_LAST_ERRNO: { *(int*)pArg = (int)pFile->lastErrno; OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); return SQLITE_OK; From 98968b22c5c6b2b4c9fb89b8d7d0199a650044a0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 15 Mar 2016 22:00:39 +0000 Subject: [PATCH 55/57] Change the OP_IntegrityCk opcode to accept the list of root pages as an intarray argument in P4. Slightly smaller and faster. FossilOrigin-Name: 15e4a272df46cbad8e71b21551dc06a126d64d46 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/pragma.c | 28 ++++++++++++++++------------ src/vdbe.c | 17 +++++------------ 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index e0adb2742c..95e98afa0f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sWin32\sVFS,\suse\sSQLITE_FCNTL_LAST_ERRNO\sinstead\sof\s(the\solder)\sSQLITE_LAST_ERRNO. -D 2016-03-15T19:10:39.513 +C Change\sthe\sOP_IntegrityCk\sopcode\sto\saccept\sthe\slist\sof\sroot\spages\sas\san\nintarray\sargument\sin\sP4.\s\sSlightly\ssmaller\sand\sfaster. +D 2016-03-15T22:00:39.610 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -343,7 +343,7 @@ F src/parse.y 5ea8c81c5c41b27887f41b4a7e1c58470d7d3821 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 -F src/pragma.c c7061870c235702a513ce4152fe978faf3f282eb +F src/pragma.c 04baa9343771f913f1c86b2720f768be8a3ad52a F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c F src/prepare.c 22df6171aec1d86904ed2ad30c2348a5748aa04e F src/printf.c 63e6fb12bbe702dd664dc3703776c090383a5a26 @@ -416,7 +416,7 @@ F src/update.c 56b3db7edff0110360a12b76af97c39ebe3ea8b8 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c 34ef7be420f82415ec48131404995ddb6ee7502f F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52 -F src/vdbe.c 87ae3a5657fefed7875f3eb30e7ababd48013d71 +F src/vdbe.c 8cf45bb8da77d39f55d108e759d15a57acd0255c F src/vdbe.h c743791f723049db94f009e3e30958952bc2d512 F src/vdbeInt.h 49a74fe5ece206d2d8666ba9afaf1abeda5f123b F src/vdbeapi.c 95b1f8e527240a18a9aea41a655b013bf07a7009 @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c7bae50bdccb5bcf3bc22e8ac5bb6725ef13db39 -R 46123ac548d09b6e0ffa37ea5d80c14d -U mistachkin -Z d90a9a53fb7ea7a50e56b06b4f7c6bc4 +P 9463762c437488970a87093ef13131c39b2adadc +R 6817ca21db6938155940db404d48bb61 +U drh +Z e5f48f52274ef8efc53f2f946a6d2fff diff --git a/manifest.uuid b/manifest.uuid index 14d2985670..a7f49d3bce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9463762c437488970a87093ef13131c39b2adadc \ No newline at end of file +15e4a272df46cbad8e71b21551dc06a126d64d46 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 883ab60c67..70c2950c8e 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1439,6 +1439,7 @@ void sqlite3Pragma( for(i=0; inDb; i++){ HashElem *x; Hash *pTbls; + int *aRoot; int cnt = 0; if( OMIT_TEMPDB && i==1 ) continue; @@ -1452,31 +1453,34 @@ void sqlite3Pragma( /* Do an integrity check of the B-Tree ** - ** Begin by filling registers 2, 3, ... with the root pages numbers + ** Begin by finding the root pages numbers ** for all tables and indices in the database. */ assert( sqlite3SchemaMutexHeld(db, i, 0) ); pTbls = &db->aDb[i].pSchema->tblHash; - for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ + for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ Table *pTab = sqliteHashData(x); Index *pIdx; - if( HasRowid(pTab) ){ - sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); - VdbeComment((v, "%s", pTab->zName)); - cnt++; - } + if( HasRowid(pTab) ) cnt++; + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ cnt++; } + } + aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1)); + if( aRoot==0 ) break; + for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ + Table *pTab = sqliteHashData(x); + Index *pIdx; + if( HasRowid(pTab) ) aRoot[cnt++] = pTab->tnum; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ - sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt); - VdbeComment((v, "%s", pIdx->zName)); - cnt++; + aRoot[cnt++] = pIdx->tnum; } } + aRoot[cnt] = 0; /* Make sure sufficient number of registers have been allocated */ - pParse->nMem = MAX( pParse->nMem, cnt+8 ); + pParse->nMem = MAX( pParse->nMem, 14 ); /* Do the b-tree integrity checks */ - sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1); + sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY); sqlite3VdbeChangeP5(v, (u8)i); addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, diff --git a/src/vdbe.c b/src/vdbe.c index 3351a44551..6f4ac5713d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -5422,7 +5422,7 @@ case OP_DropTrigger: { #ifndef SQLITE_OMIT_INTEGRITY_CHECK -/* Opcode: IntegrityCk P1 P2 P3 * P5 +/* Opcode: IntegrityCk P1 P2 P3 P4 P5 ** ** Do an analysis of the currently open database. Store in ** register P1 the text of an error message describing any problems. @@ -5433,9 +5433,8 @@ case OP_DropTrigger: { ** In other words, the analysis stops as soon as reg(P1) errors are ** seen. Reg(P1) is updated with the number of errors remaining. ** -** The root page numbers of all tables in the database are integer -** stored in reg(P1), reg(P1+1), reg(P1+2), .... There are P2 tables -** total. +** The root page numbers of all tables in the database are integers +** stored in P4_INTARRAY argument. ** ** If P5 is not zero, the check is done on the auxiliary database ** file, not the main database file. @@ -5445,30 +5444,24 @@ case OP_DropTrigger: { case OP_IntegrityCk: { int nRoot; /* Number of tables to check. (Number of root pages.) */ int *aRoot; /* Array of rootpage numbers for tables to be checked */ - int j; /* Loop counter */ int nErr; /* Number of errors reported */ char *z; /* Text of the error report */ Mem *pnErr; /* Register keeping track of errors remaining */ assert( p->bIsReader ); nRoot = pOp->p2; + aRoot = pOp->p4.ai; assert( nRoot>0 ); - aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(nRoot+1) ); - if( aRoot==0 ) goto no_mem; + assert( aRoot[nRoot]==0 ); assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); pnErr = &aMem[pOp->p3]; assert( (pnErr->flags & MEM_Int)!=0 ); assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); pIn1 = &aMem[pOp->p1]; - for(j=0; jp5nDb ); assert( DbMaskTest(p->btreeMask, pOp->p5) ); z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot, (int)pnErr->u.i, &nErr); - sqlite3DbFree(db, aRoot); pnErr->u.i -= nErr; sqlite3VdbeMemSetNull(pIn1); if( nErr==0 ){ From c5db1d4b4c8978825ee79d660e6d7cf25fdd103d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 16 Mar 2016 00:36:19 +0000 Subject: [PATCH 56/57] Rearrange some internal fields in the sqlite3_stmt object to avoid a harmless TSAN warning. FossilOrigin-Name: e0b116edd64a55c971c368685aa343cb6beed0f1 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeInt.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 95e98afa0f..8154a2631d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sOP_IntegrityCk\sopcode\sto\saccept\sthe\slist\sof\sroot\spages\sas\san\nintarray\sargument\sin\sP4.\s\sSlightly\ssmaller\sand\sfaster. -D 2016-03-15T22:00:39.610 +C Rearrange\ssome\sinternal\sfields\sin\sthe\ssqlite3_stmt\sobject\sto\savoid\sa\sharmless\nTSAN\swarning. +D 2016-03-16T00:36:19.731 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -418,7 +418,7 @@ F src/util.c 34ef7be420f82415ec48131404995ddb6ee7502f F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52 F src/vdbe.c 8cf45bb8da77d39f55d108e759d15a57acd0255c F src/vdbe.h c743791f723049db94f009e3e30958952bc2d512 -F src/vdbeInt.h 49a74fe5ece206d2d8666ba9afaf1abeda5f123b +F src/vdbeInt.h f88d3115e9bde33b01d81f0dd26d8dd51f995991 F src/vdbeapi.c 95b1f8e527240a18a9aea41a655b013bf07a7009 F src/vdbeaux.c 2c15cf88de4df97428318c8cfac0dea873dae451 F src/vdbeblob.c 3b570b730109e8f653d9d2081649f6e7015113db @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9463762c437488970a87093ef13131c39b2adadc -R 6817ca21db6938155940db404d48bb61 +P 15e4a272df46cbad8e71b21551dc06a126d64d46 +R 82478b12d64974258326bdaae56626ca U drh -Z e5f48f52274ef8efc53f2f946a6d2fff +Z e403476d229295941bbcf1df1a4408f9 diff --git a/manifest.uuid b/manifest.uuid index a7f49d3bce..f76cceaf73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -15e4a272df46cbad8e71b21551dc06a126d64d46 \ No newline at end of file +e0b116edd64a55c971c368685aa343cb6beed0f1 \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index b53952fd44..a78795f61c 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -381,16 +381,16 @@ struct Vdbe { #endif u16 nResColumn; /* Number of columns in one row of the result set */ u8 errorAction; /* Recovery action to do in case of an error */ + bft expired:1; /* True if the VM needs to be recompiled */ + bft doingRerun:1; /* True if rerunning after an auto-reprepare */ u8 minWriteFileFormat; /* Minimum file format for writable database files */ bft explain:2; /* True if EXPLAIN present on SQL command */ bft changeCntOn:1; /* True to update the change-counter */ - bft expired:1; /* True if the VM needs to be recompiled */ bft runOnlyOnce:1; /* Automatically expire on reset */ bft usesStmtJournal:1; /* True if uses a statement journal */ bft readOnly:1; /* True for statements that do not write */ bft bIsReader:1; /* True for statements that read */ bft isPrepareV2:1; /* True if prepared with prepare_v2() */ - bft doingRerun:1; /* True if rerunning after an auto-reprepare */ int nChange; /* Number of db changes made since last reset */ yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ yDbMask lockMask; /* Subset of btreeMask that requires a lock */ From 32f57d4c373c8f49b59f4a40149c136ef8a5632b Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 16 Mar 2016 01:03:10 +0000 Subject: [PATCH 57/57] Add the SQLITE_OMIT_CODEC_FROM_TCL compile-time option. FossilOrigin-Name: 45f7f0c80bd91a0c7ff859c27fd9e82e551bd83e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/tclsqlite.c | 14 +++++++------- src/test1.c | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 8154a2631d..bf413d574c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rearrange\ssome\sinternal\sfields\sin\sthe\ssqlite3_stmt\sobject\sto\savoid\sa\sharmless\nTSAN\swarning. -D 2016-03-16T00:36:19.731 +C Add\sthe\sSQLITE_OMIT_CODEC_FROM_TCL\scompile-time\soption. +D 2016-03-16T01:03:10.251 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -359,8 +359,8 @@ F src/sqliteInt.h 84c673f27b77dfbd367cb3ed1de8b6f3b73102dc F src/sqliteLimit.h 7b28cf72cbd52f178bfc97ea266445e351f2cd24 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 -F src/tclsqlite.c 54dca4eaf3a9cb0a4b845ef54ffa99225c30a52e -F src/test1.c f14a6f9e2cff6cba4d83e2b0c52857f61886cead +F src/tclsqlite.c 4bf3bea9b03aeac176ac114700f35f76a1de4c8a +F src/test1.c 52965bd684ddcd7f22328ebd7d50fd0b6e51f0d4 F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b F src/test3.c a8887dabbbee3059af338f20d290084a63ed1b0f F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -1456,7 +1456,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 15e4a272df46cbad8e71b21551dc06a126d64d46 -R 82478b12d64974258326bdaae56626ca +P e0b116edd64a55c971c368685aa343cb6beed0f1 +R 1b0c52bbc749be5b9a732d29d3d099e5 U drh -Z e403476d229295941bbcf1df1a4408f9 +Z 5dddb7cbfc6ef15baab9797e73067d60 diff --git a/manifest.uuid b/manifest.uuid index f76cceaf73..3aa4fcd861 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e0b116edd64a55c971c368685aa343cb6beed0f1 \ No newline at end of file +45f7f0c80bd91a0c7ff859c27fd9e82e551bd83e \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 4e19f92644..42dd6b0f49 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -2574,7 +2574,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ ** Change the encryption key on the currently open database. */ case DB_REKEY: { -#ifdef SQLITE_HAS_CODEC +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) int nKey; void *pKey; #endif @@ -2582,7 +2582,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ Tcl_WrongNumArgs(interp, 2, objv, "KEY"); return TCL_ERROR; } -#ifdef SQLITE_HAS_CODEC +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey); rc = sqlite3_rekey(pDb->db, pKey, nKey); if( rc ){ @@ -2955,7 +2955,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ const char *zVfs = 0; int flags; Tcl_DString translatedFilename; -#ifdef SQLITE_HAS_CODEC +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) void *pKey = 0; int nKey = 0; #endif @@ -2984,7 +2984,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ return TCL_OK; } if( strcmp(zArg,"-has-codec")==0 ){ -#ifdef SQLITE_HAS_CODEC +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) Tcl_AppendResult(interp,"1",(char*)0); #else Tcl_AppendResult(interp,"0",(char*)0); @@ -2995,7 +2995,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ for(i=3; i+1db ){ sqlite3_key(p->db, pKey, nKey); } diff --git a/src/test1.c b/src/test1.c index 744b400b2a..8ad653ca6c 100644 --- a/src/test1.c +++ b/src/test1.c @@ -651,7 +651,7 @@ static int test_key( int argc, /* Number of arguments */ char **argv /* Text of each argument */ ){ -#ifdef SQLITE_HAS_CODEC +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) sqlite3 *db; const char *zKey; int nKey;