/ Check-in [dd61c736]
Login

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

Overview
Comment:Omit unnecessary fstat() calls for determining the database file size, resulting in smaller and faster code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:dd61c736775c53450821327495276485dced7935d0b4b5ebd17662731afc8adb
User & Date: drh 2017-05-29 17:59:29
Context
2017-05-29
22:44
More efficient error handling and reset in the binding mechanism. check-in: 9a3e3b34 user: drh tags: trunk
17:59
Omit unnecessary fstat() calls for determining the database file size, resulting in smaller and faster code. check-in: dd61c736 user: drh tags: trunk
17:43
Fix an issue with OPT_FEATURE_FLAGS in configure.ac. check-in: 43ce3bd3 user: drh tags: trunk
16:45
Avoid unnecessary fstat() calls to determine the database size when transitioning into a read transaction on a rollback-mode database. Closed-Leaf check-in: 6c3476b5 user: drh tags: io-opt
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/pager.c.

  3300   3300   static int pagerOpenWalIfPresent(Pager *pPager){
  3301   3301     int rc = SQLITE_OK;
  3302   3302     assert( pPager->eState==PAGER_OPEN );
  3303   3303     assert( pPager->eLock>=SHARED_LOCK );
  3304   3304   
  3305   3305     if( !pPager->tempFile ){
  3306   3306       int isWal;                    /* True if WAL file exists */
         3307  +    rc = sqlite3OsAccess(
         3308  +        pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
         3309  +    );
         3310  +    if( rc==SQLITE_OK ){
         3311  +      if( isWal ){
  3307   3312       Pgno nPage;                   /* Size of the database file */
  3308   3313   
  3309   3314       rc = pagerPagecount(pPager, &nPage);
  3310   3315       if( rc ) return rc;
  3311   3316       if( nPage==0 ){
  3312   3317         rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
  3313         -      if( rc==SQLITE_IOERR_DELETE_NOENT ) rc = SQLITE_OK;
  3314         -      isWal = 0;
  3315   3318       }else{
  3316         -      rc = sqlite3OsAccess(
  3317         -          pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
  3318         -      );
  3319         -    }
  3320         -    if( rc==SQLITE_OK ){
  3321         -      if( isWal ){
  3322   3319           testcase( sqlite3PcachePagecount(pPager->pPCache)==0 );
  3323   3320           rc = sqlite3PagerOpenWal(pPager, 0);
         3321  +        }
  3324   3322         }else if( pPager->journalMode==PAGER_JOURNALMODE_WAL ){
  3325   3323           pPager->journalMode = PAGER_JOURNALMODE_DELETE;
  3326   3324         }
  3327   3325       }
  3328   3326     }
  3329   3327     return rc;
  3330   3328   }
................................................................................
  5259   5257         ** other bytes change randomly with each file change when
  5260   5258         ** a codec is in use.
  5261   5259         ** 
  5262   5260         ** There is a vanishingly small chance that a change will not be 
  5263   5261         ** detected.  The chance of an undetected change is so small that
  5264   5262         ** it can be neglected.
  5265   5263         */
  5266         -      Pgno nPage = 0;
  5267   5264         char dbFileVers[sizeof(pPager->dbFileVers)];
  5268   5265   
  5269         -      rc = pagerPagecount(pPager, &nPage);
  5270         -      if( rc ) goto failed;
  5271         -
  5272         -      if( nPage>0 ){
  5273   5266           IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
  5274   5267           rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
  5275         -        if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
         5268  +      if( rc!=SQLITE_OK ){
         5269  +        if( rc!=SQLITE_IOERR_SHORT_READ ){
  5276   5270             goto failed;
  5277   5271           }
  5278         -      }else{
  5279   5272           memset(dbFileVers, 0, sizeof(dbFileVers));
  5280   5273         }
  5281   5274   
  5282   5275         if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
  5283   5276           pager_reset(pPager);
  5284   5277   
  5285   5278           /* Unmap the database file. It is possible that external processes