/ Check-in [a68697d1]
Login

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

Overview
Comment:Activate the cell-overwrite optimization for index b-trees.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a68697d10ef17d452c8279181186faad7bc54e3a35858a336552f717449065ea
User & Date: drh 2018-05-07 18:41:19
Context
2018-05-08
12:49
Fuzz test cases for UPSERT. check-in: fd11fbd2 user: drh tags: trunk
2018-05-07
18:41
Activate the cell-overwrite optimization for index b-trees. check-in: a68697d1 user: drh tags: trunk
17:27
Improved comments on the cell-overwrite optimization code. check-in: a4fe966d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  8392   8392           r.eqSeen = 0;
  8393   8393           rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
  8394   8394         }else{
  8395   8395           rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
  8396   8396         }
  8397   8397         if( rc ) return rc;
  8398   8398       }
         8399  +
         8400  +    /* If the cursor is currently pointing to an entry to be overwritten
         8401  +    ** and the new content is the same as as the old, then use the
         8402  +    ** overwrite optimization.
         8403  +    */
         8404  +    if( loc==0 ){
         8405  +      getCellInfo(pCur);
         8406  +      if( pCur->info.nKey==pX->nKey ){
         8407  +        BtreePayload x2;
         8408  +        x2.pData = pX->pKey;
         8409  +        x2.nData = pX->nKey;
         8410  +        x2.nZero = 0;
         8411  +        return btreeOverwriteCell(pCur, &x2);
         8412  +      }
         8413  +    }
         8414  +
  8399   8415     }
  8400   8416     assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
  8401   8417   
  8402   8418     pPage = pCur->pPage;
  8403   8419     assert( pPage->intKey || pX->nKey>=0 );
  8404   8420     assert( pPage->leaf || !pPage->intKey );
  8405   8421   

Changes to src/btree.h.

   255    255   #define BTREE_AUXDELETE    0x04  /* not the primary delete operation */
   256    256   #define BTREE_APPEND       0x08  /* Insert is likely an append */
   257    257   
   258    258   /* An instance of the BtreePayload object describes the content of a single
   259    259   ** entry in either an index or table btree.
   260    260   **
   261    261   ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
   262         -** an arbitrary key and no data.  These btrees have pKey,nKey set to their
   263         -** key and pData,nData,nZero set to zero.
          262  +** an arbitrary key and no data.  These btrees have pKey,nKey set to the
          263  +** key and the pData,nData,nZero fields are uninitialized.  The aMem,nMem
          264  +** fields give an array of Mem objects that are a decomposition of the key.
          265  +** The nMem field might be zero, indicating that no decomposition is available.
   264    266   **
   265    267   ** Table btrees (used for rowid tables) contain an integer rowid used as
   266    268   ** the key and passed in the nKey field.  The pKey field is zero.  
   267    269   ** pData,nData hold the content of the new entry.  nZero extra zero bytes
   268    270   ** are appended to the end of the content when constructing the entry.
          271  +** The aMem,nMem fields are uninitialized for table btrees.
          272  +**
          273  +** Field usage summary:
          274  +**
          275  +**               Table BTrees                   Index Btrees
          276  +**
          277  +**   pKey        always NULL                    encoded key
          278  +**   nKey        the ROWID                      length of pKey
          279  +**   pData       data                           not used
          280  +**   aMem        not used                       decomposed key value
          281  +**   nMem        not used                       entries in aMem
          282  +**   nData       length of pData                not used
          283  +**   nZero       extra zeros after pData        not used
   269    284   **
   270    285   ** This object is used to pass information into sqlite3BtreeInsert().  The
   271    286   ** same information used to be passed as five separate parameters.  But placing
   272    287   ** the information into this object helps to keep the interface more 
   273    288   ** organized and understandable, and it also helps the resulting code to
   274    289   ** run a little faster by using fewer registers for parameter passing.
   275    290   */
   276    291   struct BtreePayload {
   277    292     const void *pKey;       /* Key content for indexes.  NULL for tables */
   278    293     sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
   279         -  const void *pData;      /* Data for tables.  NULL for indexes */
          294  +  const void *pData;      /* Data for tables. */
   280    295     sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
   281    296     u16 nMem;               /* Number of aMem[] value.  Might be zero */
   282    297     int nData;              /* Size of pData.  0 if none. */
   283    298     int nZero;              /* Extra zero data appended after pData,nData */
   284    299   };
   285    300   
   286    301   int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,