/ Check-in [ae350bfb]
Login

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

Overview
Comment:Remove some branches made unreachable by recent changes from fts5.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ae350bfbfd59f912c469a51bf7d1409f3c8d958a
User & Date: dan 2015-10-21 20:56:27
Context
2015-10-21
22:07
Fix compilation of 'testfixture' with MSVC when the FTS5 and JSON1 extensions are enabled. check-in: e31aa97a user: mistachkin tags: trunk
20:56
Remove some branches made unreachable by recent changes from fts5. check-in: ae350bfb user: dan tags: trunk
20:07
Minor optimization for fts5 queries. check-in: 363b36d5 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5Int.h.

   229    229   void sqlite3Fts5BufferAppendVarint(int*, Fts5Buffer*, i64);
   230    230   void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, int, const u8*);
   231    231   void sqlite3Fts5BufferAppendString(int *, Fts5Buffer*, const char*);
   232    232   void sqlite3Fts5BufferFree(Fts5Buffer*);
   233    233   void sqlite3Fts5BufferZero(Fts5Buffer*);
   234    234   void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*);
   235    235   void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
   236         -void sqlite3Fts5BufferAppend32(int*, Fts5Buffer*, int);
   237    236   
   238    237   char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...);
   239    238   
   240    239   #define fts5BufferZero(x)             sqlite3Fts5BufferZero(x)
   241    240   #define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,c)
   242    241   #define fts5BufferFree(a)             sqlite3Fts5BufferFree(a)
   243    242   #define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d)
   244    243   #define fts5BufferSet(a,b,c,d)        sqlite3Fts5BufferSet(a,b,c,d)
   245         -#define fts5BufferAppend32(a,b,c)     sqlite3Fts5BufferAppend32(a,b,c)
   246    244   
   247    245   #define fts5BufferGrow(pRc,pBuf,nn) ( \
   248    246     (pBuf)->n + (nn) <= (pBuf)->nSpace ? 0 : \
   249    247       sqlite3Fts5BufferSize((pRc),(pBuf),(nn)+(pBuf)->n) \
   250    248   )
   251    249   
   252    250   /* Write and decode big-endian 32-bit integer values */

Changes to ext/fts5/fts5_buffer.c.

    49     49     aBuf[3] = (iVal>> 0) & 0x00FF;
    50     50   }
    51     51   
    52     52   int sqlite3Fts5Get32(const u8 *aBuf){
    53     53     return (aBuf[0] << 24) + (aBuf[1] << 16) + (aBuf[2] << 8) + aBuf[3];
    54     54   }
    55     55   
    56         -void sqlite3Fts5BufferAppend32(int *pRc, Fts5Buffer *pBuf, int iVal){
    57         -  if( fts5BufferGrow(pRc, pBuf, 4) ) return;
    58         -  sqlite3Fts5Put32(&pBuf->p[pBuf->n], iVal);
    59         -  pBuf->n += 4;
    60         -}
    61         -
    62     56   /*
    63     57   ** Append buffer nData/pData to buffer pBuf. If an OOM error occurs, set 
    64     58   ** the error code in p. If an error has already occurred when this function
    65     59   ** is called, it is a no-op.
    66     60   */
    67     61   void sqlite3Fts5BufferAppendBlob(
    68     62     int *pRc,

Changes to ext/fts5/fts5_index.c.

  1001   1001         nSegment += pStruct->aLevel[iLvl].nSeg;
  1002   1002       }
  1003   1003     }
  1004   1004   
  1005   1005     return nSegment;
  1006   1006   }
  1007   1007   #endif
         1008  +
         1009  +#define fts5BufferSafeAppendBlob(pBuf, pBlob, nBlob) {     \
         1010  +  assert( (pBuf)->nSpace>=((pBuf)->n+nBlob) );             \
         1011  +  memcpy(&(pBuf)->p[(pBuf)->n], pBlob, nBlob);             \
         1012  +  (pBuf)->n += nBlob;                                      \
         1013  +}
         1014  +
         1015  +#define fts5BufferSafeAppendVarint(pBuf, iVal) {                \
         1016  +  (pBuf)->n += sqlite3Fts5PutVarint(&(pBuf)->p[(pBuf)->n], (iVal));  \
         1017  +  assert( (pBuf)->nSpace>=(pBuf)->n );                          \
         1018  +}
         1019  +
  1008   1020   
  1009   1021   /*
  1010   1022   ** Serialize and store the "structure" record.
  1011   1023   **
  1012   1024   ** If an error occurs, leave an error code in the Fts5Index object. If an
  1013   1025   ** error has already occurred, this function is a no-op.
  1014   1026   */
................................................................................
  1020   1032   
  1021   1033       assert( pStruct->nSegment==fts5StructureCountSegments(pStruct) );
  1022   1034       memset(&buf, 0, sizeof(Fts5Buffer));
  1023   1035   
  1024   1036       /* Append the current configuration cookie */
  1025   1037       iCookie = p->pConfig->iCookie;
  1026   1038       if( iCookie<0 ) iCookie = 0;
  1027         -    fts5BufferAppend32(&p->rc, &buf, iCookie);
  1028   1039   
  1029         -    fts5BufferAppendVarint(&p->rc, &buf, pStruct->nLevel);
  1030         -    fts5BufferAppendVarint(&p->rc, &buf, pStruct->nSegment);
  1031         -    fts5BufferAppendVarint(&p->rc, &buf, (i64)pStruct->nWriteCounter);
         1040  +    if( 0==sqlite3Fts5BufferSize(&p->rc, &buf, 4+9+9+9) ){
         1041  +      sqlite3Fts5Put32(buf.p, iCookie);
         1042  +      buf.n = 4;
         1043  +      fts5BufferSafeAppendVarint(&buf, pStruct->nLevel);
         1044  +      fts5BufferSafeAppendVarint(&buf, pStruct->nSegment);
         1045  +      fts5BufferSafeAppendVarint(&buf, (i64)pStruct->nWriteCounter);
         1046  +    }
  1032   1047   
  1033   1048       for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  1034   1049         int iSeg;                     /* Used to iterate through segments */
  1035   1050         Fts5StructureLevel *pLvl = &pStruct->aLevel[iLvl];
  1036   1051         fts5BufferAppendVarint(&p->rc, &buf, pLvl->nMerge);
  1037   1052         fts5BufferAppendVarint(&p->rc, &buf, pLvl->nSeg);
  1038   1053         assert( pLvl->nMerge<=pLvl->nSeg );
................................................................................
  2599   2614   }
  2600   2615   
  2601   2616   static void fts5MultiIterNext2(
  2602   2617     Fts5Index *p, 
  2603   2618     Fts5IndexIter *pIter,
  2604   2619     int *pbNewTerm                  /* OUT: True if *might* be new term */
  2605   2620   ){
         2621  +  assert( pIter->bSkipEmpty );
  2606   2622     if( p->rc==SQLITE_OK ){
  2607   2623       do {
  2608   2624         int iFirst = pIter->aFirst[1].iFirst;
  2609   2625         Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
  2610   2626         int bNewTerm = 0;
  2611   2627   
  2612   2628         fts5SegIterNext(p, pSeg, &bNewTerm);
................................................................................
  2617   2633           fts5MultiIterSetEof(pIter);
  2618   2634           *pbNewTerm = 1;
  2619   2635         }else{
  2620   2636           *pbNewTerm = 0;
  2621   2637         }
  2622   2638         fts5AssertMultiIterSetup(p, pIter);
  2623   2639   
  2624         -    }while( pIter->bSkipEmpty && fts5MultiIterIsEmpty(p, pIter) );
         2640  +    }while( fts5MultiIterIsEmpty(p, pIter) );
  2625   2641     }
  2626   2642   }
  2627   2643   
  2628   2644   
  2629   2645   static Fts5IndexIter *fts5MultiIterAlloc(
  2630   2646     Fts5Index *p,                   /* FTS5 backend to iterate within */
  2631   2647     int nSeg
................................................................................
  3375   3391     pWriter->iSegid = iSegid;
  3376   3392   
  3377   3393     fts5WriteDlidxGrow(p, pWriter, 1);
  3378   3394     pWriter->writer.pgno = 1;
  3379   3395     pWriter->bFirstTermInPage = 1;
  3380   3396     pWriter->iBtPage = 1;
  3381   3397   
         3398  +  assert( pWriter->writer.buf.n==0 );
         3399  +  assert( pWriter->writer.pgidx.n==0 );
         3400  +
  3382   3401     /* Grow the two buffers to pgsz + padding bytes in size. */
  3383         -  fts5BufferGrow(&p->rc, &pWriter->writer.pgidx, nBuffer);
  3384         -  fts5BufferGrow(&p->rc, &pWriter->writer.buf, nBuffer);
         3402  +  sqlite3Fts5BufferSize(&p->rc, &pWriter->writer.pgidx, nBuffer);
         3403  +  sqlite3Fts5BufferSize(&p->rc, &pWriter->writer.buf, nBuffer);
  3385   3404   
  3386   3405     if( p->pIdxWriter==0 ){
  3387   3406       Fts5Config *pConfig = p->pConfig;
  3388   3407       fts5IndexPrepareStmt(p, &p->pIdxWriter, sqlite3_mprintf(
  3389   3408             "INSERT INTO '%q'.'%q_idx'(segid,term,pgno) VALUES(?,?,?)", 
  3390   3409             pConfig->zDb, pConfig->zName
  3391   3410       ));
................................................................................
  3730   3749         if( (ret + i) > nMax ) break;
  3731   3750         ret += i;
  3732   3751       }
  3733   3752     }
  3734   3753     return ret;
  3735   3754   }
  3736   3755   
  3737         -#define fts5BufferSafeAppendBlob(pBuf, pBlob, nBlob) {     \
  3738         -  assert( (pBuf)->nSpace>=((pBuf)->n+nBlob) );             \
  3739         -  memcpy(&(pBuf)->p[(pBuf)->n], pBlob, nBlob);             \
  3740         -  (pBuf)->n += nBlob;                                      \
  3741         -}
  3742         -
  3743         -#define fts5BufferSafeAppendVarint(pBuf, iVal) {                \
  3744         -  (pBuf)->n += sqlite3Fts5PutVarint(&(pBuf)->p[(pBuf)->n], (iVal));  \
  3745         -  assert( (pBuf)->nSpace>=(pBuf)->n );                          \
  3746         -}
  3747         -
  3748   3756   /*
  3749   3757   ** Flush the contents of in-memory hash table iHash to a new level-0 
  3750   3758   ** segment on disk. Also update the corresponding structure record.
  3751   3759   **
  3752   3760   ** If an error occurs, set the Fts5Index.rc error code. If an error has 
  3753   3761   ** already occurred, this function is a no-op.
  3754   3762   */
................................................................................
  4272   4280       Fts5DoclistIter i1;
  4273   4281       Fts5DoclistIter i2;
  4274   4282       Fts5Buffer out;
  4275   4283       Fts5Buffer tmp;
  4276   4284       memset(&out, 0, sizeof(out));
  4277   4285       memset(&tmp, 0, sizeof(tmp));
  4278   4286   
  4279         -    fts5BufferGrow(&p->rc, &out, p1->n + p2->n);
         4287  +    sqlite3Fts5BufferSize(&p->rc, &out, p1->n + p2->n);
  4280   4288       fts5DoclistIterInit(p1, &i1);
  4281   4289       fts5DoclistIterInit(p2, &i2);
  4282   4290       while( p->rc==SQLITE_OK && (i1.aPoslist!=0 || i2.aPoslist!=0) ){
  4283   4291         if( i2.aPoslist==0 || (i1.aPoslist && i1.iRowid<i2.iRowid) ){
  4284   4292           /* Copy entry from i1 */
  4285   4293           fts5MergeAppendDocid(&out, iLastRowid, i1.iRowid);
  4286   4294           fts5BufferSafeAppendBlob(&out, i1.aPoslist, i1.nPoslist+i1.nSize);
................................................................................
  4638   4646     Fts5IndexIter *pRet = 0;
  4639   4647     int iIdx = 0;
  4640   4648     Fts5Buffer buf = {0, 0, 0};
  4641   4649   
  4642   4650     /* If the QUERY_SCAN flag is set, all other flags must be clear. */
  4643   4651     assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
  4644   4652   
  4645         -  if( fts5BufferGrow(&p->rc, &buf, nToken+1)==0 ){
         4653  +  if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
  4646   4654       memcpy(&buf.p[1], pToken, nToken);
  4647   4655   
  4648   4656   #ifdef SQLITE_DEBUG
  4649   4657       /* If the QUERY_TEST_NOIDX flag was specified, then this must be a
  4650   4658       ** prefix-query. Instead of using a prefix-index (if one exists), 
  4651   4659       ** evaluate the prefix query using the main FTS index. This is used
  4652   4660       ** for internal sanity checking by the integrity-check in debug