OLD | NEW |
| (Empty) |
1 # 2015 April 21 | |
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 # | |
12 # This test is focused on uses of doclist-index records. | |
13 # | |
14 | |
15 source [file join [file dirname [info script]] fts5_common.tcl] | |
16 set testprefix fts5dlidx | |
17 | |
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file. | |
19 ifcapable !fts5 { | |
20 finish_test | |
21 return | |
22 } | |
23 | |
24 if { $tcl_platform(wordSize)<8 } { | |
25 finish_test | |
26 return | |
27 } | |
28 | |
29 if 1 { | |
30 | |
31 proc do_fb_test {tn sql res} { | |
32 set res2 [lsort -integer -decr $res] | |
33 uplevel [list do_execsql_test $tn.1 $sql $res] | |
34 uplevel [list do_execsql_test $tn.2 "$sql ORDER BY rowid DESC" $res2] | |
35 } | |
36 | |
37 # This test populates the FTS5 table containing $nEntry entries. Rows are | |
38 # numbered from 0 to ($nEntry-1). The rowid for row $i is: | |
39 # | |
40 # ($iFirst + $i*$nStep) | |
41 # | |
42 # Each document is of the form "a b c a b c a b c...". If the row number ($i) | |
43 # is an integer multiple of $spc1, then an "x" token is appended to the | |
44 # document. If it is *also* a multiple of $spc2, a "y" token is also appended. | |
45 # | |
46 proc do_dlidx_test1 {tn spc1 spc2 nEntry iFirst nStep} { | |
47 | |
48 do_execsql_test $tn.0 { DELETE FROM t1 } | |
49 | |
50 set xdoc [list] | |
51 set ydoc [list] | |
52 | |
53 execsql BEGIN | |
54 for {set i 0} {$i < $nEntry} {incr i} { | |
55 set rowid [expr $i * $nStep] | |
56 set doc [string trim [string repeat "a b c " 100]] | |
57 if {($i % $spc1)==0} { | |
58 lappend xdoc $rowid | |
59 append doc " x" | |
60 if {($i % $spc2)==0} { | |
61 lappend ydoc $rowid | |
62 append doc " y" | |
63 } | |
64 } | |
65 execsql { INSERT INTO t1(rowid, x) VALUES($rowid, $doc) } | |
66 } | |
67 execsql COMMIT | |
68 | |
69 breakpoint | |
70 do_test $tn.1 { | |
71 execsql { INSERT INTO t1(t1) VALUES('integrity-check') } | |
72 } {} | |
73 | |
74 do_fb_test $tn.3.1 { SELECT rowid FROM t1 WHERE t1 MATCH 'a AND x' } $xdoc | |
75 do_fb_test $tn.3.2 { SELECT rowid FROM t1 WHERE t1 MATCH 'x AND a' } $xdoc | |
76 | |
77 do_fb_test $tn.4.1 { SELECT rowid FROM t1 WHERE t1 MATCH 'a AND y' } $ydoc | |
78 do_fb_test $tn.4.2 { SELECT rowid FROM t1 WHERE t1 MATCH 'y AND a' } $ydoc | |
79 | |
80 do_fb_test $tn.5.1 { | |
81 SELECT rowid FROM t1 WHERE t1 MATCH 'a + b + c + x' } $xdoc | |
82 do_fb_test $tn.5.2 { | |
83 SELECT rowid FROM t1 WHERE t1 MATCH 'b + c + x + y' } $ydoc | |
84 } | |
85 | |
86 | |
87 foreach {tn pgsz} { | |
88 1 32 | |
89 2 200 | |
90 } { | |
91 do_execsql_test $tn.0 { | |
92 DROP TABLE IF EXISTS t1; | |
93 CREATE VIRTUAL TABLE t1 USING fts5(x); | |
94 INSERT INTO t1(t1, rank) VALUES('pgsz', $pgsz); | |
95 } | |
96 | |
97 do_dlidx_test1 1.$tn.1 10 100 10000 0 1000 | |
98 do_dlidx_test1 1.$tn.2 10 10 10000 0 128 | |
99 do_dlidx_test1 1.$tn.3 10 10 66 0 36028797018963970 | |
100 do_dlidx_test1 1.$tn.4 10 10 50 0 150000000000000000 | |
101 do_dlidx_test1 1.$tn.5 10 10 200 0 [expr 1<<55] | |
102 do_dlidx_test1 1.$tn.6 10 10 30 0 [expr 1<<58] | |
103 } | |
104 | |
105 proc do_dlidx_test2 {tn nEntry iFirst nStep} { | |
106 set str [string repeat "a " 500] | |
107 execsql { | |
108 BEGIN; | |
109 DROP TABLE IF EXISTS t1; | |
110 CREATE VIRTUAL TABLE t1 USING fts5(x); | |
111 INSERT INTO t1(t1, rank) VALUES('pgsz', 64); | |
112 INSERT INTO t1 VALUES('b a'); | |
113 | |
114 WITH iii(ii, i) AS ( | |
115 SELECT 1, $iFirst UNION ALL | |
116 SELECT ii+1, i+$nStep FROM iii WHERE ii<$nEntry | |
117 ) | |
118 INSERT INTO t1(rowid,x) SELECT i, $str FROM iii; | |
119 COMMIT; | |
120 } | |
121 | |
122 do_execsql_test $tn.1 { | |
123 SELECT rowid FROM t1 WHERE t1 MATCH 'b AND a' | |
124 } {1} | |
125 breakpoint | |
126 do_execsql_test $tn.2 { | |
127 SELECT rowid FROM t1 WHERE t1 MATCH 'b AND a' ORDER BY rowid DESC | |
128 } {1} | |
129 } | |
130 | |
131 do_dlidx_test2 2.1 [expr 20] [expr 1<<57] [expr (1<<57) + 128] | |
132 | |
133 } | |
134 | |
135 #-------------------------------------------------------------------- | |
136 # | |
137 reset_db | |
138 | |
139 set ::vocab [list \ | |
140 IteratorpItercurrentlypointstothefirstrowidofadoclist \ | |
141 Thereisadoclistindexassociatedwiththefinaltermonthecurrent \ | |
142 pageIfthecurrenttermisthelasttermonthepageloadthe \ | |
143 doclistindexfromdiskandinitializeaniteratoratpIterpDlidx \ | |
144 IteratorpItercurrentlypointstothefirstrowidofadoclist \ | |
145 Thereisadoclistindexassociatedwiththefinaltermonthecurrent \ | |
146 pageIfthecurrenttermisthelasttermonthepageloadthe \ | |
147 doclistindexfromdiskandinitializeaniteratoratpIterpDlidx \ | |
148 ] | |
149 proc rnddoc {} { | |
150 global vocab | |
151 set nVocab [llength $vocab] | |
152 set ret [list] | |
153 for {set i 0} {$i < 64} {incr i} { | |
154 lappend ret [lindex $vocab [expr $i % $nVocab]] | |
155 } | |
156 set ret | |
157 } | |
158 db func rnddoc rnddoc | |
159 | |
160 do_execsql_test 3.1 { | |
161 CREATE VIRTUAL TABLE abc USING fts5(a); | |
162 INSERT INTO abc(abc, rank) VALUES('pgsz', 32); | |
163 | |
164 INSERT INTO abc VALUES ( rnddoc() ); | |
165 INSERT INTO abc VALUES ( rnddoc() ); | |
166 INSERT INTO abc VALUES ( rnddoc() ); | |
167 INSERT INTO abc VALUES ( rnddoc() ); | |
168 | |
169 INSERT INTO abc SELECT rnddoc() FROM abc; | |
170 INSERT INTO abc SELECT rnddoc() FROM abc; | |
171 } | |
172 | |
173 | |
174 | |
175 do_execsql_test 3.2 { | |
176 SELECT rowid FROM abc WHERE abc | |
177 MATCH 'IteratorpItercurrentlypointstothefirstrowidofadoclist' | |
178 ORDER BY rowid DESC; | |
179 } {16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} | |
180 | |
181 do_execsql_test 3.2 { | |
182 INSERT INTO abc(abc) VALUES('integrity-check'); | |
183 INSERT INTO abc(abc) VALUES('optimize'); | |
184 INSERT INTO abc(abc) VALUES('integrity-check'); | |
185 } | |
186 | |
187 set v [lindex $vocab 0] | |
188 set i 0 | |
189 foreach v $vocab { | |
190 do_execsql_test 3.3.[incr i] { | |
191 SELECT rowid FROM abc WHERE abc MATCH $v | |
192 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} | |
193 } | |
194 | |
195 | |
196 finish_test | |
197 | |
OLD | NEW |