/ Check-in [d8e1f75d]
Login

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

Overview
Comment:Only use the direct-overflow-read optimization if all data from the overflow page in question is being read.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | overflow-pgno-cache
Files: files | file ages | folders
SHA1: d8e1f75ddf10f3c0b21acd5455f90fdcea54a948
User & Date: dan 2014-03-20 18:56:35
Context
2014-03-31
22:03
Merge in the latest changes and fixes from trunk. check-in: f6211540 user: drh tags: overflow-pgno-cache
2014-03-20
18:56
Only use the direct-overflow-read optimization if all data from the overflow page in question is being read. check-in: d8e1f75d user: dan tags: overflow-pgno-cache
2014-03-11
23:44
Remove a stray C99-style comment. check-in: f500e87d user: drh tags: overflow-pgno-cache
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  3947   3947   ){
  3948   3948     unsigned char *aPayload;
  3949   3949     int rc = SQLITE_OK;
  3950   3950     u32 nKey;
  3951   3951     int iIdx = 0;
  3952   3952     MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
  3953   3953     BtShared *pBt = pCur->pBt;                  /* Btree this cursor belongs to */
         3954  +  int bEnd;                       /* True if reading to end of data */
  3954   3955   
  3955   3956     assert( pPage );
  3956   3957     assert( pCur->eState==CURSOR_VALID );
  3957   3958     assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
  3958   3959     assert( cursorHoldsMutex(pCur) );
  3959   3960   
  3960   3961     getCellInfo(pCur);
  3961   3962     aPayload = pCur->info.pCell + pCur->info.nHeader;
  3962   3963     nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
         3964  +  bEnd = (offset+amt==nKey+pCur->info.nData);
  3963   3965   
  3964   3966     if( NEVER(offset+amt > nKey+pCur->info.nData) 
  3965   3967      || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
  3966   3968     ){
  3967   3969       /* Trying to read or write past the end of the data is an error */
  3968   3970       return SQLITE_CORRUPT_BKPT;
  3969   3971     }
................................................................................
  4060   4062           /* If all the following are true:
  4061   4063           **
  4062   4064           **   1) this is a read operation, and 
  4063   4065           **   2) data is required from the start of this overflow page, and
  4064   4066           **   3) the database is file-backed, and
  4065   4067           **   4) there is no open write-transaction, and
  4066   4068           **   5) the database is not a WAL database,
         4069  +        **   6) all data from the page is being read.
  4067   4070           **
  4068   4071           ** then data can be read directly from the database file into the
  4069   4072           ** output buffer, bypassing the page-cache altogether. This speeds
  4070   4073           ** up loading large records that span many overflow pages.
  4071   4074           */
  4072   4075           if( (eOp&0x01)==0                                      /* (1) */
  4073   4076            && offset==0                                          /* (2) */
         4077  +         && (bEnd || a==ovflSize)                              /* (6) */
  4074   4078            && pBt->inTransaction==TRANS_READ                     /* (4) */
  4075   4079            && (fd = sqlite3PagerFile(pBt->pPager))->pMethods     /* (3) */
  4076   4080            && pBt->pPage1->aData[19]==0x01                       /* (5) */
  4077   4081           ){
  4078   4082             u8 aSave[4];
  4079   4083             u8 *aWrite = &pBuf[-4];
  4080   4084             memcpy(aSave, aWrite, 4);

Changes to test/func.test.

  1297   1297   do_test func-29.3 {
  1298   1298     db close
  1299   1299     sqlite3 db test.db
  1300   1300     sqlite3_db_status db CACHE_MISS 1
  1301   1301     db eval {SELECT typeof(+x) FROM t29 ORDER BY id}
  1302   1302   } {integer null real blob text}
  1303   1303   if {[permutation] != "mmap"} {
  1304         -  do_test func-29.4 {
  1305         -    set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
  1306         -    if {$x>100} {set x many}
  1307         -    set x
  1308         -  } {many}
         1304  +  ifcapable !direct_read {
         1305  +    do_test func-29.4 {
         1306  +      set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
         1307  +      if {$x>100} {set x many}
         1308  +      set x
         1309  +    } {many}
         1310  +  }
  1309   1311   }
  1310   1312   do_test func-29.5 {
  1311   1313     db close
  1312   1314     sqlite3 db test.db
  1313   1315     sqlite3_db_status db CACHE_MISS 1
  1314   1316     db eval {SELECT sum(length(x)) FROM t29}
  1315   1317   } {1000009}