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 foreach_detail_mode $testprefix { |
| 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 with $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 if {[detail_is_full]} { |
| 81 do_fb_test $tn.5.1 { |
| 82 SELECT rowid FROM t1 WHERE t1 MATCH 'a + b + c + x' } $xdoc |
| 83 do_fb_test $tn.5.2 { |
| 84 SELECT rowid FROM t1 WHERE t1 MATCH 'b + c + x + y' } $ydoc |
| 85 } |
| 86 } |
| 87 |
| 88 |
| 89 foreach {tn pgsz} { |
| 90 1 32 |
| 91 2 200 |
| 92 } { |
| 93 do_execsql_test $tn.0 { |
| 94 DROP TABLE IF EXISTS t1; |
| 95 CREATE VIRTUAL TABLE t1 USING fts5(x, detail=%DETAIL%); |
| 96 INSERT INTO t1(t1, rank) VALUES('pgsz', $pgsz); |
| 97 } |
| 98 |
| 99 do_dlidx_test1 1.$tn.1 10 100 10000 0 1000 |
| 100 do_dlidx_test1 1.$tn.2 10 10 10000 0 128 |
| 101 do_dlidx_test1 1.$tn.3 10 10 66 0 36028797018963970 |
| 102 do_dlidx_test1 1.$tn.4 10 10 50 0 150000000000000000 |
| 103 do_dlidx_test1 1.$tn.5 10 10 200 0 [expr 1<<55] |
| 104 do_dlidx_test1 1.$tn.6 10 10 30 0 [expr 1<<58] |
| 105 } |
| 106 |
| 107 proc do_dlidx_test2 {tn nEntry iFirst nStep} { |
| 108 set str [string repeat "a " 500] |
| 109 execsql { |
| 110 BEGIN; |
| 111 DROP TABLE IF EXISTS t1; |
| 112 CREATE VIRTUAL TABLE t1 USING fts5(x, detail=%DETAIL%); |
| 113 INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 114 INSERT INTO t1 VALUES('b a'); |
| 115 |
| 116 WITH iii(ii, i) AS ( |
| 117 SELECT 1, $iFirst UNION ALL |
| 118 SELECT ii+1, i+$nStep FROM iii WHERE ii<$nEntry |
| 119 ) |
| 120 INSERT INTO t1(rowid,x) SELECT i, $str FROM iii; |
| 121 COMMIT; |
| 122 } |
| 123 |
| 124 do_execsql_test $tn.1 { |
| 125 SELECT rowid FROM t1 WHERE t1 MATCH 'b AND a' |
| 126 } {1} |
| 127 breakpoint |
| 128 do_execsql_test $tn.2 { |
| 129 SELECT rowid FROM t1 WHERE t1 MATCH 'b AND a' ORDER BY rowid DESC |
| 130 } {1} |
| 131 } |
| 132 |
| 133 do_dlidx_test2 2.1 [expr 20] [expr 1<<57] [expr (1<<57) + 128] |
| 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, detail=%DETAIL%); |
| 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.3 { |
| 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.4.[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 } ;# foreach_detail_mode |
| 196 |
| 197 |
| 198 |
| 199 finish_test |
| 200 |
OLD | NEW |