mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Improvements to register allocation, especially in the ANALYZE command.
New assert() statements added to help verify that memory allocation is correct, and to help fuzzer find lingering errors. FossilOrigin-Name: 6f8b97f31a4c8552312b4c98432ea356ae54c06d9cc929969f50c3c88360cd7b
This commit is contained in:
37
src/expr.c
37
src/expr.c
@@ -6635,6 +6635,35 @@ void sqlite3ClearTempRegCache(Parse *pParse){
|
||||
pParse->nRangeReg = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Make sure sufficient registers have been allocated so that
|
||||
** iReg is a valid register number.
|
||||
*/
|
||||
void sqlite3TouchRegister(Parse *pParse, int iReg){
|
||||
if( pParse->nMem<iReg ) pParse->nMem = iReg;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the latest reusable register in the set of all registers.
|
||||
** The value returned is no less than iMin. If any register iMin or
|
||||
** greater is in permanent use, then return one more than that last
|
||||
** permanent register.
|
||||
*/
|
||||
int sqlite3FirstAvailableRegister(Parse *pParse, int iMin){
|
||||
const ExprList *pList = pParse->pConstExpr;
|
||||
if( pList ){
|
||||
int i;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
if( pList->a[i].u.iConstExprReg>=iMin ){
|
||||
iMin = pList->a[i].u.iConstExprReg + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
pParse->nTempReg = 0;
|
||||
pParse->nRangeReg = 0;
|
||||
return iMin;
|
||||
}
|
||||
|
||||
/*
|
||||
** Validate that no temporary register falls within the range of
|
||||
** iFirst..iLast, inclusive. This routine is only call from within assert()
|
||||
@@ -6654,6 +6683,14 @@ int sqlite3NoTempsInRange(Parse *pParse, int iFirst, int iLast){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if( pParse->pConstExpr ){
|
||||
ExprList *pList = pParse->pConstExpr;
|
||||
for(i=0; i<pList->nExpr; i++){
|
||||
int iReg = pList->a[i].u.iConstExprReg;
|
||||
if( iReg==0 ) continue;
|
||||
if( iReg>=iFirst && iReg<=iLast ) return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
Reference in New Issue
Block a user