/ Check-in [bf975985]
Login

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

Overview
Comment:Simplify the sqlite3BtreeKeyFetch() and sqlite3BtreeDataFetch() interfaces to the storage engine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bf97598592ff60fab2a06d8b31b0201200b91684
User & Date: drh 2013-12-09 20:43:22
Context
2013-12-09
21:06
Reduce the number of times that OP_Column calls sqlite3VdbeMemMakeWriteable(). check-in: 6b518635 user: drh tags: trunk
20:43
Simplify the sqlite3BtreeKeyFetch() and sqlite3BtreeDataFetch() interfaces to the storage engine. check-in: bf975985 user: drh tags: trunk
19:25
Minor performance optimizations in pager.c. check-in: ba9eef5f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4188   4188     }
  4189   4189     return rc;
  4190   4190   }
  4191   4191   
  4192   4192   /*
  4193   4193   ** Return a pointer to payload information from the entry that the 
  4194   4194   ** pCur cursor is pointing to.  The pointer is to the beginning of
  4195         -** the key if skipKey==0 and it points to the beginning of data if
  4196         -** skipKey==1.  The number of bytes of available key/data is written
  4197         -** into *pAmt.  If *pAmt==0, then the value returned will not be
  4198         -** a valid pointer.
         4195  +** the key if index btrees (pPage->intKey==0) and is the data for
         4196  +** table btrees (pPage->intKey==1). The number of bytes of available
         4197  +** key/data is written into *pAmt.  If *pAmt==0, then the value
         4198  +** returned will not be a valid pointer.
  4199   4199   **
  4200   4200   ** This routine is an optimization.  It is common for the entire key
  4201   4201   ** and data to fit on the local page and for there to be no overflow
  4202   4202   ** pages.  When that is so, this routine can be used to access the
  4203   4203   ** key and data without making a copy.  If the key and/or data spills
  4204   4204   ** onto overflow pages, then accessPayload() must be used to reassemble
  4205   4205   ** the key/data and copy it into a preallocated buffer.
  4206   4206   **
  4207   4207   ** The pointer returned by this routine looks directly into the cached
  4208   4208   ** page of the database.  The data might change or move the next time
  4209   4209   ** any btree routine is called.
  4210   4210   */
  4211         -static const unsigned char *fetchPayload(
         4211  +static const void *fetchPayload(
  4212   4212     BtCursor *pCur,      /* Cursor pointing to entry to read from */
  4213         -  u32 *pAmt,           /* Write the number of available bytes here */
  4214         -  int skipKey          /* read beginning at data if this is true */
         4213  +  u32 *pAmt            /* Write the number of available bytes here */
  4215   4214   ){
  4216         -  unsigned char *aPayload;
  4217         -  MemPage *pPage;
  4218         -  u32 nKey;
  4219         -  u32 nLocal;
  4220         -
  4221   4215     assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
  4222   4216     assert( pCur->eState==CURSOR_VALID );
         4217  +  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  4223   4218     assert( cursorHoldsMutex(pCur) );
  4224         -  pPage = pCur->apPage[pCur->iPage];
  4225         -  assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
         4219  +  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
  4226   4220     if( pCur->info.nSize==0 ){
  4227   4221       btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
  4228   4222                      &pCur->info);
  4229   4223     }
  4230         -  aPayload = pCur->info.pCell;
  4231         -  aPayload += pCur->info.nHeader;
  4232         -  if( pPage->intKey ){
  4233         -    nKey = 0;
  4234         -  }else{
  4235         -    nKey = (int)pCur->info.nKey;
  4236         -  }
  4237         -  if( skipKey ){
  4238         -    aPayload += nKey;
  4239         -    nLocal = pCur->info.nLocal - nKey;
  4240         -  }else{
  4241         -    nLocal = pCur->info.nLocal;
  4242         -    assert( nLocal<=nKey );
  4243         -  }
  4244         -  *pAmt = nLocal;
  4245         -  return aPayload;
         4224  +  *pAmt = pCur->info.nLocal;
         4225  +  return (void*)(pCur->info.pCell + pCur->info.nHeader);
  4246   4226   }
  4247   4227   
  4248   4228   
  4249   4229   /*
  4250   4230   ** For the entry that cursor pCur is point to, return as
  4251   4231   ** many bytes of the key or data as are available on the local
  4252   4232   ** b-tree page.  Write the number of available bytes into *pAmt.
................................................................................
  4257   4237   ** Hence, a mutex on the BtShared should be held prior to calling
  4258   4238   ** this routine.
  4259   4239   **
  4260   4240   ** These routines is used to get quick access to key and data
  4261   4241   ** in the common case where no overflow pages are used.
  4262   4242   */
  4263   4243   const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
  4264         -  const void *p = 0;
  4265         -  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  4266         -  assert( cursorHoldsMutex(pCur) );
  4267         -  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
  4268         -    p = (const void*)fetchPayload(pCur, pAmt, 0);
  4269         -  }
  4270         -  return p;
         4244  +  return fetchPayload(pCur, pAmt);
  4271   4245   }
  4272   4246   const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
  4273         -  const void *p = 0;
  4274         -  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  4275         -  assert( cursorHoldsMutex(pCur) );
  4276         -  if( ALWAYS(pCur->eState==CURSOR_VALID) ){
  4277         -    p = (const void*)fetchPayload(pCur, pAmt, 1);
  4278         -  }
  4279         -  return p;
         4247  +  return fetchPayload(pCur, pAmt);
  4280   4248   }
  4281   4249   
  4282   4250   
  4283   4251   /*
  4284   4252   ** Move the cursor down to a new child page.  The newPgno argument is the
  4285   4253   ** page number of the child page to move to.
  4286   4254   **