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

Fast-path the btree transaction start for the common case where a

transaction is already active.

FossilOrigin-Name: 798c3ff20c606b5f9fde16dc67781f238370a7c450bc239c3a98d0f4ca370399
This commit is contained in:
drh
2023-05-17 19:23:24 +00:00
parent 653882ed8c
commit a03be7987b
3 changed files with 34 additions and 8 deletions

View File

@@ -3555,7 +3555,11 @@ int sqlite3BtreeNewDb(Btree *p){
** when A already has a read lock, we encourage A to give up and let B
** proceed.
*/
int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
static SQLITE_NOINLINE int btreeBeginTrans(
Btree *p, /* The btree in which to start the transactino */
int wrflag, /* True to start a write transaction */
int *pSchemaVersion /* Put schema version number here, if not NULL */
){
BtShared *pBt = p->pBt;
Pager *pPager = pBt->pPager;
int rc = SQLITE_OK;
@@ -3727,6 +3731,28 @@ trans_begun:
sqlite3BtreeLeave(p);
return rc;
}
int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
BtShared *pBt;
if( p->sharable
|| p->inTrans==TRANS_NONE
|| (p->inTrans==TRANS_READ && wrflag!=0)
){
return btreeBeginTrans(p,wrflag,pSchemaVersion);
}
pBt = p->pBt;
if( pSchemaVersion ){
*pSchemaVersion = get4byte(&pBt->pPage1->aData[40]);
}
if( wrflag ){
/* This call makes sure that the pager has the correct number of
** open savepoints. If the second parameter is greater than 0 and
** the sub-journal is not already open, then it will be opened here.
*/
return sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
}else{
return SQLITE_OK;
}
}
#ifndef SQLITE_OMIT_AUTOVACUUM