1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Automatically close ephemeral b-trees when their last cursor is closed.

FossilOrigin-Name: 39b5af18c0580c8e92516d410f8c465bfec31b2d0be9df1cfd6a1d1a19b4fc14
This commit is contained in:
dan
2021-03-18 14:31:37 +00:00
parent 918232aadb
commit eeee8a5f01
6 changed files with 53 additions and 59 deletions

View File

@@ -2742,6 +2742,7 @@ int sqlite3BtreeClose(Btree *p){
/* Close all cursors opened via this handle. */
assert( sqlite3_mutex_held(p->db->mutex) );
sqlite3BtreeEnter(p);
pBt->openFlags &= ~BTREE_SINGLE;
pCur = pBt->pCursor;
while( pCur ){
BtCursor *pTmp = pCur;
@@ -4541,7 +4542,14 @@ int sqlite3BtreeCloseCursor(BtCursor *pCur){
unlockBtreeIfUnused(pBt);
sqlite3_free(pCur->aOverflow);
sqlite3_free(pCur->pKey);
sqlite3BtreeLeave(pBtree);
if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){
/* Since the BtShared is not sharable, there is no need to
** worry about the missing sqlite3BtreeLeave() call here. */
assert( pBtree->sharable==0 );
sqlite3BtreeClose(pBtree);
}else{
sqlite3BtreeLeave(pBtree);
}
pCur->pBtree = 0;
}
return SQLITE_OK;
@@ -10705,14 +10713,6 @@ int sqlite3BtreeIsReadonly(Btree *p){
*/
int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
/*
** Return the Btree object used to open the cursor provided as an
** argument.
*/
Btree *sqlite3BtreeGetBtree(BtCursor *pCsr){
return pCsr->pBtree;
}
#if !defined(SQLITE_OMIT_SHARED_CACHE)
/*
** Return true if the Btree passed as the only argument is sharable.