1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Further sanity checking of the OpenDup cursors.

FossilOrigin-Name: 0ec71cf16983697f68ab8d921d80a5f39611e4cb5e6e19cbc4a9ad6d49bfc835
This commit is contained in:
drh
2021-03-18 15:42:59 +00:00
parent eeee8a5f01
commit 5a4a15fd2e
5 changed files with 30 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
C Automatically\sclose\sephemeral\sb-trees\swhen\stheir\slast\scursor\sis\sclosed. C Further\ssanity\schecking\sof\sthe\sOpenDup\scursors.
D 2021-03-18T14:31:37.348 D 2021-03-18T15:42:59.646
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -483,7 +483,7 @@ F src/auth.c 08954fdc4cc2da5264ba5b75cfd90b67a6fc7d1710a02ccf917c38eadec77853
F src/backup.c 3014889fa06e20e6adfa0d07b60097eec1f6e5b06671625f476a714d2356513d F src/backup.c 3014889fa06e20e6adfa0d07b60097eec1f6e5b06671625f476a714d2356513d
F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
F src/btree.c b048dcb502fd8abd5b161189150607d8ca9477b52fc5cba907246f795eb1fe36 F src/btree.c 25cdff8bd4b3c9bb009bfe585a7edde48fdb9aa1579173922038aac6bb47c0c6
F src/btree.h 096cc53baa58be22b02c896d1cf933c38cfc6d65f9253c1367ece8cc88a24de5 F src/btree.h 096cc53baa58be22b02c896d1cf933c38cfc6d65f9253c1367ece8cc88a24de5
F src/btreeInt.h 7614cae30f95b6aed0c7cac7718276a55cfe2c77058cbfd8bef5b75329757331 F src/btreeInt.h 7614cae30f95b6aed0c7cac7718276a55cfe2c77058cbfd8bef5b75329757331
F src/build.c fec73c39d756f31d35ccbaa80fe1e040a8d675a318d4d30f41c444167bf3b860 F src/build.c fec73c39d756f31d35ccbaa80fe1e040a8d675a318d4d30f41c444167bf3b860
@@ -614,9 +614,9 @@ F src/upsert.c df8f1727d62b5987c4fd302cd4d7c0c84ae57cd65683c5a34a740dfe24039235
F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
F src/util.c 41c7a72da1df47864faa378a1c720b38adb288c6838cb6be5594511b6287a048 F src/util.c 41c7a72da1df47864faa378a1c720b38adb288c6838cb6be5594511b6287a048
F src/vacuum.c 492422c1463c076473bae1858799c7a0a5fe87a133d1223239447c422cd26286 F src/vacuum.c 492422c1463c076473bae1858799c7a0a5fe87a133d1223239447c422cd26286
F src/vdbe.c 819860625f65ebc1ad029fbef07b62c56904e057a6d76f0d5486e2c41d0fccd4 F src/vdbe.c cba3e495c8ab25af825202dfa944e6f91d5c5cf86d415af07cac3834989d64a6
F src/vdbe.h 25dabb25c7e157b84e59260cfb5b466c3ac103ede9f36f4db371332c47601abe F src/vdbe.h 25dabb25c7e157b84e59260cfb5b466c3ac103ede9f36f4db371332c47601abe
F src/vdbeInt.h 3df118924e1711f1bbc8e30c46260d0ab6c3b029b32dd411f789111f76434f3c F src/vdbeInt.h 000d9ab1ea4cb55a80de15e28f3f595645b4fddef34bca4347fb3db8031d9041
F src/vdbeapi.c 4a43e303ec3354c785f453e881521969378e85628278ab74ba4a9df790c0d93b F src/vdbeapi.c 4a43e303ec3354c785f453e881521969378e85628278ab74ba4a9df790c0d93b
F src/vdbeaux.c 6df834c4ff0c86a62b94fe0762d0abb7dbda54a862f0fe82e35d22fc4490414d F src/vdbeaux.c 6df834c4ff0c86a62b94fe0762d0abb7dbda54a862f0fe82e35d22fc4490414d
F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b1 F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b1
@@ -1910,7 +1910,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P b8de980b2fb78088ef74e053cb987bb84319d13dc96ce1e89baaaa3fe8cf1efc P 39b5af18c0580c8e92516d410f8c465bfec31b2d0be9df1cfd6a1d1a19b4fc14
R d059e62ed2003127849996336a75bcfd R a76f75bf1ec726e3bc7a2a3639bd46d6
U dan U drh
Z 5c6f726925b0e9cfdd8d4a838991a1a4 Z 8ca7de05c1a42b71a557e12a74405656

View File

@@ -1 +1 @@
39b5af18c0580c8e92516d410f8c465bfec31b2d0be9df1cfd6a1d1a19b4fc14 0ec71cf16983697f68ab8d921d80a5f39611e4cb5e6e19cbc4a9ad6d49bfc835

View File

@@ -2737,20 +2737,24 @@ static void freeTempSpace(BtShared *pBt){
*/ */
int sqlite3BtreeClose(Btree *p){ int sqlite3BtreeClose(Btree *p){
BtShared *pBt = p->pBt; BtShared *pBt = p->pBt;
BtCursor *pCur;
/* Close all cursors opened via this handle. */ /* Close all cursors opened via this handle. */
assert( sqlite3_mutex_held(p->db->mutex) ); assert( sqlite3_mutex_held(p->db->mutex) );
sqlite3BtreeEnter(p); sqlite3BtreeEnter(p);
pBt->openFlags &= ~BTREE_SINGLE;
pCur = pBt->pCursor; /* Verify that no other cursors have this Btree open */
#ifdef SQLITE_DEBUG
{
BtCursor *pCur = pBt->pCursor;
while( pCur ){ while( pCur ){
BtCursor *pTmp = pCur; BtCursor *pTmp = pCur;
pCur = pCur->pNext; pCur = pCur->pNext;
if( pTmp->pBtree==p ){ assert( pTmp->pBtree!=p );
sqlite3BtreeCloseCursor(pTmp);
} }
} }
#endif
pBt->openFlags &= ~BTREE_SINGLE;
/* Rollback any active transaction and free the handle structure. /* Rollback any active transaction and free the handle structure.
** The call to sqlite3BtreeRollback() drops any table-locks held by ** The call to sqlite3BtreeRollback() drops any table-locks held by

View File

@@ -272,11 +272,6 @@ static VdbeCursor *allocateCursor(
assert( iCur>=0 && iCur<p->nCursor ); assert( iCur>=0 && iCur<p->nCursor );
if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/ if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
/* Before calling sqlite3VdbeFreeCursor(), ensure the isEphemeral flag
** is clear. Otherwise, if this is an ephemeral cursor created by
** OP_OpenDup, the cursor will not be closed and will still be part
** of a BtShared.pCursor list. */
if( p->apCsr[iCur]->pBtx==0 ) p->apCsr[iCur]->isEphemeral = 0;
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
p->apCsr[iCur] = 0; p->apCsr[iCur] = 0;
} }
@@ -3873,7 +3868,7 @@ case OP_OpenDup: {
pOrig = p->apCsr[pOp->p2]; pOrig = p->apCsr[pOp->p2];
assert( pOrig ); assert( pOrig );
assert( pOrig->pBtx ); /* Only ephemeral cursors can be duplicated */ assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */
pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE); pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
if( pCx==0 ) goto no_mem; if( pCx==0 ) goto no_mem;
@@ -3884,6 +3879,8 @@ case OP_OpenDup: {
pCx->pgnoRoot = pOrig->pgnoRoot; pCx->pgnoRoot = pOrig->pgnoRoot;
pCx->isOrdered = pOrig->isOrdered; pCx->isOrdered = pOrig->isOrdered;
pCx->pBtx = pOrig->pBtx; pCx->pBtx = pOrig->pBtx;
pCx->hasBeenDuped = 1;
pOrig->hasBeenDuped = 1;
rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
pCx->pKeyInfo, pCx->uc.pCursor); pCx->pKeyInfo, pCx->uc.pCursor);
/* The sqlite3BtreeCursor() routine can only fail for the first cursor /* The sqlite3BtreeCursor() routine can only fail for the first cursor
@@ -3950,9 +3947,10 @@ case OP_OpenEphemeral: {
aMem[pOp->p3].z = ""; aMem[pOp->p3].z = "";
} }
pCx = p->apCsr[pOp->p1]; pCx = p->apCsr[pOp->p1];
if( pCx && ALWAYS(pCx->pBtx) ){ if( pCx && !pCx->hasBeenDuped ){
/* If the ephermeral table is already open, erase all existing content /* If the ephermeral table is already open and has no duplicates from
** so that the table is empty again, rather than creating a new table. */ ** OP_OpenDup, then erase all existing content so that the table is
** empty again, rather than creating a new table. */
assert( pCx->isEphemeral ); assert( pCx->isEphemeral );
pCx->seqCount = 0; pCx->seqCount = 0;
pCx->cacheStatus = CACHE_STALE; pCx->cacheStatus = CACHE_STALE;

View File

@@ -86,6 +86,7 @@ struct VdbeCursor {
Bool isEphemeral:1; /* True for an ephemeral table */ Bool isEphemeral:1; /* True for an ephemeral table */
Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */ u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
Btree *pBtx; /* Separate file holding temporary table */ Btree *pBtx; /* Separate file holding temporary table */
i64 seqCount; /* Sequence counter */ i64 seqCount; /* Sequence counter */