/ Check-in [4a17df13]
Login

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

Overview
Comment:Add the BtCursor.curIntKey field and use it for a small size reduction and performance boost.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4a17df139ac41e29c9a2e58afbd1238a5e94bd36
User & Date: drh 2015-06-27 22:49:10
Context
2015-06-27
23:55
Make greater use of BtCursor.curIntKey. check-in: 63998471 user: drh tags: trunk
22:49
Add the BtCursor.curIntKey field and use it for a small size reduction and performance boost. check-in: 4a17df13 user: drh tags: trunk
20:55
Enhancements to the previous check-in to make it a little smaller and faster. check-in: 291d9e0c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  1951   1951         goto getAndInitPage_error;
  1952   1952       }
  1953   1953     }
  1954   1954   
  1955   1955     /* If obtaining a child page for a cursor, we must verify that the page is
  1956   1956     ** compatible with the root page. */
  1957   1957     if( pCur
  1958         -   && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->apPage[0]->intKey)
         1958  +   && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey)
  1959   1959     ){
  1960   1960       rc = SQLITE_CORRUPT_BKPT;
  1961   1961       releasePage(*ppPage);
  1962   1962       goto getAndInitPage_error;
  1963   1963     }
  1964   1964   
  1965   1965     testcase( pgno==0 );
................................................................................
  4780   4780       rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
  4781   4781                           0, pCur->curPagerFlags);
  4782   4782       if( rc!=SQLITE_OK ){
  4783   4783         pCur->eState = CURSOR_INVALID;
  4784   4784         return rc;
  4785   4785       }
  4786   4786       pCur->iPage = 0;
         4787  +    pCur->curIntKey = pCur->apPage[0]->intKey;
  4787   4788     }
  4788   4789     pRoot = pCur->apPage[0];
  4789   4790     assert( pRoot->pgno==pCur->pgnoRoot );
  4790   4791   
  4791   4792     /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
  4792   4793     ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
  4793   4794     ** NULL, the caller expects a table b-tree. If this is not the case,

Changes to src/btreeInt.h.

   504    504   **    eState==SKIPNEXT && skipNext<0:  Next sqlite3BtreePrevious() is no-op.
   505    505   **    eState==FAULT:                   Cursor fault with skipNext as error code.
   506    506   */
   507    507   struct BtCursor {
   508    508     Btree *pBtree;            /* The Btree to which this cursor belongs */
   509    509     BtShared *pBt;            /* The BtShared this cursor points to */
   510    510     BtCursor *pNext, *pPrev;  /* Forms a linked list of all cursors */
   511         -  struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
   512    511     Pgno *aOverflow;          /* Cache of overflow page locations */
   513    512     CellInfo info;            /* A parse of the cell we are pointing at */
   514    513     i64 nKey;                 /* Size of pKey, or last integer key */
   515    514     void *pKey;               /* Saved key that was cursor last known position */
   516    515     Pgno pgnoRoot;            /* The root page of this tree */
   517    516     int nOvflAlloc;           /* Allocated size of aOverflow[] array */
   518    517     int skipNext;    /* Prev() is noop if negative. Next() is noop if positive.
   519    518                      ** Error code if eState==CURSOR_FAULT */
   520    519     u8 curFlags;              /* zero or more BTCF_* flags defined below */
   521    520     u8 curPagerFlags;         /* Flags to send to sqlite3PagerAcquire() */
   522    521     u8 eState;                /* One of the CURSOR_XXX constants (see below) */
   523         -  u8 hints;                             /* As configured by CursorSetHints() */
   524         -  i16 iPage;                            /* Index of current page in apPage */
          522  +  u8 hints;                 /* As configured by CursorSetHints() */
          523  +  /* All fields above are zeroed when the cursor is allocated.  See
          524  +  ** sqlite3BtreeCursorZero().  Fields that follow must be manually
          525  +  ** initialized. */
          526  +  i8 iPage;                 /* Index of current page in apPage */
          527  +  u8 curIntKey;             /* Value of apPage[0]->intKey */
          528  +  struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
   525    529     u16 aiIdx[BTCURSOR_MAX_DEPTH];        /* Current index in apPage[i] */
   526    530     MemPage *apPage[BTCURSOR_MAX_DEPTH];  /* Pages from root to current page */
   527    531   };
   528    532   
   529    533   /*
   530    534   ** Legal values for BtCursor.curFlags
   531    535   */