/ Check-in [507890a9]
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:Fix a problem involving a 3-way NEAR query.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 507890a9139875b1b594225c432c714f67312c0e
User & Date: dan 2009-12-04 19:07:25
Context
2009-12-04
22:51
Remove an assert() in btree.c:releasePage() that is not necessarily true when the btree is recovering from an OOM that occurs in the middle of a balance(). check-in: 04fc9c76 user: drh tags: trunk
19:07
Fix a problem involving a 3-way NEAR query. check-in: 507890a9 user: dan tags: trunk
14:25
In the OSTRACE debugging macros in os_unix.c, identify the VFS currently in use. check-in: 082b8da0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

  1047   1047     }
  1048   1048     *ppPoslist = pEnd;
  1049   1049   }
  1050   1050   
  1051   1051   static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
  1052   1052     char *pEnd = *ppPoslist;
  1053   1053     char c = 0;
         1054  +
         1055  +  /* A column-list is terminated by either a 0x01 or 0x00. */
  1054   1056     while( 0xFE & (*pEnd | c) ) c = *pEnd++ & 0x80;
  1055   1057     if( pp ){
  1056   1058       int n = (int)(pEnd - *ppPoslist);
  1057   1059       char *p = *pp;
  1058   1060       memcpy(p, *ppPoslist, n);
  1059   1061       p += n;
  1060   1062       *pp = p;
................................................................................
  1102   1104             fts3GetDeltaVarint(&p2, &i2); i2 -= 2;
  1103   1105           }
  1104   1106           fts3PutDeltaVarint(&p, &iPrev, (i1<i2 ? i1 : i2) + 2); iPrev -= 2;
  1105   1107           if( 0==(*p1&0xFE) ) i1 = 0x7FFFFFFF;
  1106   1108           if( 0==(*p2&0xFE) ) i2 = 0x7FFFFFFF;
  1107   1109         }
  1108   1110       }else if( iCol1<iCol2 ){
         1111  +      if( iCol1 ){
         1112  +        int n = sqlite3Fts3PutVarint(&p[1], iCol1);
         1113  +        *p = 0x01;
         1114  +        p += n+1;
         1115  +        p1 += n+1;
         1116  +      }
  1109   1117         fts3ColumnlistCopy(&p, &p1);
  1110   1118       }else{
         1119  +      if( iCol2 ){
         1120  +        int n = sqlite3Fts3PutVarint(&p[1], iCol2);
         1121  +        *p = 0x01;
         1122  +        p += n+1;
         1123  +        p2 += n+1;
         1124  +      }
  1111   1125         fts3ColumnlistCopy(&p, &p2);
  1112   1126       }
  1113   1127     }
  1114   1128   
  1115   1129     *p++ = '\0';
  1116   1130     *pp = p;
  1117   1131     *pp1 = p1 + 1;

Changes to test/fts3rnd.test.

    87     87     foreach {key value} [array get ::t1] {
    88     88       if {[string match $pattern $value]} { lappend ret $key }
    89     89     }
    90     90     lsort -integer $ret
    91     91   }
    92     92   
    93     93   proc simple_near {termlist nNear} {
           94  +  set ret [list]
           95  +
           96  +  # List of nNear+1 elements that contains no terms.
           97  +  #
           98  +  set dummyfields "[string repeat "X " $nNear]X"
           99  +
          100  +  foreach {key value} [array get ::t1] {
          101  +    foreach v $value {
          102  +      set v [concat $dummyfields $v $dummyfields]
          103  +
          104  +      set l [lsearch -exact -all $v [lindex $termlist 0]]
          105  +      foreach T [lrange $termlist 1 end] {
          106  +        set l2 [list]
          107  +        foreach i $l {
          108  +          set iStart [expr $i - $nNear - 1]
          109  +          set iEnd [expr $i + $nNear + 1]
          110  +          foreach i2 [lsearch -exact -all [lrange $v $iStart $iEnd] $T] {
          111  +            incr i2 $iStart
          112  +            if {$i2 != $i} { lappend l2 $i2 } 
          113  +          }
          114  +        }
          115  +        set l $l2
          116  +      }
          117  +
          118  +      if {[llength $l]} {
          119  +        lappend ret $key
          120  +      } 
          121  +    }
          122  +  }
          123  +
          124  +  lsort -unique -integer $ret
    94    125   }
    95    126   
    96    127   foreach nodesize {50 500 1000 2000} {
    97    128     catch { array unset ::t1 }
    98    129   
    99    130     # Create the FTS3 table. Populate it (and the Tcl array) with 100 rows.
   100    131     #
................................................................................
   167    198         do_test fts3rnd-1.$nodesize.$iTest.4.$i {
   168    199           execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }
   169    200         } [simple_term $term]
   170    201       }
   171    202   
   172    203       # A NEAR query with terms as the arguments.
   173    204       #
   174         -if 0 {
   175    205       for {set i 0} {$i < 10} {incr i} {
   176    206         set terms [list [random_term] [random_term]]
   177    207         set match [join $terms " NEAR "]
   178         -      do_test fts3rnd-1.$nodesize.$iTest.5.$i {
          208  +      do_test fts3rnd-1.$nodesize.$iTest.5.$i.$match {
          209  +        execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }
          210  +      } [simple_near $terms 10]
          211  +    }
          212  + 
          213  +if 0 {
          214  +    # A 3-way NEAR query with terms as the arguments.
          215  +    #
          216  +    for {set i 0} {$i < 10} {incr i} {
          217  +      set terms [list [random_term] [random_term] [random_term]]
          218  +      set match [join $terms " NEAR "]
          219  +      do_test fts3rnd-1.$nodesize.$iTest.5.$i.$match {
   179    220           execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }
   180    221         } [simple_near $terms 10]
   181    222       }
   182    223   }
   183    224     }
   184    225   }
   185    226   
   186    227   finish_test