3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # This file contains a very simple test to show that the deferred tokens
13 # optimization is doing something.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/malloc_common.tcl
19 ifcapable !fts3||!fts4_deferred {
23 set testprefix fts3defer3
28 # Set up a database that contains 800 rows. Each row contains the document
29 # "b b", except for the row with docid=200, which contains "a b". Hence
30 # token "b" is extremely common and token "a" is not.
34 CREATE VIRTUAL TABLE t1 USING fts4;
37 for {set i 1} {$i <= $nDoc} {incr i} {
39 if {$i==200} { set document "a b" }
40 execsql { INSERT INTO t1 (docid, content) VALUES($i, $document) }
45 # Check that the db contains two doclists. A small one for "a" and a
49 SELECT blockid, length(block) FROM t1_segments;
50 } [list 1 8 2 $nDoclist]
52 # Query for 'a b'. Although this test doesn't prove so, token "b" will
53 # be deferred because of the very large associated doclist.
56 SELECT docid, content FROM t1 WHERE t1 MATCH 'a b';
59 # Zero out the doclist for token "b" within the database file. Now the
60 # only queries that use token "b" that will work are those that defer
61 # it. Any query that tries to use the doclist belonging to token "b"
65 set fd [db incrblob t1_segments block 2]
66 puts -nonewline $fd [string repeat "\00" $nDoclist]
70 # The first two queries succeed, as they defer token "b". The last one
71 # fails, as it tries to load the corrupt doclist.
74 SELECT docid, content FROM t1 WHERE t1 MATCH 'a b';
77 SELECT count(*) FROM t1 WHERE t1 MATCH 'a b';
79 do_catchsql_test 1.7 {
80 SELECT count(*) FROM t1 WHERE t1 MATCH 'b';
81 } {1 {database disk image is malformed}}