|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source [file join [file dirname [info script]] fts5_common.tcl] |
|
|
set testprefix fts5ah |
|
|
|
|
|
|
|
|
ifcapable !fts5 { |
|
|
finish_test |
|
|
return |
|
|
} |
|
|
|
|
|
foreach_detail_mode $testprefix { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set Y [list] |
|
|
set W [list] |
|
|
do_test 1.0 { |
|
|
execsql { CREATE VIRTUAL TABLE t1 USING fts5(a, detail=%DETAIL%) } |
|
|
execsql { INSERT INTO t1(t1, rank) VALUES('pgsz', 128) } |
|
|
set v {w w w w w w w w w w w w w w w w w w w w} |
|
|
execsql { INSERT INTO t1(rowid, a) VALUES(0, $v) } |
|
|
for {set i 1} {$i <= 10000} {incr i} { |
|
|
set v {x x x x x x x x x x x x x x x x x x x x} |
|
|
if {($i % 2139)==0} {lset v 3 Y ; lappend Y $i} |
|
|
if {($i % 1577)==0} {lset v 5 W ; lappend W $i} |
|
|
execsql { INSERT INTO t1 VALUES($v) } |
|
|
} |
|
|
set v {w w w w w w w w w w w w w w w w w w w w} |
|
|
execsql { INSERT INTO t1 VALUES($v) } |
|
|
} {} |
|
|
|
|
|
do_execsql_test 1.1.1 { |
|
|
SELECT rowid FROM t1 WHERE t1 MATCH 'x AND w' |
|
|
} [lsort -integer -incr $W] |
|
|
|
|
|
do_execsql_test 1.1.2 { |
|
|
SELECT rowid FROM t1 WHERE t1 MATCH 'x* AND w*' |
|
|
} [lsort -integer -incr $W] |
|
|
|
|
|
do_execsql_test 1.2 { |
|
|
SELECT rowid FROM t1 WHERE t1 MATCH 'y AND x' |
|
|
} [lsort -integer -incr $Y] |
|
|
|
|
|
do_execsql_test 1.3 { |
|
|
INSERT INTO t1(t1) VALUES('integrity-check'); |
|
|
} |
|
|
|
|
|
proc reads {} { |
|
|
db one {SELECT t1 FROM t1 WHERE t1 MATCH '*reads'} |
|
|
} |
|
|
|
|
|
proc execsql_reads {sql} { |
|
|
set nRead [reads] |
|
|
execsql $sql |
|
|
expr [reads] - $nRead |
|
|
} |
|
|
|
|
|
do_test 1.4 { |
|
|
set nRead [reads] |
|
|
execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'x' } |
|
|
set nReadX [expr [reads] - $nRead] |
|
|
|
|
|
if {[detail_is_full]} { set expect 1000 } |
|
|
if {[detail_is_col]} { set expect 250 } |
|
|
if {[detail_is_none]} { set expect 80 } |
|
|
|
|
|
expr $nReadX>$expect |
|
|
} {1} |
|
|
|
|
|
do_test 1.5 { |
|
|
set fwd [execsql_reads {SELECT rowid FROM t1 WHERE t1 MATCH 'x' }] |
|
|
set bwd [execsql_reads { |
|
|
SELECT rowid FROM t1 WHERE t1 MATCH 'x' ORDER BY 1 ASC |
|
|
}] |
|
|
expr {$bwd < $fwd + 12} |
|
|
} {1} |
|
|
|
|
|
foreach {tn q res} " |
|
|
1 { SELECT rowid FROM t1 WHERE t1 MATCH 'w + x' } [list $W] |
|
|
2 { SELECT rowid FROM t1 WHERE t1 MATCH 'x + w' } [list $W] |
|
|
3 { SELECT rowid FROM t1 WHERE t1 MATCH 'x AND w' } [list $W] |
|
|
4 { SELECT rowid FROM t1 WHERE t1 MATCH 'y AND x' } [list $Y] |
|
|
" { |
|
|
if {[detail_is_full]==0 && ($tn==1 || $tn==2)} continue |
|
|
|
|
|
if {[detail_is_full]} { set ratio 8 } |
|
|
if {[detail_is_col]} { set ratio 4 } |
|
|
if {[detail_is_none]} { set ratio 2 } |
|
|
|
|
|
do_test 1.6.$tn.1 { |
|
|
set n [execsql_reads $q] |
|
|
|
|
|
expr {$n < ($nReadX / $ratio)} |
|
|
} {1} |
|
|
|
|
|
do_test 1.6.$tn.2 { |
|
|
set n [execsql_reads "$q ORDER BY rowid DESC"] |
|
|
|
|
|
expr {$n < ($nReadX / $ratio)} |
|
|
} {1} |
|
|
|
|
|
do_execsql_test 1.6.$tn.3 $q [lsort -int -incr $res] |
|
|
do_execsql_test 1.6.$tn.4 "$q ORDER BY rowid DESC" [lsort -int -decr $res] |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach {tn fraction tail cnt} { |
|
|
1 0.6 {rowid > 5000} 5000 |
|
|
2 0.2 {rowid > 9000} 1000 |
|
|
3 0.2 {rowid < 1000} 999 |
|
|
4 0.2 {rowid BETWEEN 4000 AND 5000} 1001 |
|
|
5 0.6 {rowid >= 5000} 5001 |
|
|
6 0.2 {rowid >= 9000} 1001 |
|
|
7 0.2 {rowid <= 1000} 1000 |
|
|
8 0.6 {rowid > '5000'} 5000 |
|
|
9 0.2 {rowid > '9000'} 1000 |
|
|
10 0.1 {rowid = 444} 1 |
|
|
} { |
|
|
set q "SELECT rowid FROM t1 WHERE t1 MATCH 'x' AND $tail" |
|
|
set n [execsql_reads $q] |
|
|
set ret [llength [execsql $q]] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if {[detail_is_none] && $fraction<0.5} { set fraction [expr $fraction*2] } |
|
|
|
|
|
do_test "1.7.$tn.asc.(n=$n ret=$ret)" { |
|
|
expr {$n < ($fraction*$nReadX) && $ret==$cnt} |
|
|
} {1} |
|
|
|
|
|
set q "SELECT rowid FROM t1 WHERE t1 MATCH 'x' AND $tail ORDER BY rowid DESC" |
|
|
set n [execsql_reads $q] |
|
|
set ret [llength [execsql $q]] |
|
|
do_test "1.7.$tn.desc.(n=$n ret=$ret)" { |
|
|
expr {$n < 2*$fraction*$nReadX && $ret==$cnt} |
|
|
} {1} |
|
|
} |
|
|
|
|
|
do_execsql_test 1.8.1 { |
|
|
SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND +rowid < 'text'; |
|
|
} {10000} |
|
|
do_execsql_test 1.8.2 { |
|
|
SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND rowid < 'text'; |
|
|
} {10000} |
|
|
|
|
|
do_execsql_test 1.8.3 { |
|
|
SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND rowid<5000 AND rowid < 'text'; |
|
|
} {4999} |
|
|
do_execsql_test 1.8.4 { |
|
|
SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND rowid>5000 AND rowid > 'text'; |
|
|
} {0} |
|
|
|
|
|
do_catchsql_test 1.9 { |
|
|
SELECT * FROM t1('*xy'); |
|
|
} {1 {unknown special query: xy}} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
finish_test |
|
|
|