/ Check-in [7cc2d60d]
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:Simplify some code in fts5_expr.c. Add some extra test cases for the same.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7cc2d60dce90b8d4dca35708e33002ae6387806e
User & Date: dan 2016-11-28 14:52:23
Context
2016-11-28
21:22
Fix broken hyperlinks to the sqlite3_snapshot objection definition in the documentation. No changes to code. check-in: 9021f687 user: drh tags: trunk
14:52
Simplify some code in fts5_expr.c. Add some extra test cases for the same. check-in: 7cc2d60d user: dan tags: trunk
2016-11-26
19:44
Add the sqlite3_snapshot_recover() interface and related functionality. check-in: b70c85ce user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_expr.c.

   742    742   }
   743    743   
   744    744   
   745    745   /*
   746    746   ** Initialize all term iterators in the pNear object. If any term is found
   747    747   ** to match no documents at all, return immediately without initializing any
   748    748   ** further iterators.
          749  +**
          750  +** If an error occurs, return an SQLite error code. Otherwise, return
          751  +** SQLITE_OK. It is not considered an error if some term matches zero
          752  +** documents.
   749    753   */
   750    754   static int fts5ExprNearInitAll(
   751    755     Fts5Expr *pExpr,
   752    756     Fts5ExprNode *pNode
   753    757   ){
   754    758     Fts5ExprNearset *pNear = pNode->pNear;
   755         -  int i, j;
   756         -  int rc = SQLITE_OK;
   757         -  int bEof = 1;
          759  +  int i;
   758    760   
   759    761     assert( pNode->bNomatch==0 );
   760         -  for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
          762  +  for(i=0; i<pNear->nPhrase; i++){
   761    763       Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
   762         -    for(j=0; j<pPhrase->nTerm; j++){
   763         -      Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
   764         -      Fts5ExprTerm *p;
   765         -
   766         -      for(p=pTerm; p && rc==SQLITE_OK; p=p->pSynonym){
   767         -        if( p->pIter ){
   768         -          sqlite3Fts5IterClose(p->pIter);
   769         -          p->pIter = 0;
   770         -        }
   771         -        rc = sqlite3Fts5IndexQuery(
   772         -            pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm),
   773         -            (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
   774         -            (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
   775         -            pNear->pColset,
   776         -            &p->pIter
   777         -        );
   778         -        assert( rc==SQLITE_OK || p->pIter==0 );
   779         -        if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){
   780         -          bEof = 0;
   781         -        }
   782         -      }
   783         -
   784         -      if( bEof ) break;
   785         -    }
   786         -    if( bEof ) break;
   787         -  }
   788         -
   789         -  pNode->bEof = bEof;
   790         -  return rc;
          764  +    if( pPhrase->nTerm==0 ){
          765  +      pNode->bEof = 1;
          766  +      return SQLITE_OK;
          767  +    }else{
          768  +      int j;
          769  +      for(j=0; j<pPhrase->nTerm; j++){
          770  +        Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
          771  +        Fts5ExprTerm *p;
          772  +        int bHit = 0;
          773  +
          774  +        for(p=pTerm; p; p=p->pSynonym){
          775  +          int rc;
          776  +          if( p->pIter ){
          777  +            sqlite3Fts5IterClose(p->pIter);
          778  +            p->pIter = 0;
          779  +          }
          780  +          rc = sqlite3Fts5IndexQuery(
          781  +              pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm),
          782  +              (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
          783  +              (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
          784  +              pNear->pColset,
          785  +              &p->pIter
          786  +          );
          787  +          assert( (rc==SQLITE_OK)==(p->pIter!=0) );
          788  +          if( rc!=SQLITE_OK ) return rc;
          789  +          if( 0==sqlite3Fts5IterEof(p->pIter) ){
          790  +            bHit = 1;
          791  +          }
          792  +        }
          793  +
          794  +        if( bHit==0 ){
          795  +          pNode->bEof = 1;
          796  +          return SQLITE_OK;
          797  +        }
          798  +      }
          799  +    }
          800  +  }
          801  +
          802  +  pNode->bEof = 0;
          803  +  return SQLITE_OK;
   791    804   }
   792    805   
   793    806   /*
   794    807   ** If pExpr is an ASC iterator, this function returns a value with the
   795    808   ** same sign as:
   796    809   **
   797    810   **   (iLhs - iRhs)

Changes to ext/fts5/test/fts5prefix.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12         -# This file containst tests focused on prefix indexes.
           12  +# This file contains tests focused on prefix indexes.
    13     13   #
    14     14   
    15     15   source [file join [file dirname [info script]] fts5_common.tcl]
    16     16   set testprefix fts5prefix
    17     17   
    18     18   # If SQLITE_ENABLE_FTS5 is defined, omit this file.
    19     19   ifcapable !fts5 {

Changes to ext/fts5/test/fts5simple2.test.

   327    327       INSERT INTO t2(rowid, x) VALUES(1, 'a b c');
   328    328       INSERT INTO t2(rowid, x) VALUES(456, 'a b c');
   329    329       INSERT INTO t2(rowid, x) VALUES(1000, 'a b c');
   330    330     COMMIT;
   331    331     UPDATE t2 SET x=x;
   332    332     DELETE FROM t2;
   333    333   }
          334  +
          335  +#-------------------------------------------------------------------------
          336  +#
          337  +reset_db
          338  +do_execsql_test 17.0 {
          339  +  CREATE VIRTUAL TABLE t2 USING fts5(x, y);
          340  +  BEGIN;
          341  +    INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
          342  +    INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
          343  +    INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
          344  +  COMMIT;
          345  +}
          346  +do_execsql_test 17.1 { SELECT * FROM t2('y:a*') WHERE rowid BETWEEN 10 AND 20 }
          347  +do_execsql_test 17.2 {
          348  +  BEGIN;
          349  +    INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
          350  +    SELECT * FROM t2('y:a*') WHERE rowid BETWEEN 10 AND 20 ;
          351  +}
          352  +do_execsql_test 17.3 {
          353  +  COMMIT
          354  +}
          355  +
          356  +reset_db
          357  +do_execsql_test 17.4 {
          358  +  CREATE VIRTUAL TABLE t2 USING fts5(x, y);
          359  +  BEGIN;
          360  +    INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
          361  +    INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
          362  +    SELECT * FROM t2('y:a*') WHERE rowid>66;
          363  +}
          364  +do_execsql_test 17.5 { SELECT * FROM t2('x:b* OR y:a*') }
          365  +do_execsql_test 17.5 { COMMIT ; SELECT * FROM t2('x:b* OR y:a*') }
          366  +do_execsql_test 17.6 { 
          367  +  SELECT * FROM t2('x:b* OR y:a*') WHERE rowid>55
          368  +}
   334    369   
   335    370   #db eval {SELECT rowid, fts5_decode_none(rowid, block) aS r FROM t2_data} {puts $r}
   336    371     
   337    372   finish_test
   338    373