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

Performance optimizations in the column cache of the code generator, and

especially the sqlite3ExprCacheRemove() routine.

FossilOrigin-Name: e35b345cf858018ae0c07f79725f8d58062168db
This commit is contained in:
drh
2016-04-11 18:15:37 +00:00
parent 3c19469ca2
commit bea119cdeb
4 changed files with 35 additions and 18 deletions

View File

@@ -2335,6 +2335,19 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
}
}
#if defined(SQLITE_DEBUG)
/*
** Verify the consistency of the column cache
*/
static int cacheIsValid(Parse *pParse){
int i, n;
for(i=n=0; i<SQLITE_N_COLCACHE; i++){
if( pParse->aColCache[i].iReg>0 ) n++;
}
return n==pParse->nColCache;
}
#endif
/*
** Clear a cache entry.
*/
@@ -2345,6 +2358,9 @@ static void cacheEntryClear(Parse *pParse, struct yColCache *p){
}
p->tempReg = 0;
}
p->iReg = 0;
pParse->nColCache--;
assert( cacheIsValid(pParse) );
}
@@ -2388,6 +2404,8 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){
p->iReg = iReg;
p->tempReg = 0;
p->lru = pParse->iCacheCnt++;
pParse->nColCache++;
assert( cacheIsValid(pParse) );
return;
}
}
@@ -2409,6 +2427,7 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){
p->iReg = iReg;
p->tempReg = 0;
p->lru = pParse->iCacheCnt++;
assert( cacheIsValid(pParse) );
return;
}
}
@@ -2418,15 +2437,13 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){
** Purge the range of registers from the column cache.
*/
void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
int i;
int iLast = iReg + nReg - 1;
struct yColCache *p;
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
int r = p->iReg;
if( r>=iReg && r<=iLast ){
cacheEntryClear(pParse, p);
p->iReg = 0;
}
if( iReg<=0 || pParse->nColCache==0 ) return;
p = &pParse->aColCache[SQLITE_N_COLCACHE-1];
while(1){
if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p);
if( p==pParse->aColCache ) break;
p--;
}
}
@@ -2462,7 +2479,6 @@ void sqlite3ExprCachePop(Parse *pParse){
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
if( p->iReg && p->iLevel>pParse->iCacheLevel ){
cacheEntryClear(pParse, p);
p->iReg = 0;
}
}
}
@@ -2597,7 +2613,6 @@ void sqlite3ExprCacheClear(Parse *pParse){
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
if( p->iReg ){
cacheEntryClear(pParse, p);
p->iReg = 0;
}
}
}
@@ -2639,6 +2654,7 @@ static int usedAsColumnCache(Parse *pParse, int iFrom, int iTo){
}
#endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
/*
** Convert an expression node to a TK_REGISTER
*/