OLD | NEW |
| (Empty) |
1 # 2014 June 17 | |
2 # | |
3 # The author disclaims copyright to this source code. In place of | |
4 # a legal notice, here is a blessing: | |
5 # | |
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. | |
9 # | |
10 #************************************************************************* | |
11 # This file implements regression tests for SQLite library. The | |
12 # focus of this script is testing the FTS5 module. | |
13 # | |
14 | |
15 source [file join [file dirname [info script]] fts5_common.tcl] | |
16 set testprefix fts5ah | |
17 | |
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file. | |
19 ifcapable !fts5 { | |
20 finish_test | |
21 return | |
22 } | |
23 | |
24 #------------------------------------------------------------------------- | |
25 # This file contains tests for very large doclists. | |
26 # | |
27 | |
28 do_test 1.0 { | |
29 execsql { CREATE VIRTUAL TABLE t1 USING fts5(a) } | |
30 execsql { INSERT INTO t1(t1, rank) VALUES('pgsz', 128) } | |
31 set v {w w w w w w w w w w w w w w w w w w w w} | |
32 execsql { INSERT INTO t1(rowid, a) VALUES(0, $v) } | |
33 for {set i 1} {$i <= 10000} {incr i} { | |
34 set v {x x x x x x x x x x x x x x x x x x x x} | |
35 if {($i % 2139)==0} {lset v 3 Y ; lappend Y $i} | |
36 if {($i % 1577)==0} {lset v 5 W ; lappend W $i} | |
37 execsql { INSERT INTO t1 VALUES($v) } | |
38 } | |
39 set v {w w w w w w w w w w w w w w w w w w w w} | |
40 execsql { INSERT INTO t1 VALUES($v) } | |
41 } {} | |
42 | |
43 do_execsql_test 1.1.1 { | |
44 SELECT rowid FROM t1 WHERE t1 MATCH 'x AND w' | |
45 } [lsort -integer -incr $W] | |
46 | |
47 do_execsql_test 1.1.2 { | |
48 SELECT rowid FROM t1 WHERE t1 MATCH 'x* AND w*' | |
49 } [lsort -integer -incr $W] | |
50 | |
51 do_execsql_test 1.2 { | |
52 SELECT rowid FROM t1 WHERE t1 MATCH 'y AND x' | |
53 } [lsort -integer -incr $Y] | |
54 | |
55 do_execsql_test 1.3 { | |
56 INSERT INTO t1(t1) VALUES('integrity-check'); | |
57 } | |
58 | |
59 proc reads {} { | |
60 db one {SELECT t1 FROM t1 WHERE t1 MATCH '*reads'} | |
61 } | |
62 | |
63 proc execsql_reads {sql} { | |
64 set nRead [reads] | |
65 execsql $sql | |
66 expr [reads] - $nRead | |
67 } | |
68 | |
69 do_test 1.4 { | |
70 set nRead [reads] | |
71 execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'x' } | |
72 set nReadX [expr [reads] - $nRead] | |
73 expr $nReadX>1000 | |
74 } {1} | |
75 | |
76 do_test 1.5 { | |
77 set fwd [execsql_reads {SELECT rowid FROM t1 WHERE t1 MATCH 'x' }] | |
78 set bwd [execsql_reads { | |
79 SELECT rowid FROM t1 WHERE t1 MATCH 'x' ORDER BY 1 ASC | |
80 }] | |
81 expr {$bwd < $fwd + 12} | |
82 } {1} | |
83 | |
84 foreach {tn q res} " | |
85 1 { SELECT rowid FROM t1 WHERE t1 MATCH 'w + x' } [list $W] | |
86 2 { SELECT rowid FROM t1 WHERE t1 MATCH 'x + w' } [list $W] | |
87 3 { SELECT rowid FROM t1 WHERE t1 MATCH 'x AND w' } [list $W] | |
88 4 { SELECT rowid FROM t1 WHERE t1 MATCH 'y AND x' } [list $Y] | |
89 " { | |
90 | |
91 do_test 1.6.$tn.1 { | |
92 set n [execsql_reads $q] | |
93 #puts -nonewline "(n=$n nReadX=$nReadX)" | |
94 expr {$n < ($nReadX / 8)} | |
95 } {1} | |
96 | |
97 do_test 1.6.$tn.2 { | |
98 set n [execsql_reads "$q ORDER BY rowid DESC"] | |
99 #puts -nonewline "(n=$n nReadX=$nReadX)" | |
100 expr {$n < ($nReadX / 8)} | |
101 } {1} | |
102 | |
103 do_execsql_test 1.6.$tn.3 $q [lsort -int -incr $res] | |
104 do_execsql_test 1.6.$tn.4 "$q ORDER BY rowid DESC" [lsort -int -decr $res] | |
105 } | |
106 | |
107 #------------------------------------------------------------------------- | |
108 # Now test that adding range constraints on the rowid field reduces the | |
109 # number of pages loaded from disk. | |
110 # | |
111 foreach {tn fraction tail cnt} { | |
112 1 0.6 {rowid > 5000} 5000 | |
113 2 0.2 {rowid > 9000} 1000 | |
114 3 0.2 {rowid < 1000} 999 | |
115 4 0.2 {rowid BETWEEN 4000 AND 5000} 1001 | |
116 5 0.6 {rowid >= 5000} 5001 | |
117 6 0.2 {rowid >= 9000} 1001 | |
118 7 0.2 {rowid <= 1000} 1000 | |
119 8 0.6 {rowid > '5000'} 5000 | |
120 9 0.2 {rowid > '9000'} 1000 | |
121 10 0.1 {rowid = 444} 1 | |
122 } { | |
123 set q "SELECT rowid FROM t1 WHERE t1 MATCH 'x' AND $tail" | |
124 set n [execsql_reads $q] | |
125 set ret [llength [execsql $q]] | |
126 | |
127 do_test "1.7.$tn.asc.(n=$n ret=$ret)" { | |
128 expr {$n < ($fraction*$nReadX) && $ret==$cnt} | |
129 } {1} | |
130 | |
131 set q "SELECT rowid FROM t1 WHERE t1 MATCH 'x' AND $tail ORDER BY rowid DESC" | |
132 set n [execsql_reads $q] | |
133 set ret [llength [execsql $q]] | |
134 do_test "1.7.$tn.desc.(n=$n ret=$ret)" { | |
135 expr {$n < 2*$fraction*$nReadX && $ret==$cnt} | |
136 } {1} | |
137 } | |
138 | |
139 do_execsql_test 1.8.1 { | |
140 SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND +rowid < 'text'; | |
141 } {10000} | |
142 do_execsql_test 1.8.2 { | |
143 SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND rowid < 'text'; | |
144 } {10000} | |
145 | |
146 | |
147 #db eval {SELECT rowid, fts5_decode(rowid, block) aS r FROM t1_data} {puts $r} | |
148 | |
149 finish_test | |
150 | |
OLD | NEW |