mirror of
https://github.com/sqlite/sqlite.git
synced 2025-09-02 12:21:26 +03:00
Add a couple of extra tests.
FossilOrigin-Name: aefd46dfae7e06fbaf4f2b9a86a7f2ac6927331e
This commit is contained in:
@@ -21,10 +21,14 @@ set sfep $sqlite_fts3_enable_parentheses
|
||||
set sqlite_fts3_enable_parentheses 1
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Start of Tcl infrastructure used by tests. The entry point is
|
||||
# [do_fts3query_test] (described below).
|
||||
# Start of Tcl infrastructure used by tests. The entry points are:
|
||||
#
|
||||
# do_fts3query_test
|
||||
# fts3_make_deferrable
|
||||
# fts3_zero_long_segments
|
||||
#
|
||||
|
||||
#
|
||||
# do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR
|
||||
#
|
||||
# This proc runs several test cases on FTS3/4 table $TABLE using match
|
||||
@@ -103,6 +107,38 @@ proc do_fts3query_test {tn args} {
|
||||
" $matchinfo_asc
|
||||
}
|
||||
|
||||
# fts3_make_deferrable TABLE TOKEN
|
||||
#
|
||||
proc fts3_make_deferrable {tbl token} {
|
||||
|
||||
set stmt [sqlite3_prepare db "SELECT * FROM $tbl" -1 dummy]
|
||||
set name [sqlite3_column_name $stmt 0]
|
||||
sqlite3_finalize $stmt
|
||||
|
||||
set nRow [db one "SELECT count(*) FROM $tbl"]
|
||||
set pgsz [db one "PRAGMA page_size"]
|
||||
execsql BEGIN
|
||||
for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
|
||||
set doc [string repeat "$token " 100]
|
||||
execsql "INSERT INTO $tbl ($name) VALUES(\$doc)"
|
||||
}
|
||||
execsql "INSERT INTO $tbl ($name) VALUES('aaaaaaa ${token}aaaaa')"
|
||||
execsql COMMIT
|
||||
|
||||
return [expr $nRow*$pgsz]
|
||||
}
|
||||
|
||||
# fts3_zero_long_segments TABLE ?LIMIT?
|
||||
#
|
||||
proc fts3_zero_long_segments {tbl limit} {
|
||||
execsql "
|
||||
UPDATE ${tbl}_segments
|
||||
SET block = zeroblob(length(block))
|
||||
WHERE length(block)>$limit
|
||||
"
|
||||
return [db changes]
|
||||
}
|
||||
|
||||
|
||||
proc mit {blob} {
|
||||
set scan(littleEndian) i*
|
||||
@@ -414,17 +450,6 @@ foreach {tn create} {
|
||||
#--------------------------------------------------------------------------
|
||||
# Some test cases involving deferred tokens.
|
||||
#
|
||||
proc make_token_deferrable {tbl token} {
|
||||
set nRow [db one "SELECT count(*) FROM $tbl"]
|
||||
set pgsz [db one "PRAGMA page_size"]
|
||||
execsql BEGIN
|
||||
for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
|
||||
set doc [string repeat "$token " 100]
|
||||
execsql "INSERT INTO $tbl VALUES(\$doc)"
|
||||
}
|
||||
execsql "INSERT INTO $tbl VALUES('aaaaaaa ${token}aaaaa')"
|
||||
execsql COMMIT
|
||||
}
|
||||
|
||||
foreach {tn create} {
|
||||
1 "fts4(x)"
|
||||
@@ -444,19 +469,14 @@ foreach {tn create} {
|
||||
INSERT INTO t1(docid, x) VALUES(6, 'c a b');
|
||||
}
|
||||
|
||||
make_token_deferrable t1 c
|
||||
set limit [fts3_make_deferrable t1 c]
|
||||
|
||||
foreach {tn2 expr} {
|
||||
1 {a OR c}
|
||||
} {
|
||||
do_fts3query_test 3.$tn.2.$tn2 t1 $expr
|
||||
}
|
||||
do_fts3query_test 3.$tn.2.1 t1 {a OR c}
|
||||
|
||||
do_test 3.$tn.3 {
|
||||
fts3_zero_long_segments t1 $limit
|
||||
} {1}
|
||||
|
||||
execsql {
|
||||
UPDATE t1_segments
|
||||
SET block = zeroblob(length(block))
|
||||
WHERE length(block)>10000 AND 0
|
||||
}
|
||||
foreach {tn2 expr def} {
|
||||
1 {a NEAR c} {}
|
||||
2 {a AND c} c
|
||||
@@ -465,36 +485,49 @@ foreach {tn create} {
|
||||
5 {"a c" NEAR/1 g} {}
|
||||
6 {"a c" NEAR/0 g} {}
|
||||
} {
|
||||
do_fts3query_test 3.$tn.2.$tn2 -deferred $def t1 $expr
|
||||
do_fts3query_test 3.$tn.4.$tn2 -deferred $def t1 $expr
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
foreach {tn create} {
|
||||
1 "fts4(x, y)"
|
||||
2 "fts4(x, y, order=DESC)"
|
||||
3 "fts4(x, y, order=DESC, prefix=2)"
|
||||
} {
|
||||
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)}
|
||||
}
|
||||
execsql [subst {
|
||||
DROP TABLE t1;
|
||||
CREATE VIRTUAL TABLE t1 USING $create;
|
||||
INSERT INTO t1 VALUES('one two five four five', '');
|
||||
INSERT INTO t1 VALUES('', 'one two five four five');
|
||||
INSERT INTO t1 VALUES('one two', 'five four five');
|
||||
}]
|
||||
|
||||
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
|
||||
}
|
||||
do_fts3query_test 4.$tn.1.1 t1 {one AND five}
|
||||
do_fts3query_test 4.$tn.1.2 t1 {one NEAR five}
|
||||
do_fts3query_test 4.$tn.1.3 t1 {one NEAR/1 five}
|
||||
do_fts3query_test 4.$tn.1.4 t1 {one NEAR/2 five}
|
||||
do_fts3query_test 4.$tn.1.5 t1 {one NEAR/3 five}
|
||||
|
||||
do_test 4.$tn.2 {
|
||||
set limit [fts3_make_deferrable t1 five]
|
||||
execsql { INSERT INTO t1(t1) VALUES('optimize') }
|
||||
expr {[fts3_zero_long_segments t1 $limit]>0}
|
||||
} {1}
|
||||
|
||||
do_fts3query_test 4.$tn.3.1 -deferred five t1 {one AND five}
|
||||
do_fts3query_test 4.$tn.3.2 -deferred five t1 {one NEAR five}
|
||||
do_fts3query_test 4.$tn.3.3 -deferred five t1 {one NEAR/1 five}
|
||||
do_fts3query_test 4.$tn.3.4 -deferred five t1 {one NEAR/2 five}
|
||||
do_fts3query_test 4.$tn.3.5 -deferred five t1 {one NEAR/3 five}
|
||||
|
||||
do_fts3query_test 4.$tn.4.1 -deferred fi* t1 {on* AND fi*}
|
||||
do_fts3query_test 4.$tn.4.2 -deferred fi* t1 {on* NEAR fi*}
|
||||
do_fts3query_test 4.$tn.4.3 -deferred fi* t1 {on* NEAR/1 fi*}
|
||||
do_fts3query_test 4.$tn.4.4 -deferred fi* t1 {on* NEAR/2 fi*}
|
||||
do_fts3query_test 4.$tn.4.5 -deferred fi* t1 {on* NEAR/3 fi*}
|
||||
}
|
||||
|
||||
set sqlite_fts3_enable_parentheses $sfep
|
||||
|
Reference in New Issue
Block a user