3 #--------------------------------------------------------------------------
4 # This script contains several sub-programs used to test FTS3/FTS4
5 # performance. It does not run the queries directly, but generates SQL
6 # scripts that can be run using the shell tool.
8 # The following cases are tested:
10 # 1. Inserting documents into an FTS3 table.
11 # 2. Optimizing an FTS3 table (i.e. "INSERT INTO t1 VALUES('optimize')").
12 # 3. Deleting documents from an FTS3 table.
13 # 4. Querying FTS3 tables.
16 # Number of tokens in vocabulary. And number of tokens in each document.
21 set NUM_INSERTS 100000
24 # Force everything in this script to be deterministic.
29 puts stderr "Usage: $::argv0 <rows> <selects>"
38 # Return a list of $nWord randomly generated tokens each between 2 and 10
39 # characters in length.
41 proc build_vocab {nWord} {
43 set chars [list a b c d e f g h i j k l m n o p q r s t u v w x y z]
44 for {set i 0} {$i<$nWord} {incr i} {
45 set len [expr {int((rand()*9.0)+2)}]
47 for {set j 0} {$j<$len} {incr j} {
48 append term [lindex $chars [expr {int(rand()*[llength $chars])}]]
56 set n [llength $::vocab]
57 set t [expr int(rand()*$n*3)]
58 if {$t>=2*$n} { set t [expr {($t-2*$n)/100}] }
59 if {$t>=$n} { set t [expr {($t-$n)/10}] }
63 proc select_doc {nTerm} {
65 for {set i 0} {$i<$nTerm} {incr i} {
66 lappend ret [select_term]
71 proc test_1 {nInsert} {
72 sql "PRAGMA synchronous = OFF;"
73 sql "DROP TABLE IF EXISTS t1;"
74 sql "CREATE VIRTUAL TABLE t1 USING fts4;"
75 for {set i 0} {$i < $nInsert} {incr i} {
76 set doc [select_doc $::DOC_SIZE]
77 sql "INSERT INTO t1 VALUES('$doc');"
82 sql "INSERT INTO t1(t1) VALUES('optimize');"
85 proc test_3 {nSelect} {
86 for {set i 0} {$i < $nSelect} {incr i} {
87 sql "SELECT count(*) FROM t1 WHERE t1 MATCH '[select_term]';"
91 proc test_4 {nSelect} {
92 for {set i 0} {$i < $nSelect} {incr i} {
93 sql "SELECT count(*) FROM t1 WHERE t1 MATCH '[select_term] [select_term]';"
97 if {[llength $argv]!=0} usage
99 set ::vocab [build_vocab $::VOCAB_SIZE]
101 set ::fd [open fts3speed_insert.sql w]
105 set ::fd [open fts3speed_select.sql w]
109 set ::fd [open fts3speed_select2.sql w]
113 set ::fd [open fts3speed_optimize.sql w]
117 puts "Success. Created files:"
118 puts " fts3speed_insert.sql"
119 puts " fts3speed_select.sql"
120 puts " fts3speed_select2.sql"
121 puts " fts3speed_optimize.sql"