/ Check-in [a62340dc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a62340dc0507e36f6dec05b1fda68d8399ec62ec
User & Date: drh 2016-04-01 12:35:22
Context
2016-04-01
17:54
Preupdate hook documentation fixes. No changes to code. check-in: 59814f35 user: drh tags: trunk
12:35
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. check-in: a62340dc user: drh tags: trunk
2016-03-31
22:53
Update the clean target in the MSVC makefile. check-in: 69f4d832 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

  1831   1831     assert( iDb>=0 && iDb<db->nDb );
  1832   1832     assert( db->aDb[iDb].pBt!=0 );
  1833   1833   
  1834   1834     /* Clear any prior statistics */
  1835   1835     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
  1836   1836     for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
  1837   1837       Index *pIdx = sqliteHashData(i);
  1838         -    sqlite3DefaultRowEst(pIdx);
         1838  +    pIdx->aiRowLogEst[0] = 0;
  1839   1839   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1840   1840       sqlite3DeleteIndexSamples(db, pIdx);
  1841   1841       pIdx->aSample = 0;
  1842   1842   #endif
  1843   1843     }
  1844   1844   
  1845         -  /* Check to make sure the sqlite_stat1 table exists */
         1845  +  /* Load new statistics out of the sqlite_stat1 table */
  1846   1846     sInfo.db = db;
  1847   1847     sInfo.zDatabase = db->aDb[iDb].zName;
  1848         -  if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
  1849         -    return SQLITE_ERROR;
  1850         -  }
  1851         -
  1852         -  /* Load new statistics out of the sqlite_stat1 table */
  1853         -  zSql = sqlite3MPrintf(db, 
  1854         -      "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
  1855         -  if( zSql==0 ){
  1856         -    rc = SQLITE_NOMEM_BKPT;
  1857         -  }else{
  1858         -    rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
  1859         -    sqlite3DbFree(db, zSql);
         1848  +  if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
         1849  +    zSql = sqlite3MPrintf(db, 
         1850  +        "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
         1851  +    if( zSql==0 ){
         1852  +      rc = SQLITE_NOMEM_BKPT;
         1853  +    }else{
         1854  +      rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
         1855  +      sqlite3DbFree(db, zSql);
         1856  +    }
  1860   1857     }
  1861   1858   
         1859  +  /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
         1860  +  assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
         1861  +  for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
         1862  +    Index *pIdx = sqliteHashData(i);
         1863  +    if( pIdx->aiRowLogEst[0]==0 ) sqlite3DefaultRowEst(pIdx);
         1864  +  }
  1862   1865   
  1863   1866     /* Load the statistics from the sqlite_stat4 table. */
  1864   1867   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1865   1868     if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
  1866   1869       db->lookaside.bDisable++;
  1867   1870       rc = loadStat4(db, sInfo.zDatabase);
  1868   1871       db->lookaside.bDisable--;