/ Check-in [6c3476b5]
Login

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

Overview
Comment:Avoid unnecessary fstat() calls to determine the database size when transitioning into a read transaction on a rollback-mode database.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | io-opt
Files: files | file ages | folders
SHA3-256: 6c3476b513965df22d648f9a1b99733af753b44d51163cc7d42a69bf562300e1
User & Date: drh 2017-05-29 16:45:45
Context
2017-05-29
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
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
14:57
Avoid unnecessary calls to fstat() to determine the database file size. check-in: c733a1de user: drh tags: io-opt
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace 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         -    Pgno nPage;                   /* Size of the database file */
  3308         -
  3309         -    rc = pagerPagecount(pPager, &nPage);
  3310         -    if( rc ) return rc;
  3311         -    if( nPage==0 ){
  3312         -      rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
  3313         -      if( rc==SQLITE_IOERR_DELETE_NOENT ) rc = SQLITE_OK;
  3314         -      isWal = 0;
  3315         -    }else{
  3316         -      rc = sqlite3OsAccess(
  3317         -          pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
  3318         -      );
  3319         -    }
         3307  +    rc = sqlite3OsAccess(
         3308  +        pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
         3309  +    );
  3320   3310       if( rc==SQLITE_OK ){
  3321   3311         if( isWal ){
  3322         -        testcase( sqlite3PcachePagecount(pPager->pPCache)==0 );
  3323         -        rc = sqlite3PagerOpenWal(pPager, 0);
         3312  +        Pgno nPage;                   /* Size of the database file */
         3313  +
         3314  +        rc = pagerPagecount(pPager, &nPage);
         3315  +        if( rc ) return rc;
         3316  +        if( nPage==0 ){
         3317  +          rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
         3318  +        }else{
         3319  +          testcase( sqlite3PcachePagecount(pPager->pPCache)==0 );
         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   }