/ Check-in [e78f6f3b]
Login

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

Overview
Comment:Fix an fts5 problem causing a crash in phrase queries where the first token of the phrase matches one or more rows but some other token within the phrase matches zero.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e78f6f3bbf4781850960fe6741f7cba480f2c27d
User & Date: dan 2016-11-14 08:19:37
Context
2016-11-23
20:37
Fix an fts5 problem causing a crash in phrase queries where the first token of the phrase matches one or more rows but some other token within the phrase matches zero. check-in: 4efd331e user: drh tags: branch-3.15
2016-11-14
15:28
Avoid unnecessary calls to sqlite3ExprCacheAffinityChange() when generating OP_MakeRecord opcodes that do not change any register affinities. check-in: e211c579 user: drh tags: trunk
08:19
Fix an fts5 problem causing a crash in phrase queries where the first token of the phrase matches one or more rows but some other token within the phrase matches zero. check-in: e78f6f3b user: dan tags: trunk
2016-11-11
20:37
Fix harmless compiler warnings in test code for MSVC. check-in: 7b76be41 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_expr.c.

   916    916             if( fts5ExprSynonymAdvanceto(pTerm, bDesc, &iLast, &rc) ){
   917    917               pNode->bNomatch = 0;
   918    918               pNode->bEof = 1;
   919    919               return rc;
   920    920             }
   921    921           }else{
   922    922             Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
   923         -          if( pIter->iRowid==iLast ) continue;
          923  +          if( pIter->iRowid==iLast || pIter->bEof ) continue;
   924    924             bMatch = 0;
   925    925             if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
   926    926               return rc;
   927    927             }
   928    928           }
   929    929         }
   930    930       }

Changes to ext/fts5/fts5_index.c.

  2836   2836   static void fts5MultiIterNext(
  2837   2837     Fts5Index *p, 
  2838   2838     Fts5Iter *pIter,
  2839   2839     int bFrom,                      /* True if argument iFrom is valid */
  2840   2840     i64 iFrom                       /* Advance at least as far as this */
  2841   2841   ){
  2842   2842     int bUseFrom = bFrom;
         2843  +  assert( pIter->base.bEof==0 );
  2843   2844     while( p->rc==SQLITE_OK ){
  2844   2845       int iFirst = pIter->aFirst[1].iFirst;
  2845   2846       int bNewTerm = 0;
  2846   2847       Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
  2847   2848       assert( p->rc==SQLITE_OK );
  2848   2849       if( bUseFrom && pSeg->pDlidx ){
  2849   2850         fts5SegIterNextFrom(p, pSeg, iFrom);

Changes to ext/fts5/test/fts5simple3.test.

    75     75   do_execsql_test 3.0 {
    76     76     CREATE VIRTUAL TABLE x3 USING fts5(one);
    77     77     INSERT INTO x3 VALUES('a b c');
    78     78     INSERT INTO x3 VALUES('c b a');
    79     79     INSERT INTO x3 VALUES('o t t');
    80     80     SELECT * FROM x3('x OR y OR z');
    81     81   }
           82  +
           83  +#-------------------------------------------------------------------------
           84  +# Test that a crash occuring when the second or subsequent tokens in a
           85  +# phrase matched zero rows has been fixed.
           86  +#
           87  +do_execsql_test 4.0 {
           88  +  CREATE VIRTUAL TABLE t1 USING fts5(x);
           89  +  INSERT INTO t1 VALUES('ab');
           90  +  INSERT INTO t1 VALUES('cd');
           91  +  INSERT INTO t1 VALUES('ab cd');
           92  +  INSERT INTO t1 VALUES('ab cdXXX');
           93  +  INSERT INTO t1 VALUES('abXXX cd');
           94  +}
           95  +do_execsql_test 4.1 {
           96  +  SELECT * FROM t1('"ab cd" OR "ab cd" *');
           97  +} {{ab cd} {ab cdXXX}}
           98  +do_execsql_test 4.2 {
           99  +  SELECT * FROM t1('"xy zz" OR "ab cd" *');
          100  +} {{ab cd} {ab cdXXX}}
          101  +do_execsql_test 4.3 {
          102  +  SELECT * FROM t1('"xy zz" OR "xy zz" *');
          103  +}
          104  +do_execsql_test 4.4 {
          105  +  SELECT * FROM t1('"ab cd" OR "xy zz" *');
          106  +} {{ab cd}}
          107  +do_execsql_test 4.5 {
          108  +  CREATE VIRTUAL TABLE t2 USING fts5(x);
          109  +  INSERT INTO t2 VALUES('ab');
          110  +  INSERT INTO t2 VALUES('cd');
          111  +  INSERT INTO t2 VALUES('ef');
          112  +} 
          113  +do_execsql_test 4.6 {
          114  +  SELECT * FROM t2('ab + xyz');
          115  +}
    82    116   
    83    117   
    84    118   finish_test
    85    119