From 6d683c5c6e7cfbd3393f64e6520caef5a5921a53 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Feb 2017 02:28:45 +0000 Subject: [PATCH 1/6] Use the sqlite3_blob interface for reading values from the %_node shadow table in RTREE. This is a work in progress. There are still some minor problems. FossilOrigin-Name: fc4917d730b29b0bf60fea5e0166728635783e9c --- ext/rtree/rtree.c | 106 ++++++++++++++++++++++++++++++++++------------ manifest | 18 ++++---- manifest.uuid | 2 +- 3 files changed, 88 insertions(+), 38 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 66cca987da..eae9ef819a 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -133,6 +133,9 @@ struct Rtree { RtreeNode *pDeleted; int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */ + /* Blob I/O on xxx_node */ + sqlite3_blob *pNodeBlob; + /* Statements to read/write/delete a record from xxx_node */ sqlite3_stmt *pReadNode; sqlite3_stmt *pWriteNode; @@ -615,6 +618,16 @@ static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){ return pNode; } +/* +** Clear the Rtree.pNodeBlob object +*/ +static void nodeBlobReset(Rtree *pRtree){ + if( pRtree->pNodeBlob ){ + sqlite3_blob_close(pRtree->pNodeBlob); + pRtree->pNodeBlob = 0; + } +} + /* ** Obtain a reference to an r-tree node. */ @@ -624,9 +637,8 @@ static int nodeAcquire( RtreeNode *pParent, /* Either the parent node or NULL */ RtreeNode **ppNode /* OUT: Acquired node */ ){ - int rc; - int rc2 = SQLITE_OK; - RtreeNode *pNode; + int rc = SQLITE_OK; + RtreeNode *pNode = 0; /* Check if the requested node is already in the hash table. If so, ** increase its reference count and return it. @@ -642,28 +654,42 @@ static int nodeAcquire( return SQLITE_OK; } - sqlite3_bind_int64(pRtree->pReadNode, 1, iNode); - rc = sqlite3_step(pRtree->pReadNode); - if( rc==SQLITE_ROW ){ - const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0); - if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){ - pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); - if( !pNode ){ - rc2 = SQLITE_NOMEM; - }else{ - pNode->pParent = pParent; - pNode->zData = (u8 *)&pNode[1]; - pNode->nRef = 1; - pNode->iNode = iNode; - pNode->isDirty = 0; - pNode->pNext = 0; - memcpy(pNode->zData, zBlob, pRtree->iNodeSize); - nodeReference(pParent); - } + if( pRtree->pNodeBlob ){ + sqlite3_blob *pBlob = pRtree->pNodeBlob; + pRtree->pNodeBlob = 0; + rc = sqlite3_blob_reopen(pBlob, iNode); + pRtree->pNodeBlob = pBlob; + if( rc ){ + nodeBlobReset(pRtree); + if( rc==SQLITE_NOMEM ) return rc; + } + } + if( pRtree->pNodeBlob==0 ){ + char *zTab = sqlite3_mprintf("%s_node", pRtree->zName); + if( zTab==0 ) return SQLITE_NOMEM; + rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0, + &pRtree->pNodeBlob); + sqlite3_free(zTab); + } + if( rc ){ + nodeBlobReset(pRtree); + *ppNode = 0; + }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ + pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); + if( !pNode ){ + rc = SQLITE_NOMEM; + }else{ + pNode->pParent = pParent; + pNode->zData = (u8 *)&pNode[1]; + pNode->nRef = 1; + pNode->iNode = iNode; + pNode->isDirty = 0; + pNode->pNext = 0; + rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData, + pRtree->iNodeSize, 0); + nodeReference(pParent); } } - rc = sqlite3_reset(pRtree->pReadNode); - if( rc==SQLITE_OK ) rc = rc2; /* If the root node was just loaded, set pRtree->iDepth to the height ** of the r-tree structure. A height of zero means all data is stored on @@ -909,6 +935,7 @@ static void rtreeReference(Rtree *pRtree){ static void rtreeRelease(Rtree *pRtree){ pRtree->nBusy--; if( pRtree->nBusy==0 ){ + nodeBlobReset(pRtree); sqlite3_finalize(pRtree->pReadNode); sqlite3_finalize(pRtree->pWriteNode); sqlite3_finalize(pRtree->pDeleteNode); @@ -947,6 +974,7 @@ static int rtreeDestroy(sqlite3_vtab *pVtab){ if( !zCreate ){ rc = SQLITE_NOMEM; }else{ + nodeBlobReset(pRtree); rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0); sqlite3_free(zCreate); } @@ -3152,6 +3180,27 @@ constraint: return rc; } +/* +** Called when a transaction starts. +** This is a no-op. But the Virtual Table mechanism needs a method +** here or else it will never call the xRollback and xCommit methods, +** and those methods are necessary for clearing the sqlite3_blob object. +*/ +static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ + (void)pVtab; + return SQLITE_OK; +} + +/* +** Called when a transaction completes (either by COMMIT or ROLLBACK). +** The sqlite3_blob object should be released at this point. +*/ +static int rtreeEndTransaction(sqlite3_vtab *pVtab){ + Rtree *pRtree = (Rtree *)pVtab; + nodeBlobReset(pRtree); + return SQLITE_OK; +} + /* ** The xRename method for rtree module virtual tables. */ @@ -3173,6 +3222,7 @@ static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){ return rc; } + /* ** This function populates the pRtree->nRowEst variable with an estimate ** of the number of rows in the virtual table. If possible, this is based @@ -3232,15 +3282,15 @@ static sqlite3_module rtreeModule = { rtreeColumn, /* xColumn - read data */ rtreeRowid, /* xRowid - read data */ rtreeUpdate, /* xUpdate - write data */ - 0, /* xBegin - begin transaction */ + rtreeBeginTransaction, /* xBegin - begin transaction */ 0, /* xSync - sync transaction */ - 0, /* xCommit - commit transaction */ - 0, /* xRollback - rollback transaction */ + rtreeEndTransaction, /* xCommit - commit transaction */ + rtreeEndTransaction, /* xRollback - rollback transaction */ 0, /* xFindFunction - function overloading */ rtreeRename, /* xRename - rename the table */ 0, /* xSavepoint */ 0, /* xRelease */ - 0 /* xRollbackTo */ + 0, /* xRollbackTo */ }; static int rtreeSqlInit( @@ -3440,7 +3490,7 @@ static int rtreeInit( pRtree->zDb = (char *)&pRtree[1]; pRtree->zName = &pRtree->zDb[nDb+1]; pRtree->nDim = (u8)((argc-4)/2); - pRtree->nDim2 = argc - 4; + pRtree->nDim2 = pRtree->nDim*2; pRtree->nBytesPerCell = 8 + pRtree->nDim2*4; pRtree->eCoordType = (u8)eCoordType; memcpy(pRtree->zDb, argv[1], nDb); diff --git a/manifest b/manifest index 4cc36f422d..65dc3b7b4d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C This\sis\san\sexperimental\spatch\sthat\sensures\sthat\sall\scursors\shave\stheir\sposition\nsaved\sprior\sto\sstarting\sa\sROLLBACK\sTO. -D 2017-02-02T00:46:55.000 +C Use\sthe\ssqlite3_blob\sinterface\sfor\sreading\svalues\sfrom\sthe\s%_node\sshadow\ntable\sin\sRTREE.\s\sThis\sis\sa\swork\sin\sprogress.\s\sThere\sare\sstill\ssome\sminor\nproblems. +D 2017-02-02T02:28:45.543 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc ba953c8921fc7e18333f61898007206de7e23964 @@ -264,7 +264,7 @@ F ext/rbu/sqlite3rbu.c bb0de6cdbdb14a7d55a097238a434b7e99caf318 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 70f2488eef5c04dccf15a52cbd4961492124f825 +F ext/rtree/rtree.c 73c4308585c47a7500b9e98617e45a62f8564ddb F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 42dadfc7b44a436cd74a1bebc0b9b689e4eaf7ec F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1552,10 +1552,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 0c66cf0f0a9ada2ddcb8d61001ef791b86226416 -R 329580c21139f900f64001f6acfc9557 -T *branch * savepoint-rollback -T *sym-savepoint-rollback * -T -sym-trunk * +P 01d97e5b6502b1811b52a681f445e1aaae6c0ee6 +R 79c2c34c9473af6d4e0161547969b398 +T *branch * rtree-sqlite3_blob +T *sym-rtree-sqlite3_blob * +T -sym-savepoint-rollback * U drh -Z 5087946e64391fb6ac59f69d722efdd6 +Z fc394298cc4191cf41d9c752fa550c9c diff --git a/manifest.uuid b/manifest.uuid index 9d5ad1c981..099f46fdff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01d97e5b6502b1811b52a681f445e1aaae6c0ee6 \ No newline at end of file +fc4917d730b29b0bf60fea5e0166728635783e9c \ No newline at end of file From 2033d1c8ca2698a874709b87c04caba559985985 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Feb 2017 14:40:06 +0000 Subject: [PATCH 2/6] Change RTREE so that the sqlite3_blob object is closed whenever the cursor count drops to zero and there is not a pending write transaction. FossilOrigin-Name: 9bb4eafe1a60176ed2e731bb7e3067c0b8a46615 --- ext/rtree/rtree.c | 26 +++++++++++++++++++------- ext/rtree/rtreeA.test | 2 +- manifest | 17 +++++++---------- manifest.uuid | 2 +- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index eae9ef819a..92ddcf526e 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -119,11 +119,13 @@ struct Rtree { u8 nDim2; /* Twice the number of dimensions */ u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ u8 nBytesPerCell; /* Bytes consumed per cell */ + u8 inWrTrans; /* True if inside write transaction */ int iDepth; /* Current depth of the r-tree structure */ char *zDb; /* Name of database containing r-tree table */ char *zName; /* Name of r-tree table */ - int nBusy; /* Current number of users of this structure */ + u32 nBusy; /* Current number of users of this structure */ i64 nRowEst; /* Estimated number of rows in this table */ + u32 nCursor; /* Number of open cursors */ /* List of nodes removed during a CondenseTree operation. List is ** linked together via the pointer normally used for hash chains - @@ -622,7 +624,7 @@ static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){ ** Clear the Rtree.pNodeBlob object */ static void nodeBlobReset(Rtree *pRtree){ - if( pRtree->pNodeBlob ){ + if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){ sqlite3_blob_close(pRtree->pNodeBlob); pRtree->pNodeBlob = 0; } @@ -661,7 +663,7 @@ static int nodeAcquire( pRtree->pNodeBlob = pBlob; if( rc ){ nodeBlobReset(pRtree); - if( rc==SQLITE_NOMEM ) return rc; + if( rc==SQLITE_NOMEM ) return SQLITE_NOMEM; } } if( pRtree->pNodeBlob==0 ){ @@ -674,6 +676,9 @@ static int nodeAcquire( if( rc ){ nodeBlobReset(pRtree); *ppNode = 0; + /* If unable to open an sqlite3_blob on the desired row, that can only + ** be because the shadow tables hold erroneous data. */ + if( rc==SQLITE_ERROR ) rc = SQLITE_CORRUPT_VTAB; }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); if( !pNode ){ @@ -935,6 +940,8 @@ static void rtreeReference(Rtree *pRtree){ static void rtreeRelease(Rtree *pRtree){ pRtree->nBusy--; if( pRtree->nBusy==0 ){ + pRtree->inWrTrans = 0; + pRtree->nCursor = 0; nodeBlobReset(pRtree); sqlite3_finalize(pRtree->pReadNode); sqlite3_finalize(pRtree->pWriteNode); @@ -990,6 +997,7 @@ static int rtreeDestroy(sqlite3_vtab *pVtab){ */ static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ int rc = SQLITE_NOMEM; + Rtree *pRtree = (Rtree *)pVTab; RtreeCursor *pCsr; pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor)); @@ -997,6 +1005,7 @@ static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ memset(pCsr, 0, sizeof(RtreeCursor)); pCsr->base.pVtab = pVTab; rc = SQLITE_OK; + pRtree->nCursor++; } *ppCursor = (sqlite3_vtab_cursor *)pCsr; @@ -1029,10 +1038,13 @@ static int rtreeClose(sqlite3_vtab_cursor *cur){ Rtree *pRtree = (Rtree *)(cur->pVtab); int ii; RtreeCursor *pCsr = (RtreeCursor *)cur; + assert( pRtree->nCursor>0 ); freeCursorConstraints(pCsr); sqlite3_free(pCsr->aPoint); for(ii=0; iiaNode[ii]); sqlite3_free(pCsr); + pRtree->nCursor--; + nodeBlobReset(pRtree); return SQLITE_OK; } @@ -3182,12 +3194,11 @@ constraint: /* ** Called when a transaction starts. -** This is a no-op. But the Virtual Table mechanism needs a method -** here or else it will never call the xRollback and xCommit methods, -** and those methods are necessary for clearing the sqlite3_blob object. */ static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ - (void)pVtab; + Rtree *pRtree = (Rtree *)pVtab; + assert( pRtree->inWrTrans==0 ); + pRtree->inWrTrans++; return SQLITE_OK; } @@ -3197,6 +3208,7 @@ static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ */ static int rtreeEndTransaction(sqlite3_vtab *pVtab){ Rtree *pRtree = (Rtree *)pVtab; + pRtree->inWrTrans = 0; nodeBlobReset(pRtree); return SQLITE_OK; } diff --git a/ext/rtree/rtreeA.test b/ext/rtree/rtreeA.test index e377b013c1..84644e9ede 100644 --- a/ext/rtree/rtreeA.test +++ b/ext/rtree/rtreeA.test @@ -109,7 +109,7 @@ do_corruption_tests rtreeA-1.1 { } do_execsql_test rtreeA-1.2.0 { DROP TABLE t1_node } {} -do_corruption_tests rtreeA-1.2 -error "SQL logic error or missing database" { +do_corruption_tests rtreeA-1.2 -error "database disk image is malformed" { 1 "SELECT * FROM t1" 2 "SELECT * FROM t1 WHERE rowid=5" 3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)" diff --git a/manifest b/manifest index 65dc3b7b4d..5b06a60ca8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sthe\ssqlite3_blob\sinterface\sfor\sreading\svalues\sfrom\sthe\s%_node\sshadow\ntable\sin\sRTREE.\s\sThis\sis\sa\swork\sin\sprogress.\s\sThere\sare\sstill\ssome\sminor\nproblems. -D 2017-02-02T02:28:45.543 +C Change\sRTREE\sso\sthat\sthe\ssqlite3_blob\sobject\sis\sclosed\swhenever\sthe\scursor\ncount\sdrops\sto\szero\sand\sthere\sis\snot\sa\spending\swrite\stransaction. +D 2017-02-02T14:40:06.876 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc ba953c8921fc7e18333f61898007206de7e23964 @@ -264,7 +264,7 @@ F ext/rbu/sqlite3rbu.c bb0de6cdbdb14a7d55a097238a434b7e99caf318 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 73c4308585c47a7500b9e98617e45a62f8564ddb +F ext/rtree/rtree.c df33d86df608a16516a95c6d184a5ed9988d2bc9 F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 42dadfc7b44a436cd74a1bebc0b9b689e4eaf7ec F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -275,7 +275,7 @@ F ext/rtree/rtree6.test 773a90db2dce6a8353dd0d5b64bca69b29761196 F ext/rtree/rtree7.test 1fa710b9e6bf997a0c1a537b81be7bb6fded1971 F ext/rtree/rtree8.test db79c812f9e4a11f9b1f3f9934007884610a713a F ext/rtree/rtree9.test b5eb13849545dfd271a54ff16784cb00d8792aea -F ext/rtree/rtreeA.test ace05e729a36e342d40cf94e9efc7b4723d9dcdf +F ext/rtree/rtreeA.test ac8b503931f2f397cc3c3303354e1e085dcadb86 F ext/rtree/rtreeB.test c85f9ce78766c4e68b8b89fbf2979ee9cfa82b4e F ext/rtree/rtreeC.test c0a9c67f2efa98b6fae12acb8a28348d231a481d F ext/rtree/rtreeD.test bdfaaf26df8b4eea7364039aca9150bc1e1f8825 @@ -1552,10 +1552,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 01d97e5b6502b1811b52a681f445e1aaae6c0ee6 -R 79c2c34c9473af6d4e0161547969b398 -T *branch * rtree-sqlite3_blob -T *sym-rtree-sqlite3_blob * -T -sym-savepoint-rollback * +P fc4917d730b29b0bf60fea5e0166728635783e9c +R 0b53bd94b2e2abfad755fb806046ae11 U drh -Z fc394298cc4191cf41d9c752fa550c9c +Z 9c59d9d407f6159f87ae8b113cdc33c2 diff --git a/manifest.uuid b/manifest.uuid index 099f46fdff..0b51f62de3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc4917d730b29b0bf60fea5e0166728635783e9c \ No newline at end of file +9bb4eafe1a60176ed2e731bb7e3067c0b8a46615 \ No newline at end of file From 413e207e316ae584dd2218905ab02522cc8e5a33 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Feb 2017 15:35:54 +0000 Subject: [PATCH 3/6] The sqlite3_blob_close() interface can cause recursive invocations of nodeBlobReset() in RTREE. Make sure that does not cause problems. FossilOrigin-Name: 88333441cbf26bfde2acebf2a3f75b5ebbdfb0ae --- ext/rtree/rtree.c | 3 ++- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 92ddcf526e..c5998d2548 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -625,8 +625,9 @@ static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){ */ static void nodeBlobReset(Rtree *pRtree){ if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){ - sqlite3_blob_close(pRtree->pNodeBlob); + sqlite3_blob *pBlob = pRtree->pNodeBlob; pRtree->pNodeBlob = 0; + sqlite3_blob_close(pBlob); } } diff --git a/manifest b/manifest index 5b06a60ca8..f8a355c0e7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sRTREE\sso\sthat\sthe\ssqlite3_blob\sobject\sis\sclosed\swhenever\sthe\scursor\ncount\sdrops\sto\szero\sand\sthere\sis\snot\sa\spending\swrite\stransaction. -D 2017-02-02T14:40:06.876 +C The\ssqlite3_blob_close()\sinterface\scan\scause\srecursive\sinvocations\sof\nnodeBlobReset()\sin\sRTREE.\s\sMake\ssure\sthat\sdoes\snot\scause\sproblems. +D 2017-02-02T15:35:54.700 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc ba953c8921fc7e18333f61898007206de7e23964 @@ -264,7 +264,7 @@ F ext/rbu/sqlite3rbu.c bb0de6cdbdb14a7d55a097238a434b7e99caf318 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c df33d86df608a16516a95c6d184a5ed9988d2bc9 +F ext/rtree/rtree.c 93fd417d6f566caa49a548c915a27125a1b405c3 F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 42dadfc7b44a436cd74a1bebc0b9b689e4eaf7ec F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1552,7 +1552,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 fc4917d730b29b0bf60fea5e0166728635783e9c -R 0b53bd94b2e2abfad755fb806046ae11 +P 9bb4eafe1a60176ed2e731bb7e3067c0b8a46615 +R 6cebe0517919da4320850125e35977ce U drh -Z 9c59d9d407f6159f87ae8b113cdc33c2 +Z 7ae516135e0fc0897102b9fc210a106c diff --git a/manifest.uuid b/manifest.uuid index 0b51f62de3..ee09db23cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9bb4eafe1a60176ed2e731bb7e3067c0b8a46615 \ No newline at end of file +88333441cbf26bfde2acebf2a3f75b5ebbdfb0ae \ No newline at end of file From ce655a236773fafcd3ce751b23cd217a96e5467b Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Feb 2017 16:08:27 +0000 Subject: [PATCH 4/6] Fix a potential uninitialized (though harmless) variable in RTREE. FossilOrigin-Name: a1c74e09d63aca630d022ed074866433eed6b493 --- ext/rtree/rtree.c | 6 +++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index c5998d2548..432c72781e 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1118,7 +1118,6 @@ static int rtreeCallbackConstraint( sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */ int *peWithin /* OUT: visibility of the cell */ ){ - int i; /* Loop counter */ sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */ int nCoord = pInfo->nCoord; /* No. of coordinates */ int rc; /* Callback return code */ @@ -1163,9 +1162,10 @@ static int rtreeCallbackConstraint( } } if( pConstraint->op==RTREE_MATCH ){ + int eWithin = 0; rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo, - nCoord, aCoord, &i); - if( i==0 ) *peWithin = NOT_WITHIN; + nCoord, aCoord, &eWithin); + if( eWithin==0 ) *peWithin = NOT_WITHIN; *prScore = RTREE_ZERO; }else{ pInfo->aCoord = aCoord; diff --git a/manifest b/manifest index f8a355c0e7..0fcd596e1e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\ssqlite3_blob_close()\sinterface\scan\scause\srecursive\sinvocations\sof\nnodeBlobReset()\sin\sRTREE.\s\sMake\ssure\sthat\sdoes\snot\scause\sproblems. -D 2017-02-02T15:35:54.700 +C Fix\sa\spotential\suninitialized\s(though\sharmless)\svariable\sin\sRTREE. +D 2017-02-02T16:08:27.041 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc ba953c8921fc7e18333f61898007206de7e23964 @@ -264,7 +264,7 @@ F ext/rbu/sqlite3rbu.c bb0de6cdbdb14a7d55a097238a434b7e99caf318 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 93fd417d6f566caa49a548c915a27125a1b405c3 +F ext/rtree/rtree.c e1b77d0f32241f3c09ab0bc7cf7be5d263902978 F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 42dadfc7b44a436cd74a1bebc0b9b689e4eaf7ec F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1552,7 +1552,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 9bb4eafe1a60176ed2e731bb7e3067c0b8a46615 -R 6cebe0517919da4320850125e35977ce +P 88333441cbf26bfde2acebf2a3f75b5ebbdfb0ae +R 6c083917a4ecdc09328902e3d7d74ce0 U drh -Z 7ae516135e0fc0897102b9fc210a106c +Z 3e4bf024e32b2f321d57a48b2d7cd9ed diff --git a/manifest.uuid b/manifest.uuid index ee09db23cc..507bf4c42c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -88333441cbf26bfde2acebf2a3f75b5ebbdfb0ae \ No newline at end of file +a1c74e09d63aca630d022ed074866433eed6b493 \ No newline at end of file From 3accc7e1af59b89cc54df381ddf67dc96487103f Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Feb 2017 16:30:25 +0000 Subject: [PATCH 5/6] Remove the unused pReadNode prepared statement from each RTREE object. FossilOrigin-Name: e51dc0ec60d45cd57564735b6b2bb254a588533e --- ext/rtree/rtree.c | 24 ++++++++++-------------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 432c72781e..9e6f0e082a 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -139,7 +139,6 @@ struct Rtree { sqlite3_blob *pNodeBlob; /* Statements to read/write/delete a record from xxx_node */ - sqlite3_stmt *pReadNode; sqlite3_stmt *pWriteNode; sqlite3_stmt *pDeleteNode; @@ -944,7 +943,6 @@ static void rtreeRelease(Rtree *pRtree){ pRtree->inWrTrans = 0; pRtree->nCursor = 0; nodeBlobReset(pRtree); - sqlite3_finalize(pRtree->pReadNode); sqlite3_finalize(pRtree->pWriteNode); sqlite3_finalize(pRtree->pDeleteNode); sqlite3_finalize(pRtree->pReadRowid); @@ -3315,10 +3313,9 @@ static int rtreeSqlInit( ){ int rc = SQLITE_OK; - #define N_STATEMENT 9 + #define N_STATEMENT 8 static const char *azSql[N_STATEMENT] = { - /* Read and write the xxx_node table */ - "SELECT data FROM '%q'.'%q_node' WHERE nodeno = :1", + /* Write the xxx_node table */ "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)", "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1", @@ -3356,15 +3353,14 @@ static int rtreeSqlInit( } } - appStmt[0] = &pRtree->pReadNode; - appStmt[1] = &pRtree->pWriteNode; - appStmt[2] = &pRtree->pDeleteNode; - appStmt[3] = &pRtree->pReadRowid; - appStmt[4] = &pRtree->pWriteRowid; - appStmt[5] = &pRtree->pDeleteRowid; - appStmt[6] = &pRtree->pReadParent; - appStmt[7] = &pRtree->pWriteParent; - appStmt[8] = &pRtree->pDeleteParent; + appStmt[0] = &pRtree->pWriteNode; + appStmt[1] = &pRtree->pDeleteNode; + appStmt[2] = &pRtree->pReadRowid; + appStmt[3] = &pRtree->pWriteRowid; + appStmt[4] = &pRtree->pDeleteRowid; + appStmt[5] = &pRtree->pReadParent; + appStmt[6] = &pRtree->pWriteParent; + appStmt[7] = &pRtree->pDeleteParent; rc = rtreeQueryStat1(db, pRtree); for(i=0; i Date: Sat, 4 Feb 2017 13:12:12 +0000 Subject: [PATCH 6/6] Close sqlite3_blob objects on xSync rather than waiting until xCommit. FossilOrigin-Name: 95ee745fceb4a48c683f34c404c380fe5e7d684a --- ext/rtree/rtree.c | 2 +- manifest | 15 +++++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 9e6f0e082a..c46bce7d37 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -3294,7 +3294,7 @@ static sqlite3_module rtreeModule = { rtreeRowid, /* xRowid - read data */ rtreeUpdate, /* xUpdate - write data */ rtreeBeginTransaction, /* xBegin - begin transaction */ - 0, /* xSync - sync transaction */ + rtreeEndTransaction, /* xSync - sync transaction */ rtreeEndTransaction, /* xCommit - commit transaction */ rtreeEndTransaction, /* xRollback - rollback transaction */ 0, /* xFindFunction - function overloading */ diff --git a/manifest b/manifest index ea1bf5a3bf..e59dba6295 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\sunused\spReadNode\sprepared\sstatement\sfrom\seach\sRTREE\sobject. -D 2017-02-02T16:30:25.555 +C Close\ssqlite3_blob\sobjects\son\sxSync\srather\sthan\swaiting\suntil\sxCommit. +D 2017-02-04T13:12:12.865 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc ba953c8921fc7e18333f61898007206de7e23964 @@ -264,7 +264,7 @@ F ext/rbu/sqlite3rbu.c bb0de6cdbdb14a7d55a097238a434b7e99caf318 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c be9d44f5707c5a73887d3ac3ad14a355e9b92b58 +F ext/rtree/rtree.c ed39c157eab89ce014675f07601f2813c9f54e9c F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 42dadfc7b44a436cd74a1bebc0b9b689e4eaf7ec F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1552,7 +1552,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 a1c74e09d63aca630d022ed074866433eed6b493 -R b4b0a5df6a2ab40920c13363cd1d25e9 +P e51dc0ec60d45cd57564735b6b2bb254a588533e +R a16debe67e7399020e94d725cd2d4af7 +T *branch * rtree-blob-agressive-release +T *sym-rtree-blob-agressive-release * +T -sym-rtree-sqlite3_blob * U drh -Z 5406bbb7ccb82072da8c73ecd9c87865 +Z a61d538b0d9c1a9c54d88c1f71c254d7 diff --git a/manifest.uuid b/manifest.uuid index dda662b8b9..be149e116e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e51dc0ec60d45cd57564735b6b2bb254a588533e \ No newline at end of file +95ee745fceb4a48c683f34c404c380fe5e7d684a \ No newline at end of file