/ Check-in [0778825d]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Rework the Fts5MultiSegIter structure a bit to make it more efficient.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0778825d0ec9315c70659fae8d0640b209049dd8
User & Date: dan 2015-07-03 20:47:18
Context
2015-07-03
21:38
Add static mutexes for use by the built-in / third-party VFSs and use the built-in VFS mutex where appropriate. check-in: b202e2a1 user: mistachkin tags: trunk
20:47
Rework the Fts5MultiSegIter structure a bit to make it more efficient. check-in: 0778825d user: dan tags: trunk
19:13
Speed up eof checks on fts5 cursors. check-in: 3df4af5d user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_index.c.

   432    432   
   433    433   typedef struct Fts5CResult Fts5CResult;
   434    434   struct Fts5CResult {
   435    435     u16 iFirst;                     /* aSeg[] index of firstest iterator */
   436    436     u8 bTermEq;                     /* True if the terms are equal */
   437    437   };
   438    438   
   439         -struct Fts5MultiSegIter {
   440         -  int nSeg;                       /* Size of aSeg[] array */
   441         -  int bRev;                       /* True to iterate in reverse order */
   442         -  int bSkipEmpty;                 /* True to skip deleted entries */
   443         -  int bEof;                       /* True at EOF */
   444         -  Fts5SegIter *aSeg;              /* Array of segment iterators */
   445         -  Fts5CResult *aFirst;            /* Current merge state (see above) */
   446         -};
   447         -
   448    439   /*
   449    440   ** Object for iterating through a single segment, visiting each term/docid
   450    441   ** pair in the segment.
   451    442   **
   452    443   ** pSeg:
   453    444   **   The segment to iterate through.
   454    445   **
................................................................................
   514    505     int nPos;                       /* Number of bytes in current position list */
   515    506     int bDel;                       /* True if the delete flag is set */
   516    507   };
   517    508   
   518    509   #define FTS5_SEGITER_ONETERM 0x01
   519    510   #define FTS5_SEGITER_REVERSE 0x02
   520    511   
          512  +
          513  +struct Fts5MultiSegIter {
          514  +  int nSeg;                       /* Size of aSeg[] array */
          515  +  int bRev;                       /* True to iterate in reverse order */
          516  +  int bSkipEmpty;                 /* True to skip deleted entries */
          517  +  int bEof;                       /* True at EOF */
          518  +  Fts5CResult *aFirst;            /* Current merge state (see above) */
          519  +  Fts5SegIter aSeg[1];            /* Array of segment iterators */
          520  +};
          521  +
   521    522   
   522    523   /*
   523    524   ** Object for iterating through the conents of a single internal node in 
   524    525   ** memory.
   525    526   */
   526    527   struct Fts5NodeIter {
   527    528     /* Internal. Set and managed by fts5NodeIterXXX() functions. Except, 
................................................................................
  2440   2441     Fts5MultiSegIter *pIter,        /* Iterator to update aFirst[] array for */
  2441   2442     int iChanged                    /* Index of sub-iterator just advanced */
  2442   2443   ){
  2443   2444     int i;
  2444   2445     Fts5SegIter *pNew = &pIter->aSeg[iChanged];
  2445   2446     Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
  2446   2447   
  2447         -  for(i=(pIter->nSeg+iChanged)/2; p->rc==SQLITE_OK; i=i/2){
         2448  +  for(i=(pIter->nSeg+iChanged)/2; 1; i=i/2){
  2448   2449       Fts5CResult *pRes = &pIter->aFirst[i];
  2449   2450   
  2450   2451       assert( pNew->pLeaf );
  2451   2452       assert( pRes->bTermEq==0 || pOther->pLeaf );
  2452   2453       
  2453   2454       if( pRes->bTermEq ){
  2454   2455         if( pNew->iRowid==pOther->iRowid ){
................................................................................
  2518   2519   ){
  2519   2520     Fts5MultiSegIter *pNew;
  2520   2521     int nSlot;                      /* Power of two >= nSeg */
  2521   2522   
  2522   2523     for(nSlot=2; nSlot<nSeg; nSlot=nSlot*2);
  2523   2524     pNew = fts5IdxMalloc(p, 
  2524   2525         sizeof(Fts5MultiSegIter) +          /* pNew */
  2525         -      sizeof(Fts5SegIter) * nSlot +       /* pNew->aSeg[] */
         2526  +      sizeof(Fts5SegIter) * (nSlot-1) +   /* pNew->aSeg[] */
  2526   2527         sizeof(Fts5CResult) * nSlot         /* pNew->aFirst[] */
  2527   2528     );
  2528   2529     if( pNew ){
  2529   2530       pNew->nSeg = nSlot;
  2530         -    pNew->aSeg = (Fts5SegIter*)&pNew[1];
  2531   2531       pNew->aFirst = (Fts5CResult*)&pNew->aSeg[nSlot];
  2532   2532     }
  2533   2533     return pNew;
  2534   2534   }
  2535   2535   
  2536   2536   /*
  2537   2537   ** Allocate a new Fts5MultiSegIter object.