diff options
Diffstat (limited to 'src/pragma.c')
-rw-r--r-- | src/pragma.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/pragma.c b/src/pragma.c index 18fc88ace..e65233389 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2486,6 +2486,7 @@ void sqlite3Pragma( int nCheck = 0; /* Number of tables to be optimized */ int nBtree = 0; /* Number of btrees to scan */ int nIndex; /* Number of indexes on the current table */ + int hasStat1; /* True if any STAT1 info available for the table */ if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2520,10 +2521,13 @@ void sqlite3Pragma( ** indicate a new, unanalyzed index */ szThreshold = pTab->nRowLogEst; + hasStat1 = (pTab->tabFlags & TF_HasStat1)!=0; nIndex = 0; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ nIndex++; - if( !pIdx->hasStat1 ){ + if( pIdx->hasStat1 ){ + hasStat1 = 1; + }else{ szThreshold = -1; /* Always analyze if any index lacks statistics */ break; } @@ -2555,14 +2559,17 @@ void sqlite3Pragma( ** the last analysis. Unconditional reanalysis if there are ** unanalyzed indexes. */ if( szThreshold>=0 ){ - LogEst iRange = 33; /* 10x size change */ + const LogEst iRange = 33; /* 10x size change */ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur, - sqlite3VdbeCurrentAddr(v)+3+(opMask&1), + sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold>=iRange ? szThreshold-iRange : -1, szThreshold+iRange); - sqlite3VdbeAddOp1(v, OP_Close, iTabCur); VdbeCoverage(v); + }else if( !hasStat1 ){ + sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); + sqlite3VdbeAddOp2(v, OP_Rewind, iTabCur, + sqlite3VdbeCurrentAddr(v)+2+(opMask&1)); } zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"", db->aDb[iDb].zDbSName, pTab->zName); |