/ Check-in [0f9df202]
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:Remove some dead code from fts5. Add auxiliary function api tests to the same.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts5
Files: files | file ages | folders
SHA1: 0f9df202cc58097afddb8dad662b7c7fdc2c7d0c
User & Date: dan 2015-05-28 14:37:26
Context
2015-05-28
19:57
Optimizations for fts5 queries that match against a specific column. check-in: b29ac50a user: dan tags: fts5
14:37
Remove some dead code from fts5. Add auxiliary function api tests to the same. check-in: 0f9df202 user: dan tags: fts5
2015-05-26
18:22
Simplifications and minor optimizations to fts5 prefix queries that cannot use a prefix index. check-in: aef89d9f user: dan tags: fts5
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to ext/fts5/fts5_index.c.

   268    268    ((i64)(height) << (FTS5_DATA_PAGE_B)) +                                       \
   269    269    ((i64)(pgno))                                                                 \
   270    270   )
   271    271   
   272    272   #define FTS5_SEGMENT_ROWID(segid, height, pgno) fts5_dri(segid, 0, height, pgno)
   273    273   #define FTS5_DLIDX_ROWID(segid, height, pgno)   fts5_dri(segid, 1, height, pgno)
   274    274   
   275         -#if 0
   276         -/*
   277         -** The height of segment b-trees is actually limited to one less than 
   278         -** (1<<HEIGHT_BITS). This is because the rowid address space for nodes
   279         -** with such a height is used by doclist indexes.
   280         -*/
   281         -#define FTS5_SEGMENT_MAX_HEIGHT ((1 << FTS5_DATA_HEIGHT_B)-1)
   282         -#endif
   283         -
   284    275   /*
   285    276   ** Maximum segments permitted in a single index 
   286    277   */
   287    278   #define FTS5_MAX_SEGMENT 2000
   288    279   
   289         -#if 0
   290         -/*
   291         -** The rowid for the doclist index associated with leaf page pgno of segment
   292         -** segid in index idx.
   293         -*/
   294         -#define FTS5_DOCLIST_IDX_ROWID(segid, height, pgno) \
   295         -        FTS5_SEGMENT_ROWID(segid, FTS5_SEGMENT_MAX_HEIGHT, pgno)
   296         -#endif
   297         -
   298    280   #ifdef SQLITE_DEBUG
   299    281   int sqlite3Fts5Corrupt() { return SQLITE_CORRUPT_VTAB; }
   300    282   #endif
   301    283   
   302    284   
   303    285   /*
   304    286   ** Each time a blob is read from the %_data table, it is padded with this
................................................................................
   768    750     if( p->pReader ){
   769    751       sqlite3_blob *pReader = p->pReader;
   770    752       p->pReader = 0;
   771    753       sqlite3_blob_close(pReader);
   772    754     }
   773    755   }
   774    756   
   775         -/*
   776         -** Check if row iRowid exists in the %_data table, and that it contains
   777         -** a blob value. If so, return SQLITE_ERROR (yes - SQLITE_ERROR, not 
   778         -** SQLITE_OK). If not, return SQLITE_CORRUPT_VTAB.
   779         -**
   780         -** If an error occurs (e.g. OOM or IOERR), return the relevant error code.
   781         -**
   782         -** This function does not need to be efficient. It is part of vary rarely
   783         -** invoked error handling code only.
   784         -*/
   785         -#if 0
   786         -static int fts5CheckMissingRowid(Fts5Index *p, i64 iRowid){
   787         -  const char *zFmt = "SELECT typeof(block)=='blob' FROM '%q'.%Q WHERE id=%lld";
   788         -  int bOk = 0;
   789         -  int rc;
   790         -  char *zSql;
   791         -
   792         -  zSql = sqlite3_mprintf(zFmt, p->pConfig->zDb, p->zDataTbl, iRowid);
   793         -  if( zSql==0 ){
   794         -    rc = SQLITE_NOMEM;
   795         -  }else{
   796         -    sqlite3_stmt *pStmt;
   797         -    rc = sqlite3_prepare_v2(p->pConfig->db, zSql, -1, &pStmt, 0);
   798         -    if( rc==SQLITE_OK ){
   799         -      if( SQLITE_ROW==sqlite3_step(pStmt) ){
   800         -        bOk = sqlite3_column_int(pStmt, 0);
   801         -      }
   802         -      rc = sqlite3_finalize(pStmt);
   803         -    }
   804         -    sqlite3_free(zSql);
   805         -  }
   806         -
   807         -  if( rc==SQLITE_OK ){
   808         -    rc = bOk ? SQLITE_ERROR : FTS5_CORRUPT;
   809         -  }
   810         -
   811         -  return rc;
   812         -}
   813         -#endif
   814         -
   815    757   static Fts5Data *fts5DataReadOrBuffer(
   816    758     Fts5Index *p, 
   817    759     Fts5Buffer *pBuf, 
   818    760     i64 iRowid
   819    761   ){
   820    762     Fts5Data *pRet = 0;
   821    763     if( p->rc==SQLITE_OK ){
................................................................................
   974    916   
   975    917     sqlite3_bind_int64(p->pDeleter, 1, iFirst);
   976    918     sqlite3_bind_int64(p->pDeleter, 2, iLast);
   977    919     sqlite3_step(p->pDeleter);
   978    920     p->rc = sqlite3_reset(p->pDeleter);
   979    921   }
   980    922   
   981         -/*
   982         -** Close the sqlite3_blob handle used to read records from the %_data table.
   983         -** And discard any cached reads. This function is called at the end of
   984         -** a read transaction or when any sub-transaction is rolled back.
   985         -*/
   986         -#if 0
   987         -static void fts5DataReset(Fts5Index *p){
   988         -  if( p->pReader ){
   989         -    sqlite3_blob_close(p->pReader);
   990         -    p->pReader = 0;
   991         -  }
   992         -}
   993         -#endif
   994         -
   995    923   /*
   996    924   ** Remove all records associated with segment iSegid.
   997    925   */
   998    926   static void fts5DataRemoveSegment(Fts5Index *p, int iSegid){
   999    927     i64 iFirst = FTS5_SEGMENT_ROWID(iSegid, 0, 0);
  1000    928     i64 iLast = FTS5_SEGMENT_ROWID(iSegid+1, 0, 0)-1;
  1001    929     fts5DataDelete(p, iFirst, iLast);
................................................................................
  3305   3233   
  3306   3234       if( pPage->buf.n>=p->pConfig->pgsz ){
  3307   3235         fts5WriteFlushLeaf(p, pWriter);
  3308   3236       }
  3309   3237     }
  3310   3238   }
  3311   3239   
  3312         -#if 0
  3313         -static void fts5WriteAppendPoslistInt(
  3314         -  Fts5Index *p, 
  3315         -  Fts5SegWriter *pWriter,
  3316         -  int iVal
  3317         -){
  3318         -  if( p->rc==SQLITE_OK ){
  3319         -    Fts5PageWriter *pPage = &pWriter->aWriter[0];
  3320         -    fts5BufferAppendVarint(&p->rc, &pPage->buf, iVal);
  3321         -    if( pPage->buf.n>=p->pConfig->pgsz ){
  3322         -      fts5WriteFlushLeaf(p, pWriter);
  3323         -    }
  3324         -  }
  3325         -}
  3326         -#endif
  3327         -
  3328   3240   static void fts5WriteAppendPoslistData(
  3329   3241     Fts5Index *p, 
  3330   3242     Fts5SegWriter *pWriter, 
  3331   3243     const u8 *aData, 
  3332   3244     int nData
  3333   3245   ){
  3334   3246     Fts5PageWriter *pPage = &pWriter->aWriter[0];
................................................................................
  3570   3482       pStruct->nSegment++;
  3571   3483   
  3572   3484       /* Read input from all segments in the input level */
  3573   3485       nInput = pLvl->nSeg;
  3574   3486     }
  3575   3487     bOldest = (pLvlOut->nSeg==1 && pStruct->nLevel==iLvl+2);
  3576   3488   
  3577         -#if 0
  3578         -fprintf(stdout, "merging %d segments from level %d!", nInput, iLvl);
  3579         -fflush(stdout);
  3580         -#endif
  3581         -
  3582   3489     assert( iLvl>=0 );
  3583   3490     for(fts5MultiIterNew(p, pStruct, 0, 0, 0, 0, iLvl, nInput, &pIter);
  3584   3491         fts5MultiIterEof(p, pIter)==0;
  3585   3492         fts5MultiIterNext(p, pIter, 0, 0)
  3586   3493     ){
  3587   3494       Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
  3588   3495       int nPos;                     /* position-list size field value */

Changes to ext/fts5/test/fts5aux.test.

   215    215     SELECT 
   216    216       my_phrasesize(t1, -1),
   217    217       my_phrasesize(t1, 0),
   218    218       my_phrasesize(t1, 1),
   219    219       my_phrasesize(t1, 2)
   220    220     FROM t1 WHERE t1 MATCH 'a OR b+c'
   221    221   } {0 1 2 0}
          222  +
          223  +#-------------------------------------------------------------------------
          224  +#
          225  +do_execsql_test 8.0 {
          226  +  CREATE VIRTUAL TABLE x1 USING fts5(a);
          227  +}
          228  +
          229  +foreach {tn lRow res} {
          230  +  4  {"a a a" "b" "a d"} {"[a] [a] [a]" "[a] d"}
          231  +  1  {"b d" "a b"}       {"[b] [d]" "[a] b"}
          232  +  2  {"d b" "a d"}       {"[d] [b]" "[a] d"}
          233  +  3  {"a a d"}           {"[a] [a] d"}
          234  +} {
          235  +  execsql { DELETE FROM x1 }
          236  +  foreach row $lRow { execsql { INSERT INTO x1 VALUES($row) } }
          237  +  breakpoint
          238  +  do_execsql_test 8.$tn {
          239  +    SELECT highlight(x1, 0, '[', ']') FROM x1 WHERE x1 MATCH 'a OR (b AND d)';
          240  +  } $res
          241  +}
   222    242   
   223    243   finish_test
   224    244   

Changes to ext/fts5/test/fts5fault5.test.

    72     72     execsql {
    73     73       CREATE VIRTUAL TABLE tt USING fts5(x);
    74     74       CREATE VIRTUAL TABLE tv USING fts5vocab(tt, 'row');
    75     75       INSERT INTO tt(tt, rank) VALUES('pgsz', 32);
    76     76       BEGIN;
    77     77     }
    78     78     for {set i 0} {$i < 20} {incr i} {
    79         -    set str [string repeat "$i " 20]
           79  +    set str [string repeat "$i " 50]
    80     80       execsql { INSERT INTO tt VALUES($str) }
    81     81     }
    82     82     execsql COMMIT
    83     83   } {}
    84     84   
    85         -do_faultsim_test 2.1 -faults oom-t* -body {
           85  +do_faultsim_test 3.1 -faults oom-t* -body {
    86     86     db eval {
    87     87       SELECT term FROM tv;
    88     88     }
    89     89   } -test {
    90     90     faultsim_test_result {0 {0 1 10 11 12 13 14 15 16 17 18 19 2 3 4 5 6 7 8 9}}
    91     91   }
    92     92   
    93     93   
    94     94   
    95     95   finish_test
    96     96