diff options
author | drh <> | 2024-02-19 20:12:30 +0000 |
---|---|---|
committer | drh <> | 2024-02-19 20:12:30 +0000 |
commit | 9a28311b6af89a16bda3837ec0115e8839029241 (patch) | |
tree | ffec2c20a46dacc33c3e78405153bf635cba30f0 /src | |
parent | 74b0aad09f0931c6645a1c43a0290ab1ee6ab4ff (diff) | |
download | sqlite-9a28311b6af89a16bda3837ec0115e8839029241.tar.gz sqlite-9a28311b6af89a16bda3837ec0115e8839029241.zip |
If there is no mention of a table in sqlite_stat1, use OP_Rewind to see if
the table is empty prior to invoking ANALYZE.
FossilOrigin-Name: 0cc93b19de597866292e0696f89fbd0e22a6cbb374678f5cc096fb889210fe3c
Diffstat (limited to 'src')
-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); |