]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix another bug in 3-way NEAR queries.
authordan <dan@noemail.net>
Sat, 5 Dec 2009 14:29:22 +0000 (14:29 +0000)
committerdan <dan@noemail.net>
Sat, 5 Dec 2009 14:29:22 +0000 (14:29 +0000)
FossilOrigin-Name: 3bb13a06521b54194c9f3eb44e0dc42bacf016a4

ext/fts3/fts3.c
manifest
manifest.uuid
test/fts3rnd.test

index d41f10ea30f500d6f0e6003e2646b1b035e44360..ee3981cfb99626a7c0172e48b223ffcc1dc9f4b7 100644 (file)
@@ -1124,11 +1124,17 @@ static void fts3PoslistMerge(
   char *p1 = *pp1;
   char *p2 = *pp2;
 
-  while( *p1 && *p2 ){
-    int iCol1 = 0;
-    int iCol2 = 0;
+  while( *p1 || *p2 ){
+    int iCol1;
+    int iCol2;
+
     if( *p1==0x01 ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
+    else if( *p1==0x00 ) iCol1 = OFFSET_LIST_END;
+    else iCol1 = 0;
+
     if( *p2==0x01 ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
+    else if( *p2==0x00 ) iCol2 = OFFSET_LIST_END;
+    else iCol2 = 0;
 
     if( iCol1==iCol2 ){
       sqlite3_int64 i1 = 0;
@@ -1381,6 +1387,10 @@ static int fts3DoclistMerge(
   if( !aBuffer ){
     return SQLITE_NOMEM;
   }
+  if( n1==0 && n2==0 ){
+    *pnBuffer = 0;
+    return SQLITE_OK;
+  }
 
   /* Read the first docid from each doclist */
   fts3GetDeltaVarint2(&p1, pEnd1, &i1);
index 80a34d4a1e6a9384f526962c11e3d93bca7c1c82..298b9feaeb9c8a40760e146384b91a904de827ff 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\ssome\sproblems\swith\sFTS3\sand\s3-way\sNEAR\squeries.
-D 2009-12-05T11:37:19
+C Fix\sanother\sbug\sin\s3-way\sNEAR\squeries.
+D 2009-12-05T14:29:23
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -56,7 +56,7 @@ F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0
 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
 F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9
 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
-F ext/fts3/fts3.c 7d344410bffdddf98c1af623993dd284e156a89f
+F ext/fts3/fts3.c f4152f277722781048c9bba19aa605dbb831ad9a
 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
 F ext/fts3/fts3Int.h cc716c74afa7da8e0f8ef39404f33ea62a823eb3
 F ext/fts3/fts3_expr.c c18794a62c257d3456d3314c5a18e348ae0d84bd
@@ -402,7 +402,7 @@ F test/fts3expr.test 05dab77387801e4900009917bb18f556037d82da
 F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a
 F test/fts3malloc.test d02ee86b21edd2b43044e0d6dfdcd26cb6efddcb
 F test/fts3near.test dc196dd17b4606f440c580d45b3d23aa975fd077
-F test/fts3rnd.test 071ff7ed7bf60f8f7502a3e09cbc680dbd795da1
+F test/fts3rnd.test 151071849c9db2bade6e3d3c0c20e3a8f4f30892
 F test/func.test af106ed834001738246d276659406823e35cde7b
 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
 F test/fuzz.test a4174c3009a3e2c2e14b31b364ebf7ddb49de2c9
@@ -776,7 +776,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 08faee686eb2fabe0dde51231ee55880e78541e8
-R b8a65915c3bbacc7a62e1d6f19ca7f03
+P 23dc6fb5b28712d1ba18dc7ddb3f2ef3b469d611
+R bd59d2e643443e6c4d242260f4459347
 U dan
-Z bdcaf8016833561b09539543f7f27b88
+Z 684064b55602f4b676c31d5b0005b496
index 61482edf96492253c0aff0d9e0a288dda3232b5a..16a33ee6635f04e997d76bdebbe5b8843e764805 100644 (file)
@@ -1 +1 @@
-23dc6fb5b28712d1ba18dc7ddb3f2ef3b469d611
\ No newline at end of file
+3bb13a06521b54194c9f3eb44e0dc42bacf016a4
\ No newline at end of file
index 057fd5fa27230af18d869308594acc8403ab8126..7747855bc87f24c5a2202dac9728350ac820a8ee 100644 (file)
@@ -93,13 +93,8 @@ proc simple_prefix {zPrefix} {
 proc simple_near {termlist nNear} {
   set ret [list]
 
-  # List of nNear+1 elements that contains no terms.
-  #
-  set dummyfields "[string repeat "X " $nNear]X"
-
   foreach {key value} [array get ::t1] {
     foreach v $value {
-      set v [concat $dummyfields $v $dummyfields]
 
       set l [lsearch -exact -all $v [lindex $termlist 0]]
       foreach T [lrange $termlist 1 end] {
@@ -107,15 +102,17 @@ proc simple_near {termlist nNear} {
         foreach i $l {
           set iStart [expr $i - $nNear - 1]
           set iEnd [expr $i + $nNear + 1]
+          if {$iStart < 0} {set iStart 0}
           foreach i2 [lsearch -exact -all [lrange $v $iStart $iEnd] $T] {
             incr i2 $iStart
             if {$i2 != $i} { lappend l2 $i2 } 
           }
         }
-        set l $l2
+        set l [lsort -uniq -integer $l2]
       }
 
       if {[llength $l]} {
+#puts "MATCH($key): $v"
         lappend ret $key
       } 
     }
@@ -155,7 +152,7 @@ foreach nodesize {50 500 1000 2000} {
       update_row $iUpdate
       delete_row $iDelete
     }
-  
+
     # Pick 10 terms from the vocabulary. Check that the results of querying
     # the database for the set of documents containing each of these terms
     # is the same as the result obtained by scanning the contents of the Tcl 
@@ -210,17 +207,19 @@ foreach nodesize {50 500 1000 2000} {
       } [simple_near $terms 10]
     }
  
-if 0 {
     # A 3-way NEAR query with terms as the arguments.
     #
     for {set i 0} {$i < 10} {incr i} {
       set terms [list [random_term] [random_term] [random_term]]
-      set match [join $terms " NEAR "]
+      set nNear 11
+      set match [join $terms " NEAR/$nNear "]
+      set fts3 [execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }]
+      set tcl [simple_near $terms $nNear]
       do_test fts3rnd-1.$nodesize.$iTest.5.$i.$match {
         execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }
-      } [simple_near $terms 10]
+      } [simple_near $terms $nNear]
+if {$::nErr} {exit -1}
     }
-}
   }
 }