/ Check-in [c63311e2]
Login

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

Overview
Comment:Patch the sqlite3PagerWrite() method in the Pager to run a bit faster.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c63311e2f3344363a5ed99838fb5850004eaee30
User & Date: drh 2014-08-24 01:32:43
Context
2014-08-24
02:53
The sqlite3VdbeChangeEncoding() routine goes about 3x faster if the sqlite3VdbeMemTranslate() subroutine is not inlined. check-in: 0c7e1b87 user: drh tags: trunk
01:32
Patch the sqlite3PagerWrite() method in the Pager to run a bit faster. check-in: c63311e2 user: drh tags: trunk
2014-08-23
23:15
Faster implementation of pcache1Fetch() check-in: 0371cc3b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/pager.c.

  5769   5769     if( pPager->dbSize<pPg->pgno ){
  5770   5770       pPager->dbSize = pPg->pgno;
  5771   5771     }
  5772   5772     return rc;
  5773   5773   }
  5774   5774   
  5775   5775   /*
  5776         -** Mark a data page as writeable. This routine must be called before 
  5777         -** making changes to a page. The caller must check the return value 
  5778         -** of this function and be careful not to change any page data unless 
  5779         -** this routine returns SQLITE_OK.
         5776  +** This is a variant of sqlite3PagerWrite() that runs when the sector size
         5777  +** is larger than the page size.  SQLite makes the (reasonable) assumption that
         5778  +** all bytes of a sector are written together by hardware.  Hence, all bytes of
         5779  +** a sector need to be journalled in case of a power loss in the middle of
         5780  +** a write.
  5780   5781   **
  5781         -** The difference between this function and pager_write() is that this
  5782         -** function also deals with the special case where 2 or more pages
  5783         -** fit on a single disk sector. In this case all co-resident pages
  5784         -** must have been written to the journal file before returning.
  5785         -**
  5786         -** If an error occurs, SQLITE_NOMEM or an IO error code is returned
  5787         -** as appropriate. Otherwise, SQLITE_OK.
         5782  +** Usually, the sector size is less than or equal to the page size, in which
         5783  +** case pages can be individually written.  This routine only runs in the exceptional
         5784  +** case where the page size is smaller than the sector size.
  5788   5785   */
  5789         -int sqlite3PagerWrite(DbPage *pDbPage){
  5790         -  int rc = SQLITE_OK;
  5791         -
  5792         -  PgHdr *pPg = pDbPage;
  5793         -  Pager *pPager = pPg->pPager;
  5794         -
  5795         -  assert( (pPg->flags & PGHDR_MMAP)==0 );
  5796         -  assert( pPager->eState>=PAGER_WRITER_LOCKED );
  5797         -  assert( pPager->eState!=PAGER_ERROR );
  5798         -  assert( assert_pager_state(pPager) );
  5799         -
  5800         -  if( pPager->sectorSize > (u32)pPager->pageSize ){
         5786  +static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
         5787  +  int rc = SQLITE_OK;            /* Return code */
  5801   5788       Pgno nPageCount;          /* Total number of pages in database file */
  5802   5789       Pgno pg1;                 /* First page of the sector pPg is located on. */
  5803   5790       int nPage = 0;            /* Number of pages starting at pg1 to journal */
  5804   5791       int ii;                   /* Loop counter */
  5805   5792       int needSync = 0;         /* True if any page has PGHDR_NEED_SYNC */
         5793  +  Pager *pPager = pPg->pPager;   /* The pager that owns pPg */
  5806   5794       Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
  5807   5795   
  5808   5796       /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
  5809   5797       ** a journal header to be written between the pages journaled by
  5810   5798       ** this function.
  5811   5799       */
  5812   5800       assert( !MEMDB );
................................................................................
  5868   5856             sqlite3PagerUnrefNotNull(pPage);
  5869   5857           }
  5870   5858         }
  5871   5859       }
  5872   5860   
  5873   5861       assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
  5874   5862       pPager->doNotSpill &= ~SPILLFLAG_NOSYNC;
         5863  +  return rc;
         5864  +}
         5865  +
         5866  +/*
         5867  +** Mark a data page as writeable. This routine must be called before 
         5868  +** making changes to a page. The caller must check the return value 
         5869  +** of this function and be careful not to change any page data unless 
         5870  +** this routine returns SQLITE_OK.
         5871  +**
         5872  +** The difference between this function and pager_write() is that this
         5873  +** function also deals with the special case where 2 or more pages
         5874  +** fit on a single disk sector. In this case all co-resident pages
         5875  +** must have been written to the journal file before returning.
         5876  +**
         5877  +** If an error occurs, SQLITE_NOMEM or an IO error code is returned
         5878  +** as appropriate. Otherwise, SQLITE_OK.
         5879  +*/
         5880  +int sqlite3PagerWrite(PgHdr *pPg){
         5881  +  assert( (pPg->flags & PGHDR_MMAP)==0 );
         5882  +  assert( pPg->pPager->eState>=PAGER_WRITER_LOCKED );
         5883  +  assert( pPg->pPager->eState!=PAGER_ERROR );
         5884  +  assert( assert_pager_state(pPg->pPager) );
         5885  +  if( pPg->pPager->sectorSize > (u32)pPg->pPager->pageSize ){
         5886  +    return pagerWriteLargeSector(pPg);
  5875   5887     }else{
  5876         -    rc = pager_write(pDbPage);
         5888  +    return pager_write(pPg);
  5877   5889     }
  5878         -  return rc;
  5879   5890   }
  5880   5891   
  5881   5892   /*
  5882   5893   ** Return TRUE if the page given in the argument was previously passed
  5883   5894   ** to sqlite3PagerWrite().  In other words, return TRUE if it is ok
  5884   5895   ** to change the content of the page.
  5885   5896   */