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