1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Fix a performance regression: Keep two btree masks in each prepared

statement; one for btrees used and another for btrees that require locks.
Only try to lock the btrees identified by the second mask.

FossilOrigin-Name: 614de91a504d2231009a9de1305e31fce1b1c5a6
This commit is contained in:
drh
2011-04-06 22:05:53 +00:00
parent dc5df0f824
commit dc5b047ec3
7 changed files with 44 additions and 24 deletions

View File

@@ -160,7 +160,8 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
if( op==OP_ParseSchema ){
/* Any program that uses the OP_ParseSchema opcode needs to lock
** all btrees. */
p->btreeMask = ~(yDbMask)0;
int j;
for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
}
#ifdef SQLITE_DEBUG
pOp->zComment = 0;
@@ -958,6 +959,9 @@ void sqlite3VdbeUsesBtree(Vdbe *p, int i){
assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
assert( i<(int)sizeof(p->btreeMask)*8 );
p->btreeMask |= ((yDbMask)1)<<i;
if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
p->lockMask |= ((yDbMask)1)<<i;
}
}
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
@@ -985,11 +989,15 @@ void sqlite3VdbeUsesBtree(Vdbe *p, int i){
void sqlite3VdbeEnter(Vdbe *p){
int i;
yDbMask mask;
sqlite3 *db = p->db;
Db *aDb = db->aDb;
int nDb = db->nDb;
sqlite3 *db;
Db *aDb;
int nDb;
if( p->lockMask==0 ) return; /* The common case */
db = p->db;
aDb = db->aDb;
nDb = db->nDb;
for(i=0, mask=1; i<nDb; i++, mask += mask){
if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
sqlite3BtreeEnter(aDb[i].pBt);
}
}
@@ -1003,12 +1011,15 @@ void sqlite3VdbeEnter(Vdbe *p){
void sqlite3VdbeLeave(Vdbe *p){
int i;
yDbMask mask;
sqlite3 *db = p->db;
Db *aDb = db->aDb;
int nDb = db->nDb;
sqlite3 *db;
Db *aDb;
int nDb;
if( p->lockMask==0 ) return; /* The common case */
db = p->db;
aDb = db->aDb;
nDb = db->nDb;
for(i=0, mask=1; i<nDb; i++, mask += mask){
if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
if( i!=1 && (mask & p->lockMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
sqlite3BtreeLeave(aDb[i].pBt);
}
}