Fix another bug caused by NEAR/matchinfo/order=DESC interaction.

FossilOrigin-Name: 04907fbadeb743c95cc9f3529e63ef388684799f
This commit is contained in:
dan 2011-06-14 09:00:27 +00:00
parent c72f9d98cb
commit 2cf1a1de4b
5 changed files with 87 additions and 37 deletions

View File

@ -3387,7 +3387,6 @@ void sqlite3Fts3DoclistPrev(
u8 *pbEof /* OUT: End-of-file flag */
){
char *p = *ppIter;
int iMul = (bDescIdx ? -1 : 1);
assert( nDoclist>0 );
assert( *pbEof==0 );
@ -3399,10 +3398,8 @@ void sqlite3Fts3DoclistPrev(
char *pNext = 0;
char *pDocid = aDoclist;
char *pEnd = &aDoclist[nDoclist];
int iMul = 1;
pDocid += sqlite3Fts3GetVarint(pDocid, &iDocid);
pNext = pDocid;
fts3PoslistCopy(0, &pDocid);
while( pDocid<pEnd ){
sqlite3_int64 iDelta;
pDocid += sqlite3Fts3GetVarint(pDocid, &iDelta);
@ -3410,12 +3407,14 @@ void sqlite3Fts3DoclistPrev(
pNext = pDocid;
fts3PoslistCopy(0, &pDocid);
while( pDocid<pEnd && *pDocid==0 ) pDocid++;
iMul = (bDescIdx ? -1 : 1);
}
*pnList = pEnd - pNext;
*ppIter = pNext;
*piDocid = iDocid;
}else{
int iMul = (bDescIdx ? -1 : 1);
sqlite3_int64 iDelta;
fts3GetReverseVarint(&p, aDoclist, &iDelta);
*piDocid -= (iMul * iDelta);

View File

@ -1,5 +1,5 @@
C Merge\srecent\strunk\schanges\sinto\sfts3-prefix-search\sbranch.
D 2011-06-14T07:22:30.078
C Fix\sanother\sbug\scaused\sby\sNEAR/matchinfo/order=DESC\sinteraction.
D 2011-06-14T09:00:27.140
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c1d7a7f4fd8da6b1815032efca950e3d5125407e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -61,7 +61,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 5d59c015d60379d399bbd1e1a597624237fd4583
F ext/fts3/fts3.c ae3ae91d204d177fc37a22c7bc5a3a9df70e65a0
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3Int.h a999cfbf605efec293a88519f74192f5204c84d6
F ext/fts3/fts3_aux.c baed9dab7fb4604ae8cafdb2d7700abe93beffbe
@ -455,7 +455,7 @@ F test/fts3am.test 218aa6ba0dfc50c7c16b2022aac5c6be593d08d8
F test/fts3an.test a49ccadc07a2f7d646ec1b81bc09da2d85a85b18
F test/fts3ao.test b83f99f70e9eec85f27d75801a974b3f820e01f9
F test/fts3atoken.test 402ef2f7c2fb4b3d4fa0587df6441c1447e799b3
F test/fts3auto.test 0173f3fc3e03d66beb6dd65f7b99e7eb4ae2a27d
F test/fts3auto.test 337dff2758887bfe7d337f76d25cc48db6e26f28
F test/fts3aux1.test 0b02743955d56fc0d4d66236a26177bd1b726de0
F test/fts3b.test e93bbb653e52afde110ad53bbd793f14fe7a8984
F test/fts3c.test fc723a9cf10b397fdfc2b32e73c53c8b1ec02958
@ -614,7 +614,7 @@ F test/pageropt.test 8146bf448cf09e87bb1867c2217b921fb5857806
F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb
F test/pcache.test 065aa286e722ab24f2e51792c1f093bf60656b16
F test/pcache2.test 0d85f2ab6963aee28c671d4c71bec038c00a1d16
F test/permutations.test d27eac16dae111ff7cec331dab4bca08625ba65a
F test/permutations.test 3a0d43a3e92f74f49be42ddc580e9b1ec361ba0e
F test/pragma.test fdfc09067ea104a0c247a1a79d8093b56656f850
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea
@ -945,7 +945,7 @@ F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
F tool/symbols.sh bc2a3709940d47c8ac8e0a1fdf17ec801f015a00
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings.sh 347d974d143cf132f953b565fbc03026f19fcb4d
P 06de3f2cbc27cdfd9f83218c9ea576f74f60d07b 77f01578bb565d1bc884b374b68bae10ce34a084
R 4b70a0fb05718888a014edb1bc0cc1e6
P 135ce30f62ebd6a1b239c18dbbd9c926ea507db4
R 6437acdf1435a01de33437d42862b03a
U dan
Z 363a76362b64a627be0e398551d0d1e2
Z 0ea30b6b1ae90b1e541e7d3c3cb40fc6

View File

@ -1 +1 @@
135ce30f62ebd6a1b239c18dbbd9c926ea507db4
04907fbadeb743c95cc9f3529e63ef388684799f

View File

@ -40,11 +40,38 @@ set sqlite_fts3_enable_parentheses 1
# (for closing) character of a list element. i.e. the expression "(a OR b)c"
# will not be parsed correctly, but "( a OR b) c" will.
#
# Available OPTIONS are:
#
# -deferred TOKENLIST
#
# If the "deferred" option is supplied, it is passed a list of tokens that
# are deferred by FTS and result in the relevant matchinfo() stats being an
# approximation.
#
set sqlite_fts3_enable_parentheses 1
proc do_fts3query_test {tn tbl expr} {
proc do_fts3query_test {tn args} {
get_near_results $tbl $expr aMatchinfo
set match $expr
set nArg [llength $args]
if {$nArg < 2 || ($nArg % 2)} {
set cmd do_fts3query_test
error "wrong # args: should be \"$cmd ?-deferred LIST? TABLE MATCHEXPR\""
}
set tbl [lindex $args [expr $nArg-2]]
set match [lindex $args [expr $nArg-1]]
set deferred [list]
foreach {k v} [lrange $args 0 [expr $nArg-3]] {
switch -- $k {
-deferred {
set deferred $v
}
default {
error "bad option \"$k\": must be -deferred"
}
}
}
get_near_results $tbl $match $deferred aMatchinfo
set matchinfo_asc [list]
foreach docid [lsort -integer -incr [array names aMatchinfo]] {
@ -97,7 +124,7 @@ proc fix_near_expr {expr} {
return $out
}
proc get_single_near_results {tbl expr arrayvar nullvar} {
proc get_single_near_results {tbl expr deferred arrayvar nullvar} {
upvar $arrayvar aMatchinfo
upvar $nullvar nullentry
catch {array unset aMatchinfo}
@ -153,12 +180,12 @@ proc get_single_near_results {tbl expr arrayvar nullvar} {
}
}
if {[info exists ::fts3_deferred] && [llength $expr]==1} {
if {[llength $deferred] && [llength $expr]==1} {
set phrase [lindex $expr 0]
set rewritten [list]
set partial 0
foreach tok $phrase {
if {[lsearch $::fts3_deferred $tok]>=0} {
if {[lsearch $deferred $tok]>=0} {
lappend rewritten *
} else {
lappend rewritten $tok
@ -178,7 +205,7 @@ proc get_single_near_results {tbl expr arrayvar nullvar} {
while {[lindex $rewritten 0] == "*"} {
set rewritten [lrange $rewritten 1 end]
}
get_single_near_results $tbl [list $rewritten] aRewrite nullentry
get_single_near_results $tbl [list $rewritten] {} aRewrite nullentry
foreach docid [array names hits] {
set aMatchinfo($docid) $aRewrite($docid)
}
@ -228,7 +255,7 @@ proc matching_brackets {expr} {
return [expr ($iBracket==0 && $i==$nExpr)]
}
proc get_near_results {tbl expr arrayvar {nullvar ""}} {
proc get_near_results {tbl expr deferred arrayvar {nullvar ""}} {
upvar $arrayvar aMatchinfo
if {$nullvar != ""} { upvar $nullvar nullentry }
@ -260,13 +287,13 @@ proc get_near_results {tbl expr arrayvar {nullvar ""}} {
if {$iBracket!=0} { error "mismatched brackets in: $expr" }
if {[info exists opidx]==0} {
get_single_near_results $tbl $expr aMatchinfo nullentry
get_single_near_results $tbl $expr $deferred aMatchinfo nullentry
} else {
set eLeft [lrange $expr 0 [expr $opidx-1]]
set eRight [lrange $expr [expr $opidx+1] end]
get_near_results $tbl $eLeft aLeft nullleft
get_near_results $tbl $eRight aRight nullright
get_near_results $tbl $eLeft $deferred aLeft nullleft
get_near_results $tbl $eRight $deferred aRight nullright
switch -- [lindex $expr $opidx] {
"NOT" {
@ -390,8 +417,6 @@ foreach {tn create} {
proc make_token_deferrable {tbl token} {
set nRow [db one "SELECT count(*) FROM $tbl"]
set pgsz [db one "PRAGMA page_size"]
execsql "INSERT INTO $tbl ($tbl) VALUES('maxpending=100000000')"
execsql BEGIN
for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
set doc [string repeat "$token " 100]
@ -421,28 +446,54 @@ foreach {tn create} {
make_token_deferrable t1 c
set ::fts3_deferred [list]
foreach {tn2 expr} {
1 {a OR c}
} {
do_fts3query_test 3.$tn.2.$tn2 t1 $expr
}
set ::fts3_deferred [list c]
execsql {
UPDATE t1_segments
SET block = zeroblob(length(block))
WHERE length(block)>10000 AND 0
}
foreach {tn2 expr} {
1 {a NEAR c}
2 {a AND c}
3 {"a c"}
4 {"c a"}
5 {"a c" NEAR/1 g}
6 {"a c" NEAR/0 g}
foreach {tn2 expr def} {
1 {a NEAR c} {}
2 {a AND c} c
3 {"a c"} c
4 {"c a"} c
5 {"a c" NEAR/1 g} {}
6 {"a c" NEAR/0 g} {}
} {
do_fts3query_test 3.$tn.2.$tn2 t1 $expr
do_fts3query_test 3.$tn.2.$tn2 -deferred $def t1 $expr
}
}
#--------------------------------------------------------------------------
#
foreach {tn create} {
1 "fts4(x, y)"
2 "fts4(x, y, order=DESC)"
} {
catchsql { DROP TABLE t1 }
execsql "CREATE VIRTUAL TABLE t1 USING $create"
foreach {x y} {
{one two five four five} {}
{} {one two five four five}
{one two} {five four five}
} {
execsql {INSERT INTO t1 VALUES($x, $y)}
}
foreach {tn2 expr} {
1 {one AND five}
2 {one NEAR five}
3 {one NEAR/1 five}
4 {one NEAR/2 five}
5 {one NEAR/3 five}
} {
do_fts3query_test 4.$tn.2.$tn2 t1 $expr
}
}

View File

@ -183,7 +183,7 @@ test_suite "fts3" -prefix "" -description {
fts3fault.test fts3malloc.test fts3matchinfo.test
fts3aux1.test fts3comp1.test
fts3aux1.test fts3comp1.test fts3auto.test
}