From bda4cb876c9636d67a04781aac795b07a39ae965 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 23 Feb 2017 16:30:16 +0000 Subject: [PATCH 01/10] Save a few bytes and a few cycles by setting Vdbe.expmask to zero for statements prepared using legacy interface sqlite3_prepare(). FossilOrigin-Name: a8fd705258643863493476f8b42ee981608a339f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeapi.c | 14 ++++++++------ src/vdbeaux.c | 1 + 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 7980c45c8d..c20fd94d76 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sa\sbranch\scondition\sin\sanalyze.c\sinside\san\s#ifdef\sSQLITE_ENABLE_STAT4\sblock. -D 2017-02-22T19:41:16.947 +C Save\sa\sfew\sbytes\sand\sa\sfew\scycles\sby\ssetting\sVdbe.expmask\sto\szero\sfor\nstatements\sprepared\susing\slegacy\sinterface\ssqlite3_prepare(). +D 2017-02-23T16:30:16.521 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -465,8 +465,8 @@ F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 F src/vdbe.c 83f387d9e6842b1dc99f6e85bb577c5bbc4e397d F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f -F src/vdbeapi.c 3e4a8893feeb78620f4aac4ac5b85d92255b97e1 -F src/vdbeaux.c 2f48204a0f2875b098ee046bba9265907297b0b5 +F src/vdbeapi.c 70aabe108c411e529a59d8800445513965334062 +F src/vdbeaux.c 031422c66e272c7f1027070e7f0858f4c418dfbc F src/vdbeblob.c 359891617358deefc85bef7bcf787fa6b77facb9 F src/vdbemem.c 3b5a9a5b375458d3e12a50ae1aaa41eeec2175fd F src/vdbesort.c eda25cb2d1727efca6f7862fea32b8aa33c0face @@ -1557,7 +1557,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 737a82444065752785c643b1d29ca097c828effb -R 36d1036d6c004868a4b3899253e892b2 +P d6afd98de3ee8b714dfd6477ead955096f623972 +R d82d78a185c578681c4bad1233af7bd3 U dan -Z b9298378d570f055da46d519ad41197c +Z 013ae364526d4d7cd1569b7a9709f5c0 diff --git a/manifest.uuid b/manifest.uuid index 69e4a7f8b9..36ee9348a9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d6afd98de3ee8b714dfd6477ead955096f623972 \ No newline at end of file +a8fd705258643863493476f8b42ee981608a339f \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 6eb97f1d1d..3d9bcca99f 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -154,7 +154,8 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){ sqlite3VdbeMemRelease(&p->aVar[i]); p->aVar[i].flags = MEM_Null; } - if( p->isPrepareV2 && p->expmask ){ + assert( p->isPrepareV2 || p->expmask==0 ); + if( p->expmask ){ p->expired = 1; } sqlite3_mutex_leave(mutex); @@ -1258,9 +1259,8 @@ static int vdbeUnbind(Vdbe *p, int i){ ** as if there had been a schema change, on the first sqlite3_step() call ** following any change to the bindings of that parameter. */ - if( p->isPrepareV2 && - ((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff) - ){ + assert( p->isPrepareV2 || p->expmask==0 ); + if( p->expmask & ((u32)1 << (i&0x001F)) && (i<32 || p->expmask==0xffffffff) ){ p->expired = 1; } return SQLITE_OK; @@ -1523,10 +1523,12 @@ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ if( pFrom->nVar!=pTo->nVar ){ return SQLITE_ERROR; } - if( pTo->isPrepareV2 && pTo->expmask ){ + assert( pTo->isPrepareV2 || pTo->expmask==0 ); + if( pTo->expmask ){ pTo->expired = 1; } - if( pFrom->isPrepareV2 && pFrom->expmask ){ + assert( pFrom->isPrepareV2 || pFrom->expmask==0 ); + if( pFrom->expmask ){ pFrom->expired = 1; } return sqlite3TransferBindings(pFromStmt, pToStmt); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 292ff2bdd2..67e0f63ef6 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -57,6 +57,7 @@ void sqlite3VdbeError(Vdbe *p, const char *zFormat, ...){ void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){ assert( isPrepareV2==1 || isPrepareV2==0 ); if( p==0 ) return; + if( !isPrepareV2 ) p->expmask = 0; #if defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_ENABLE_SQLLOG) if( !isPrepareV2 ) return; #endif From e6d065a81e6bd7be15c778c3a103d94bf1ad3e0f Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 24 Feb 2017 19:58:22 +0000 Subject: [PATCH 02/10] Optimize defragmentPage() in the case where the page contains either one or two free-blocks and a small number of fragmented bytes. FossilOrigin-Name: 202b1c0276aec6b8da64d3277de1ad91c9d62d80 --- manifest | 15 ++++++++----- manifest.uuid | 2 +- src/btree.c | 62 ++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index c20fd94d76..77cbf1aa41 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Save\sa\sfew\sbytes\sand\sa\sfew\scycles\sby\ssetting\sVdbe.expmask\sto\szero\sfor\nstatements\sprepared\susing\slegacy\sinterface\ssqlite3_prepare(). -D 2017-02-23T16:30:16.521 +C Optimize\sdefragmentPage()\sin\sthe\scase\swhere\sthe\spage\scontains\seither\sone\sor\ntwo\sfree-blocks\sand\sa\ssmall\snumber\sof\sfragmented\sbytes. +D 2017-02-24T19:58:22.394 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -338,7 +338,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c 3ae66974881e74df9909093818b4c3428f8d7982 +F src/btree.c 1763e0ec3a6cbda48d3a5cb5a7451e46fbc8784d F src/btree.h e6d352808956ec163a17f832193a3e198b3fb0ac F src/btreeInt.h cd55d39d9916270837a88c12e701047cba0729b0 F src/build.c 51b473eec465f471d607b54e8dbc00751c3f8a1f @@ -1557,7 +1557,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 d6afd98de3ee8b714dfd6477ead955096f623972 -R d82d78a185c578681c4bad1233af7bd3 +P a8fd705258643863493476f8b42ee981608a339f +R c55510e117c3384aa955b9dc66959921 +T *branch * defragmentpage-opt +T *sym-defragmentpage-opt * +T -sym-trunk * U dan -Z 013ae364526d4d7cd1569b7a9709f5c0 +Z a194b2944e8972170f1e898920de81d2 diff --git a/manifest.uuid b/manifest.uuid index 36ee9348a9..6d120aa8df 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a8fd705258643863493476f8b42ee981608a339f \ No newline at end of file +202b1c0276aec6b8da64d3277de1ad91c9d62d80 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index e78ffef1be..6276a850a0 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1317,17 +1317,18 @@ static void ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell, int *pRC){ /* -** Defragment the page given. All Cells are moved to the -** end of the page and all free space is collected into one -** big FreeBlk that occurs in between the header and cell -** pointer array and the cell content area. +** Defragment the page given. This routine reorganizes cells within the +** page so that there are no free-blocks on the free-block list. +** +** Parameter nMaxFrag is the maximum amount of fragmented space that may be +** present in the page after this routine returns. ** ** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a ** b-tree page so that there are no freeblocks or fragment bytes, all ** unused bytes are contained in the unallocated space region, and all ** cells are packed tightly at the end of the page. */ -static int defragmentPage(MemPage *pPage){ +static int defragmentPage(MemPage *pPage, int nMaxFrag){ int i; /* Loop counter */ int pc; /* Address of the i-th cell */ int hdr; /* Offset to the page header */ @@ -1342,7 +1343,6 @@ static int defragmentPage(MemPage *pPage){ int iCellFirst; /* First allowable cell index */ int iCellLast; /* Last possible cell index */ - assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( pPage->pBt!=0 ); assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); @@ -1354,10 +1354,44 @@ static int defragmentPage(MemPage *pPage){ cellOffset = pPage->cellOffset; nCell = pPage->nCell; assert( nCell==get2byte(&data[hdr+3]) ); + iCellFirst = cellOffset + 2*nCell; + + /* This block handles pages with two or fewer free blocks and nMaxFrag + ** or fewer fragmented bytes. In this case it is faster to move the + ** two (or one) blocks of cells using memmove() and add the required + ** offsets to each pointer in the cell-pointer array than it is to + ** reconstruct the entire page. */ + if( (int)data[hdr+7]<=nMaxFrag ){ + int iFree = get2byte(&data[hdr+1]); + if( iFree ){ + int iFree2 = get2byte(&data[iFree]); + if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){ + u8 *pEnd = &data[cellOffset + nCell*2]; + u8 *pAddr; + int sz2 = 0; + int sz = get2byte(&data[iFree+2]); + int top = get2byte(&data[hdr+5]); + if( iFree2 ){ + sz2 = get2byte(&data[iFree2+2]); + memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); + sz += sz2; + } + cbrk = top+sz; + memmove(&data[cbrk], &data[top], iFree-top); + for(pAddr=&data[cellOffset]; pAddrpBt->usableSize; cbrk = usableSize; - iCellFirst = cellOffset + 2*nCell; iCellLast = usableSize - 4; + for(i=0; inFree ){ + return SQLITE_CORRUPT_BKPT; + } + + defragment_out: assert( cbrk>=iCellFirst ); put2byte(&data[hdr+5], cbrk); data[hdr+1] = 0; data[hdr+2] = 0; - data[hdr+7] = 0; memset(&data[iCellFirst], 0, cbrk-iCellFirst); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); - if( cbrk-iCellFirst!=pPage->nFree ){ - return SQLITE_CORRUPT_BKPT; - } return SQLITE_OK; } @@ -1537,7 +1573,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ testcase( gap+2+nByte==top ); if( gap+2+nByte>top ){ assert( pPage->nCell>0 || CORRUPT_DB ); - rc = defragmentPage(pPage); + rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte))); if( rc ) return rc; top = get2byteNotZero(&data[hdr+5]); assert( gap+nByte<=top ); @@ -7689,7 +7725,7 @@ static int balance_nonroot( ** free space needs to be up front. */ assert( nNew==1 || CORRUPT_DB ); - rc = defragmentPage(apNew[0]); + rc = defragmentPage(apNew[0], 0); testcase( rc!=SQLITE_OK ); assert( apNew[0]->nFree == (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) From 3b2ede1f035a86195df4b23c11cd445d6361818e Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 25 Feb 2017 16:24:02 +0000 Subject: [PATCH 03/10] Tweak the code on this branch to detect b-tree page corruption in the same cases as the trunk. FossilOrigin-Name: f9863b39d96dce6cb5e49a5f3a445ff3d897a951 --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/btree.c | 10 +++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 77cbf1aa41..c6196d9c48 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\sdefragmentPage()\sin\sthe\scase\swhere\sthe\spage\scontains\seither\sone\sor\ntwo\sfree-blocks\sand\sa\ssmall\snumber\sof\sfragmented\sbytes. -D 2017-02-24T19:58:22.394 +C Tweak\sthe\scode\son\sthis\sbranch\sto\sdetect\sb-tree\spage\scorruption\sin\sthe\ssame\scases\sas\sthe\strunk. +D 2017-02-25T16:24:02.032 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -338,7 +338,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c 1763e0ec3a6cbda48d3a5cb5a7451e46fbc8784d +F src/btree.c 03149b0f3fec3c1aa3c50a17e997bb442b867632 F src/btree.h e6d352808956ec163a17f832193a3e198b3fb0ac F src/btreeInt.h cd55d39d9916270837a88c12e701047cba0729b0 F src/build.c 51b473eec465f471d607b54e8dbc00751c3f8a1f @@ -1557,10 +1557,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 a8fd705258643863493476f8b42ee981608a339f -R c55510e117c3384aa955b9dc66959921 -T *branch * defragmentpage-opt -T *sym-defragmentpage-opt * -T -sym-trunk * +P 202b1c0276aec6b8da64d3277de1ad91c9d62d80 +R 7a56121f7b6bd4c4a315ae4d10cd07e6 U dan -Z a194b2944e8972170f1e898920de81d2 +Z 0eab51f3ee55bc511deac00d1a02232c diff --git a/manifest.uuid b/manifest.uuid index 6d120aa8df..190b38aa89 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -202b1c0276aec6b8da64d3277de1ad91c9d62d80 \ No newline at end of file +f9863b39d96dce6cb5e49a5f3a445ff3d897a951 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 6276a850a0..bf65852fe6 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1425,11 +1425,11 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ memcpy(&data[cbrk], &src[pc], size); } data[hdr+7] = 0; - if( cbrk-iCellFirst!=pPage->nFree ){ - return SQLITE_CORRUPT_BKPT; - } defragment_out: + if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){ + return SQLITE_CORRUPT_BKPT; + } assert( cbrk>=iCellFirst ); put2byte(&data[hdr+5], cbrk); data[hdr+1] = 0; @@ -1576,7 +1576,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte))); if( rc ) return rc; top = get2byteNotZero(&data[hdr+5]); - assert( gap+nByte<=top ); + assert( gap+2+nByte<=top ); } @@ -7725,7 +7725,7 @@ static int balance_nonroot( ** free space needs to be up front. */ assert( nNew==1 || CORRUPT_DB ); - rc = defragmentPage(apNew[0], 0); + rc = defragmentPage(apNew[0], -1); testcase( rc!=SQLITE_OK ); assert( apNew[0]->nFree == (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) From 70cdf382323dcc97c8eacdad658e58739c6adc2d Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 25 Feb 2017 20:57:46 +0000 Subject: [PATCH 04/10] Add an 'extern "C"' block to header file sqlite3userauth.h. FossilOrigin-Name: ffd61fb449a510b2fc90caf86b266733051cc365 --- ext/userauth/sqlite3userauth.h | 8 ++++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ext/userauth/sqlite3userauth.h b/ext/userauth/sqlite3userauth.h index 619477cac9..c7d23b9399 100644 --- a/ext/userauth/sqlite3userauth.h +++ b/ext/userauth/sqlite3userauth.h @@ -21,6 +21,10 @@ */ #ifdef SQLITE_USER_AUTHENTICATION +#ifdef __cplusplus +extern "C" { +#endif + /* ** If a database contains the SQLITE_USER table, then the ** sqlite3_user_authenticate() interface must be invoked with an @@ -85,4 +89,8 @@ int sqlite3_user_delete( const char *zUsername /* Username to remove */ ); +#ifdef __cplusplus +} /* end of the 'extern "C"' block */ +#endif + #endif /* SQLITE_USER_AUTHENTICATION */ diff --git a/manifest b/manifest index ffaf3dbb28..706934adb3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\sdefragmentPage()\sin\sthe\scase\swhere\sthe\spage\scontains\seither\sone\sor\ntwo\sfree-blocks\sand\sa\ssmall\snumber\sof\sfragmented\sbytes. -D 2017-02-25T17:47:31.387 +C Add\san\s'extern\s"C"'\sblock\sto\sheader\sfile\ssqlite3userauth.h. +D 2017-02-25T20:57:46.730 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -313,7 +313,7 @@ F ext/session/sessionwor.test 2f3744236dc8b170a695b7d8ddc8c743c7e79fdc F ext/session/sqlite3session.c 13642d9c754cc18f17e141f82860d269e2adf920 F ext/session/sqlite3session.h d4db650adfcc7a4360e9f12a09c2d117b1db6b53 F ext/session/test_session.c eb0bd6c1ea791c1d66ee4ef94c16500dad936386 -F ext/userauth/sqlite3userauth.h 19cb6f0e31316d0ee4afdfb7a85ef9da3333a220 +F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x @@ -1557,7 +1557,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 a8fd705258643863493476f8b42ee981608a339f f9863b39d96dce6cb5e49a5f3a445ff3d897a951 -R 7a56121f7b6bd4c4a315ae4d10cd07e6 +P 4cd2a9672c59ea4b3b4cf3d2f139af3c18a8e833 +R 16a6968419b5f6c02a1445afca8164e1 U dan -Z 1f9c94a7513412f3add97a95f1a8ec80 +Z e669ffb28fd5f6d2e359df5fca2d3400 diff --git a/manifest.uuid b/manifest.uuid index 15d62e357c..604dc67407 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4cd2a9672c59ea4b3b4cf3d2f139af3c18a8e833 \ No newline at end of file +ffd61fb449a510b2fc90caf86b266733051cc365 \ No newline at end of file From 2efd3488ba12c6d36763a9ef732647c33c56913c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 27 Feb 2017 12:23:52 +0000 Subject: [PATCH 05/10] Remove references to special handling in virtual table methods from the documentation for sqlite3_last_insert_rowid(). FossilOrigin-Name: 660f9569d76e4ff1f5bd4f37f640e6a4fc2cf87d --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 10 ++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 706934adb3..1efcbbbcf0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\s'extern\s"C"'\sblock\sto\sheader\sfile\ssqlite3userauth.h. -D 2017-02-25T20:57:46.730 +C Remove\sreferences\sto\sspecial\shandling\sin\svirtual\stable\smethods\sfrom\sthe\ndocumentation\sfor\ssqlite3_last_insert_rowid(). +D 2017-02-27T12:23:52.119 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -397,7 +397,7 @@ F src/resolve.c f9bc0de45a30a450da47b3766de00be89bf9be79 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c d12f3539f80db38b09015561b569e0eb1c4b6c5f F src/shell.c bf976d5301be9d8a4c52852c97909cc9a41ee20d -F src/sqlite.h.in 751ff125eb159c8f92c182b8df980a5e4f50e966 +F src/sqlite.h.in 154b80d215289fb9b845a6f4f9b67ea4fcf049f8 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae F src/sqliteInt.h a23e18aebdd0d851c2956a74a3a4f12ff202b472 @@ -1557,7 +1557,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 4cd2a9672c59ea4b3b4cf3d2f139af3c18a8e833 -R 16a6968419b5f6c02a1445afca8164e1 +P ffd61fb449a510b2fc90caf86b266733051cc365 +R 8aa5e89f1f59df441ed610ff04b07915 U dan -Z e669ffb28fd5f6d2e359df5fca2d3400 +Z e6ccfdfcae6209cec3abae13f87bf4f8 diff --git a/manifest.uuid b/manifest.uuid index 604dc67407..d173449ff7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ffd61fb449a510b2fc90caf86b266733051cc365 \ No newline at end of file +660f9569d76e4ff1f5bd4f37f640e6a4fc2cf87d \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index eaa75fc249..79b9996848 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2048,12 +2048,10 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff); ** have ever occurred on the database connection D, ** then sqlite3_last_insert_rowid(D) returns zero. ** -** ^(If an [INSERT] occurs within a trigger or within a [virtual table] -** method, then this routine will return the [rowid] of the inserted -** row as long as the trigger or virtual table method is running. -** But once the trigger or virtual table method ends, the value returned -** by this routine reverts to what it was before the trigger or virtual -** table method began.)^ +** ^(If an [INSERT] occurs within a trigger then this routine will +** return the [rowid] of the inserted row as long as the trigger is +** running. Once the trigger program ends, the value returned +** by this routine reverts to what it was before the trigger was fired.)^ ** ** ^An [INSERT] that fails due to a constraint violation is not a ** successful [INSERT] and does not change the value returned by this From 9c58b63c18938a9bdbcc2f774de45747eec74fbc Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 27 Feb 2017 14:52:48 +0000 Subject: [PATCH 06/10] Add an sqlite3_set_last_insert_rowid() method. Use it to work around fts4 and fts5 modifying the last-insert-rowid unintuitively from within commit processing. FossilOrigin-Name: fe41bb5632a5d438acfd682809f1bd12315b970a --- ext/fts3/fts3.c | 5 ++- ext/fts5/fts5_storage.c | 11 +++-- ext/fts5/test/fts5lastrowid.test | 73 ++++++++++++++++++++++++++++++++ manifest | 23 ++++++---- manifest.uuid | 2 +- src/main.c | 15 +++++++ src/sqlite.h.in | 36 +++++++++++++--- test/fts4lastrowid.test | 73 ++++++++++++++++++++++++++++++++ 8 files changed, 217 insertions(+), 21 deletions(-) create mode 100644 ext/fts5/test/fts5lastrowid.test create mode 100644 test/fts4lastrowid.test diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 7c931c42d4..8af62cda45 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -3408,8 +3408,10 @@ static int fts3SyncMethod(sqlite3_vtab *pVtab){ const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */ Fts3Table *p = (Fts3Table*)pVtab; - int rc = sqlite3Fts3PendingTermsFlush(p); + int rc; + i64 iLastRowid = sqlite3_last_insert_rowid(p->db); + rc = sqlite3Fts3PendingTermsFlush(p); if( rc==SQLITE_OK && p->nLeafAdd>(nMinMerge/16) && p->nAutoincrmerge && p->nAutoincrmerge!=0xff @@ -3424,6 +3426,7 @@ static int fts3SyncMethod(sqlite3_vtab *pVtab){ if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, p->nAutoincrmerge); } sqlite3Fts3SegmentsClose(p); + sqlite3_set_last_insert_rowid(p->db, iLastRowid); return rc; } diff --git a/ext/fts5/fts5_storage.c b/ext/fts5/fts5_storage.c index a695887458..1f8ad2f434 100644 --- a/ext/fts5/fts5_storage.c +++ b/ext/fts5/fts5_storage.c @@ -1092,12 +1092,17 @@ int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow){ ** Flush any data currently held in-memory to disk. */ int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){ + int rc = SQLITE_OK; + i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db); if( bCommit && p->bTotalsValid ){ - int rc = fts5StorageSaveTotals(p); + rc = fts5StorageSaveTotals(p); p->bTotalsValid = 0; - if( rc!=SQLITE_OK ) return rc; } - return sqlite3Fts5IndexSync(p->pIndex, bCommit); + if( rc==SQLITE_OK ){ + rc = sqlite3Fts5IndexSync(p->pIndex, bCommit); + } + sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid); + return rc; } int sqlite3Fts5StorageRollback(Fts5Storage *p){ diff --git a/ext/fts5/test/fts5lastrowid.test b/ext/fts5/test/fts5lastrowid.test new file mode 100644 index 0000000000..0f7628b233 --- /dev/null +++ b/ext/fts5/test/fts5lastrowid.test @@ -0,0 +1,73 @@ +# 2017 Feb 27 +# +# 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 of the last_insert_rowid functionality with fts5. +# + +source [file join [file dirname [info script]] fts5_common.tcl] +set testprefix fts5lastrowid + +# If SQLITE_ENABLE_FTS5 is defined, omit this file. +ifcapable !fts5 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts5(str); +} + +do_execsql_test 1.1 { + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + SELECT last_insert_rowid(); +} {3} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + COMMIT; + SELECT last_insert_rowid(); +} {6} + +do_execsql_test 1.3 { + INSERT INTO t1(rowid, str) VALUES(-22, 'some more text'); + SELECT last_insert_rowid(); +} {-22} + +do_execsql_test 1.4 { + BEGIN; + INSERT INTO t1(rowid, str) VALUES(45, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(46, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(222, 'some more text'); + SELECT last_insert_rowid(); + COMMIT; + SELECT last_insert_rowid(); +} {222 222} + +do_execsql_test 1.5 { + CREATE TABLE x1(x); + INSERT INTO x1 VALUES('john'), ('paul'), ('george'), ('ringo'); + INSERT INTO t1 SELECT x FROM x1; + SELECT last_insert_rowid(); +} {226} + +do_execsql_test 1.6 { + INSERT INTO t1(rowid, str) SELECT rowid+10, x FROM x1; + SELECT last_insert_rowid(); +} {14} + + +finish_test + diff --git a/manifest b/manifest index 1efcbbbcf0..e571698523 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sreferences\sto\sspecial\shandling\sin\svirtual\stable\smethods\sfrom\sthe\ndocumentation\sfor\ssqlite3_last_insert_rowid(). -D 2017-02-27T12:23:52.119 +C Add\san\ssqlite3_set_last_insert_rowid()\smethod.\sUse\sit\sto\swork\saround\sfts4\sand\nfts5\smodifying\sthe\slast-insert-rowid\sunintuitively\sfrom\swithin\scommit\nprocessing. +D 2017-02-27T14:52:48.644 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -70,7 +70,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c c4d7eecb12de9749851bcab6e5ca616a5803047a +F ext/fts3/fts3.c 95c7041ea75d82d2d9a4cd058904ba889751f5b8 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h eb2502000148e80913b965db3e59f29251266d0a F ext/fts3/fts3_aux.c 9edc3655fcb287f0467d0a4b886a01c6185fe9f1 @@ -106,7 +106,7 @@ F ext/fts5/fts5_expr.c c6ecc2280162a3714d15dce2a8f2299f748b627c F ext/fts5/fts5_hash.c 880998e596b60f078348d48732ca4ad9a90caad2 F ext/fts5/fts5_index.c f67032a9a529ba52a545e6e3ab970764199c05d4 F ext/fts5/fts5_main.c f85281445dcf8be32d18841c93a6f90fe27dbfe2 -F ext/fts5/fts5_storage.c de0ed8a06738bde433afe11e92295ceaffbc4e58 +F ext/fts5/fts5_storage.c 1db0b6f859ce910027245cf41e8a32c7aaed0042 F ext/fts5/fts5_tcl.c 4a901f00c8553740dba63511603f5527d741c26a F ext/fts5/fts5_test_mi.c 783b86697ebf773c18fc109992426c0173a055bc F ext/fts5/fts5_test_tok.c db08af63673c3a7d39f053b36fd6e065017706be @@ -165,6 +165,7 @@ F ext/fts5/test/fts5full.test 6f6143af0c6700501d9fd597189dfab1555bb741 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/fts5lastrowid.test 4fac1aba696dd6c956e03b0cf91f6f1f3aaec494 F ext/fts5/test/fts5matchinfo.test f7dde99697bcb310ea8faa8eb2714d9f4dfc0e1b F ext/fts5/test/fts5merge.test 9f65f090d214ff865c56bef4f864aaa1182af6e3 F ext/fts5/test/fts5merge2.test a6da3c16d694235938d1939f503cfa53f0943d75 @@ -360,7 +361,7 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3ed64afc49c0a2221e397b9f65d231ffbef506fe F src/legacy.c e88ed13c2d531decde75d42c2e35623fb9ce3cb0 F src/loadext.c a68d8d1d14cf7488bb29dc5311cb1ce9a4404258 -F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0 +F src/main.c 158326243c5ddc8b98a1e983fa488650cf76d760 F src/malloc.c d0a1474236486165bcb349af82e2a6560178bf7b F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c fd7cd6fe21d46fe0a4186367dd8dc26d87b787eb @@ -397,7 +398,7 @@ F src/resolve.c f9bc0de45a30a450da47b3766de00be89bf9be79 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c d12f3539f80db38b09015561b569e0eb1c4b6c5f F src/shell.c bf976d5301be9d8a4c52852c97909cc9a41ee20d -F src/sqlite.h.in 154b80d215289fb9b845a6f4f9b67ea4fcf049f8 +F src/sqlite.h.in 4d0c08f8640c586564a7032b259c5f69bf397850 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae F src/sqliteInt.h a23e18aebdd0d851c2956a74a3a4f12ff202b472 @@ -806,6 +807,7 @@ F test/fts4growth.test e5390da74619cacc389711bac9349640b32c4f9a F test/fts4growth2.test 13ad4e76451af6e6906c95cdc725d01b00044269 F test/fts4incr.test 4e353a0bd886ea984e56fce9e77724fc923b8d0d F test/fts4langid.test 65a7332c9bc257919e259a304aa8a38c41655b9d +F test/fts4lastrowid.test fa5e157955a3121615ef3e16ff5196e96c9e1e64 F test/fts4merge.test d2b39f6b1bd4a9738a13540e2d044cba11c43d47 F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891 F test/fts4merge3.test 8d9ccb4a3d41c4c617a149d6c4b13ad02de797d0 @@ -1557,7 +1559,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 ffd61fb449a510b2fc90caf86b266733051cc365 -R 8aa5e89f1f59df441ed610ff04b07915 +P 660f9569d76e4ff1f5bd4f37f640e6a4fc2cf87d +R 882d86f84a56568be3256ca713764e4e +T *branch * set-last-insert-rowid +T *sym-set-last-insert-rowid * +T -sym-trunk * U dan -Z e6ccfdfcae6209cec3abae13f87bf4f8 +Z 68fc9fa30db7c037a3f29bd13a0c709d diff --git a/manifest.uuid b/manifest.uuid index d173449ff7..ab91f005ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -660f9569d76e4ff1f5bd4f37f640e6a4fc2cf87d \ No newline at end of file +fe41bb5632a5d438acfd682809f1bd12315b970a \ No newline at end of file diff --git a/src/main.c b/src/main.c index 9aad8fdd4c..4ac5327e4f 100644 --- a/src/main.c +++ b/src/main.c @@ -921,6 +921,21 @@ sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ return db->lastRowid; } +/* +** Set the value returned by the sqlite3_last_insert_rowid() API function. +*/ +void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){ +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) ){ + (void)SQLITE_MISUSE_BKPT; + return; + } +#endif + sqlite3_mutex_enter(db->mutex); + db->lastRowid = iRowid; + sqlite3_mutex_leave(db->mutex); +} + /* ** Return the number of changes in the most recent call to sqlite3_exec(). */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 79b9996848..076a011319 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2040,13 +2040,25 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff); ** the table has a column of type [INTEGER PRIMARY KEY] then that column ** is another alias for the rowid. ** -** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the -** most recent successful [INSERT] into a rowid table or [virtual table] -** on database connection D. -** ^Inserts into [WITHOUT ROWID] tables are not recorded. -** ^If no successful [INSERT]s into rowid tables -** have ever occurred on the database connection D, -** then sqlite3_last_insert_rowid(D) returns zero. +** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of +** the most recent successful [INSERT] into a rowid table or [virtual table] +** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not +** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred +** on the database connection D, then sqlite3_last_insert_rowid(D) returns +** zero. +** +** As well as being set automatically as rows are inserted into database +** tables, the value returned by this function may be set explicitly by +** [sqlite3_set_last_insert_rowid()] +** +** Some virtual table implementations may INSERT rows into rowid tables as +** part of committing a transaction (e.g. to flush data accumulated in memory +** to disk). In this case subsequent calls to this function return the rowid +** associated with these internal INSERT operations, which leads to +** unintuitive results. Virtual table implementations that do write to rowid +** tables in this way can avoid this problem by restoring the original +** rowid value using [sqlite3_set_last_insert_rowid()] before returning +** control to the user. ** ** ^(If an [INSERT] occurs within a trigger then this routine will ** return the [rowid] of the inserted row as long as the trigger is @@ -2078,6 +2090,16 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff); */ sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); +/* +** CAPI3REF: Set the Last Insert Rowid value. +** METHOD: sqlite3 +** +** The sqlite3_set_last_insert_rowid(D, R) method allows the application to +** set the value returned by calling sqlite3_last_insert_rowid(D) to R +** without inserting a row into the database. +*/ +void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); + /* ** CAPI3REF: Count The Number Of Rows Modified ** METHOD: sqlite3 diff --git a/test/fts4lastrowid.test b/test/fts4lastrowid.test new file mode 100644 index 0000000000..b5720a2ef3 --- /dev/null +++ b/test/fts4lastrowid.test @@ -0,0 +1,73 @@ +# 2017 Feb 27 +# +# 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 of the last_insert_rowid functionality with fts4. +# + +set testdir [file dirname $argv0] +source [file join [file dirname [info script]] tester.tcl] +set testprefix fts4lastrowid + +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(str); +} + +do_execsql_test 1.1 { + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + SELECT last_insert_rowid(); +} {3} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + COMMIT; + SELECT last_insert_rowid(); +} {6} + +do_execsql_test 1.3 { + INSERT INTO t1(rowid, str) VALUES(-22, 'some more text'); + SELECT last_insert_rowid(); +} {-22} + +do_execsql_test 1.4 { + BEGIN; + INSERT INTO t1(rowid, str) VALUES(45, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(46, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(222, 'some more text'); + SELECT last_insert_rowid(); + COMMIT; + SELECT last_insert_rowid(); +} {222 222} + +do_execsql_test 1.5 { + CREATE TABLE x1(x); + INSERT INTO x1 VALUES('john'), ('paul'), ('george'), ('ringo'); + INSERT INTO t1 SELECT x FROM x1; + SELECT last_insert_rowid(); +} {226} + +do_execsql_test 1.6 { + INSERT INTO t1(rowid, str) SELECT rowid+10, x FROM x1; + SELECT last_insert_rowid(); +} {14} + + +finish_test + From 81415257ec6bdfc97ff5073e7f80bda09abef774 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 27 Feb 2017 17:06:56 +0000 Subject: [PATCH 07/10] Improve performance of fts5 writes by writing the "averages" record once at the end of each transaction instead of every time the table is updated. FossilOrigin-Name: 2b210d691462b463796e7948399133c296e89ebf --- ext/fts5/fts5_storage.c | 14 ++------------ manifest | 13 ++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/ext/fts5/fts5_storage.c b/ext/fts5/fts5_storage.c index 1f8ad2f434..c8c26bd1b6 100644 --- a/ext/fts5/fts5_storage.c +++ b/ext/fts5/fts5_storage.c @@ -545,11 +545,6 @@ int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel, sqlite3_value **apVal){ } } - /* Write the averages record */ - if( rc==SQLITE_OK ){ - rc = fts5StorageSaveTotals(p); - } - return rc; } @@ -753,11 +748,6 @@ int sqlite3Fts5StorageIndexInsert( } sqlite3_free(buf.p); - /* Write the averages record */ - if( rc==SQLITE_OK ){ - rc = fts5StorageSaveTotals(p); - } - return rc; } @@ -1094,9 +1084,9 @@ int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow){ int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){ int rc = SQLITE_OK; i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db); - if( bCommit && p->bTotalsValid ){ + if( p->bTotalsValid ){ rc = fts5StorageSaveTotals(p); - p->bTotalsValid = 0; + if( bCommit ) p->bTotalsValid = 0; } if( rc==SQLITE_OK ){ rc = sqlite3Fts5IndexSync(p->pIndex, bCommit); diff --git a/manifest b/manifest index 089fbab958..f842047291 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\ssqlite3_set_last_insert_rowid()\smethod.\sUse\sit\sto\swork\saround\sfts4\sand\nfts5\smodifying\sthe\slast-insert-rowid\sunintuitively\sfrom\swithin\scommit\nprocessing. -D 2017-02-27T16:15:29.690 +C Improve\sperformance\sof\sfts5\swrites\sby\swriting\sthe\s"averages"\srecord\sonce\sat\nthe\send\sof\seach\stransaction\sinstead\sof\severy\stime\sthe\stable\sis\supdated. +D 2017-02-27T17:06:56.850 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -106,7 +106,7 @@ F ext/fts5/fts5_expr.c c6ecc2280162a3714d15dce2a8f2299f748b627c F ext/fts5/fts5_hash.c 880998e596b60f078348d48732ca4ad9a90caad2 F ext/fts5/fts5_index.c f67032a9a529ba52a545e6e3ab970764199c05d4 F ext/fts5/fts5_main.c f85281445dcf8be32d18841c93a6f90fe27dbfe2 -F ext/fts5/fts5_storage.c 1db0b6f859ce910027245cf41e8a32c7aaed0042 +F ext/fts5/fts5_storage.c 8f0e65cb33bde8f449e1c9b4be4600d18b4da6e9 F ext/fts5/fts5_tcl.c 4a901f00c8553740dba63511603f5527d741c26a F ext/fts5/fts5_test_mi.c 783b86697ebf773c18fc109992426c0173a055bc F ext/fts5/fts5_test_tok.c db08af63673c3a7d39f053b36fd6e065017706be @@ -1559,8 +1559,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 660f9569d76e4ff1f5bd4f37f640e6a4fc2cf87d fe41bb5632a5d438acfd682809f1bd12315b970a -R 882d86f84a56568be3256ca713764e4e -T +closed fe41bb5632a5d438acfd682809f1bd12315b970a +P 952a3906b30a818e4574bb85f57150577d04f74e +R 84bac8b8e25067f97464b8201fd688d3 U dan -Z 5437a317a211c2826dc04cbed3f42658 +Z 50f45fcec707e33cc33fa8432e53c9b6 diff --git a/manifest.uuid b/manifest.uuid index c4e0be71d1..a89a664ddf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -952a3906b30a818e4574bb85f57150577d04f74e \ No newline at end of file +2b210d691462b463796e7948399133c296e89ebf \ No newline at end of file From 6e5688d37502f62f7a55bd35c072546d1f78d82e Mon Sep 17 00:00:00 2001 From: mistachkin Date: Mon, 27 Feb 2017 17:16:27 +0000 Subject: [PATCH 08/10] Make PATH handling more robust in the batch tools for MSVC. FossilOrigin-Name: 23a8917e848a999533bc66467f7cb2f4f3d45bc1 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- tool/GetTclKit.bat | 14 +++++++++++++- tool/build-all-msvc.bat | 6 +++++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index f842047291..c06c866121 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sperformance\sof\sfts5\swrites\sby\swriting\sthe\s"averages"\srecord\sonce\sat\nthe\send\sof\seach\stransaction\sinstead\sof\severy\stime\sthe\stable\sis\supdated. -D 2017-02-27T17:06:56.850 +C Make\sPATH\shandling\smore\srobust\sin\sthe\sbatch\stools\sfor\sMSVC. +D 2017-02-27T17:16:27.906 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -1469,10 +1469,10 @@ F test/wordcount.c 06efb84b7c48a4973c2c24ea06c93d00bce24389 F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test e59a56443d6298ecf7435f618f0b27654f0c849e F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 -F tool/GetTclKit.bat f94784e3bdc2f50c539266f5467cbf1f27612cb3 +F tool/GetTclKit.bat 6afa640edc7810725aec61c3076ac617c4aaf0b7 F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91 F tool/addopcodes.tcl 10c889c4a65ec6c5604e4a47306fa77ff57ae189 -F tool/build-all-msvc.bat 018c1b273458a90c8ba633c6f0c5654cfcb138bf x +F tool/build-all-msvc.bat c12328d06c45fec8baada5949e3d5af54bf8c887 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/cg_anno.tcl f95b0006c52cf7f0496b506343415b6ee3cdcdd3 x F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 @@ -1559,7 +1559,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 952a3906b30a818e4574bb85f57150577d04f74e -R 84bac8b8e25067f97464b8201fd688d3 -U dan -Z 50f45fcec707e33cc33fa8432e53c9b6 +P 2b210d691462b463796e7948399133c296e89ebf +R 2fadaa28e86ebe3a08aafa06769bc23f +U mistachkin +Z 6b968b4fe877e63444beda0443031271 diff --git a/manifest.uuid b/manifest.uuid index a89a664ddf..af9a30ac81 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2b210d691462b463796e7948399133c296e89ebf \ No newline at end of file +23a8917e848a999533bc66467f7cb2f4f3d45bc1 \ No newline at end of file diff --git a/tool/GetTclKit.bat b/tool/GetTclKit.bat index 8764b195dd..1c9f92bc12 100644 --- a/tool/GetTclKit.bat +++ b/tool/GetTclKit.bat @@ -124,7 +124,7 @@ IF NOT EXIST "%FRAMEWORKDIR%\csc.exe" ( GOTO errors ) -SET PATH=%FRAMEWORKDIR%;%PATH% +CALL :fn_PrependToPath FRAMEWORKDIR :skip_addToPath @@ -246,6 +246,18 @@ GOTO no_errors ENDLOCAL && SET %1=%VALUE% GOTO :EOF +:fn_PrependToPath + IF NOT DEFINED %1 GOTO :EOF + SETLOCAL + SET __ECHO_CMD=ECHO %%%1%% + FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO ( + SET VALUE=%%V + ) + SET VALUE=%VALUE:"=% + REM " + ENDLOCAL && SET PATH=%VALUE%;%PATH% + GOTO :EOF + :fn_ResetErrorLevel VERIFY > NUL GOTO :EOF diff --git a/tool/build-all-msvc.bat b/tool/build-all-msvc.bat index 497b05e316..aaeb67bdfb 100755 --- a/tool/build-all-msvc.bat +++ b/tool/build-all-msvc.bat @@ -460,7 +460,7 @@ FOR %%P IN (%PLATFORMS%) DO ( REM REM NOTE: Reset the PATH here to the absolute bare minimum required. REM - SET PATH=%TOOLPATH%;%SystemRoot%\System32;%SystemRoot% + CALL :fn_ResetPath REM REM NOTE: This is the inner loop. There are normally two iterations, one @@ -818,6 +818,10 @@ GOTO no_errors CALL :fn_ResetErrorLevel GOTO :EOF +:fn_ResetPath + SET PATH=%TOOLPATH%;%SystemRoot%\System32;%SystemRoot% + GOTO :EOF + :fn_AppendVariable SET __ECHO_CMD=ECHO %%%1%% IF DEFINED %1 ( From 2147221c36ca4f5067e6e2ea0dd0b8eac4a18f37 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 Mar 2017 11:30:27 +0000 Subject: [PATCH 09/10] Fix a use-after-free problem in the shell tool code that could occur if an SQL statement were executed after an ".open" command with invalid options. FossilOrigin-Name: ac760db0727209db0a816e112ea5f47e54d54dac --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c06c866121..f194990812 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sPATH\shandling\smore\srobust\sin\sthe\sbatch\stools\sfor\sMSVC. -D 2017-02-27T17:16:27.906 +C Fix\sa\suse-after-free\sproblem\sin\sthe\sshell\stool\scode\sthat\scould\soccur\sif\san\sSQL\nstatement\swere\sexecuted\safter\san\s".open"\scommand\swith\sinvalid\soptions. +D 2017-03-01T11:30:27.730 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -397,7 +397,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c f9bc0de45a30a450da47b3766de00be89bf9be79 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c d12f3539f80db38b09015561b569e0eb1c4b6c5f -F src/shell.c bf976d5301be9d8a4c52852c97909cc9a41ee20d +F src/shell.c 27d2b31099fd2cd749e44d025ef9b54ca26692cb F src/sqlite.h.in 4d0c08f8640c586564a7032b259c5f69bf397850 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1559,7 +1559,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 2b210d691462b463796e7948399133c296e89ebf -R 2fadaa28e86ebe3a08aafa06769bc23f -U mistachkin -Z 6b968b4fe877e63444beda0443031271 +P 23a8917e848a999533bc66467f7cb2f4f3d45bc1 +R 6f5948ee4f1d68e0584e854f4c330a6f +U dan +Z 4914d52d58dfba6bed9b5d6006acef82 diff --git a/manifest.uuid b/manifest.uuid index af9a30ac81..a3f75430ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -23a8917e848a999533bc66467f7cb2f4f3d45bc1 \ No newline at end of file +ac760db0727209db0a816e112ea5f47e54d54dac \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index f1c7f3c157..2dcf915f28 100644 --- a/src/shell.c +++ b/src/shell.c @@ -4344,6 +4344,7 @@ static int do_meta_command(char *zLine, ShellState *p){ session_close_all(p); sqlite3_close(p->db); p->db = 0; + p->zDbFilename = 0; sqlite3_free(p->zFreeOnClose); p->zFreeOnClose = 0; /* Check for command-line arguments */ From 76adb239805a543742232090cd4399db3f8f46f6 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Mar 2017 13:13:30 +0000 Subject: [PATCH 10/10] Make sure the Vdbe.expmask value is set correctly in sqlite3VdbeSwap(). This fixes a problem introduced by [a8fd7052]. FossilOrigin-Name: 29f54b899e5cf22ece98ab41c39c41d75a4b228d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index f194990812..646adca563 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\suse-after-free\sproblem\sin\sthe\sshell\stool\scode\sthat\scould\soccur\sif\san\sSQL\nstatement\swere\sexecuted\safter\san\s".open"\scommand\swith\sinvalid\soptions. -D 2017-03-01T11:30:27.730 +C Make\ssure\sthe\sVdbe.expmask\svalue\sis\sset\scorrectly\sin\ssqlite3VdbeSwap().\nThis\sfixes\sa\sproblem\sintroduced\sby\s[a8fd7052]. +D 2017-03-02T13:13:30.327 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -467,7 +467,7 @@ F src/vdbe.c 83f387d9e6842b1dc99f6e85bb577c5bbc4e397d F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f F src/vdbeapi.c 70aabe108c411e529a59d8800445513965334062 -F src/vdbeaux.c 031422c66e272c7f1027070e7f0858f4c418dfbc +F src/vdbeaux.c b632f9151a296c5eb22a2cc955c487ebc2347cb6 F src/vdbeblob.c 359891617358deefc85bef7bcf787fa6b77facb9 F src/vdbemem.c 3b5a9a5b375458d3e12a50ae1aaa41eeec2175fd F src/vdbesort.c eda25cb2d1727efca6f7862fea32b8aa33c0face @@ -1559,7 +1559,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 23a8917e848a999533bc66467f7cb2f4f3d45bc1 -R 6f5948ee4f1d68e0584e854f4c330a6f -U dan -Z 4914d52d58dfba6bed9b5d6006acef82 +P ac760db0727209db0a816e112ea5f47e54d54dac +R be25bb329cc9311f7d92b42176424b6a +U drh +Z eb983447910676b385a2c6496a637326 diff --git a/manifest.uuid b/manifest.uuid index a3f75430ae..9f406e4ffa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac760db0727209db0a816e112ea5f47e54d54dac \ No newline at end of file +29f54b899e5cf22ece98ab41c39c41d75a4b228d \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 67e0f63ef6..8a19c26003 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -86,6 +86,7 @@ void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){ pA->zSql = pB->zSql; pB->zSql = zTmp; pB->isPrepareV2 = pA->isPrepareV2; + pB->expmask = pA->expmask; } /*