From: drh Date: Fri, 1 Apr 2016 12:35:22 +0000 (+0000) Subject: When reading an sqlite_stat1 table with missing entries for some indexes, X-Git-Tag: version-3.13.0~140 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6661a88963aa939d1c377954cbf34de98902476;p=thirdparty%2Fsqlite.git When reading an sqlite_stat1 table with missing entries for some indexes, set the default for the missing indexes after all other indexes are set so that the default values are more in line with indexes that are actually in the stat1 table. FossilOrigin-Name: a62340dc0507e36f6dec05b1fda68d8399ec62ec --- diff --git a/manifest b/manifest index 6ccaa6e08d..51885512ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sclean\starget\sin\sthe\sMSVC\smakefile. -D 2016-03-31T22:53:37.345 +C When\sreading\san\ssqlite_stat1\stable\swith\smissing\sentries\sfor\ssome\sindexes,\nset\sthe\sdefault\sfor\sthe\smissing\sindexes\safter\sall\sother\sindexes\sare\sset\nso\sthat\sthe\sdefault\svalues\sare\smore\sin\sline\swith\sindexes\sthat\sare\sactually\nin\sthe\sstat1\stable. +D 2016-04-01T12:35:22.357 F Makefile.in e812bb732d7af01baa09f1278bd4f4a2e3a09449 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc fe57d7e3e74fa383fd01ced796c0ffd966fc094a @@ -311,7 +311,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 1bb0709b3048e24217b80ec6bd78a3e99a47c01b -F src/analyze.c ab57b6763dd4c6170a20673d14882c033affd188 +F src/analyze.c 39b21e4d9ad8a647e9834aa5ba99a74fb6c98879 F src/attach.c 771153bd1f4ab0b97a44a13dde2c7e5e1efeba22 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce @@ -1480,7 +1480,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c648539b52ca28c0b2cb61208e2c32b1d29626a1 -R 6ae456c611a2dfae066ef8a6f11a421b -U mistachkin -Z 730dfc7c7e8862f73161aa001e93b9d4 +P 69f4d83210f6425b2c0d699b397ef4fa4422d438 +R 7562b4ce09688850a9cd06c483af68bc +U drh +Z f4c65a7a3ea821b7d157bc63d7456b83 diff --git a/manifest.uuid b/manifest.uuid index c52f6651c2..0b71e7ae1c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -69f4d83210f6425b2c0d699b397ef4fa4422d438 \ No newline at end of file +a62340dc0507e36f6dec05b1fda68d8399ec62ec \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index cd59ae681d..423ef0d714 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1835,31 +1835,34 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ Index *pIdx = sqliteHashData(i); - sqlite3DefaultRowEst(pIdx); + pIdx->aiRowLogEst[0] = 0; #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 sqlite3DeleteIndexSamples(db, pIdx); pIdx->aSample = 0; #endif } - /* Check to make sure the sqlite_stat1 table exists */ + /* Load new statistics out of the sqlite_stat1 table */ sInfo.db = db; sInfo.zDatabase = db->aDb[iDb].zName; - if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){ - return SQLITE_ERROR; + if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){ + zSql = sqlite3MPrintf(db, + "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase); + if( zSql==0 ){ + rc = SQLITE_NOMEM_BKPT; + }else{ + rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0); + sqlite3DbFree(db, zSql); + } } - /* Load new statistics out of the sqlite_stat1 table */ - zSql = sqlite3MPrintf(db, - "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase); - if( zSql==0 ){ - rc = SQLITE_NOMEM_BKPT; - }else{ - rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0); - sqlite3DbFree(db, zSql); + /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */ + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); + for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ + Index *pIdx = sqliteHashData(i); + if( pIdx->aiRowLogEst[0]==0 ) sqlite3DefaultRowEst(pIdx); } - /* Load the statistics from the sqlite_stat4 table. */ #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){