modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/fts5/test/fts5ah.test (about) 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 foreach_detail_mode $testprefix { 25 26 #------------------------------------------------------------------------- 27 # This file contains tests for very large doclists. 28 # 29 30 set Y [list] 31 set W [list] 32 do_test 1.0 { 33 execsql { CREATE VIRTUAL TABLE t1 USING fts5(a, detail=%DETAIL%) } 34 execsql { INSERT INTO t1(t1, rank) VALUES('pgsz', 128) } 35 set v {w w w w w w w w w w w w w w w w w w w w} 36 execsql { INSERT INTO t1(rowid, a) VALUES(0, $v) } 37 for {set i 1} {$i <= 10000} {incr i} { 38 set v {x x x x x x x x x x x x x x x x x x x x} 39 if {($i % 2139)==0} {lset v 3 Y ; lappend Y $i} 40 if {($i % 1577)==0} {lset v 5 W ; lappend W $i} 41 execsql { INSERT INTO t1 VALUES($v) } 42 } 43 set v {w w w w w w w w w w w w w w w w w w w w} 44 execsql { INSERT INTO t1 VALUES($v) } 45 } {} 46 47 do_execsql_test 1.1.1 { 48 SELECT rowid FROM t1 WHERE t1 MATCH 'x AND w' 49 } [lsort -integer -incr $W] 50 51 do_execsql_test 1.1.2 { 52 SELECT rowid FROM t1 WHERE t1 MATCH 'x* AND w*' 53 } [lsort -integer -incr $W] 54 55 do_execsql_test 1.2 { 56 SELECT rowid FROM t1 WHERE t1 MATCH 'y AND x' 57 } [lsort -integer -incr $Y] 58 59 do_execsql_test 1.3 { 60 INSERT INTO t1(t1) VALUES('integrity-check'); 61 } 62 63 proc reads {} { 64 db one {SELECT t1 FROM t1 WHERE t1 MATCH '*reads'} 65 } 66 67 proc execsql_reads {sql} { 68 set nRead [reads] 69 execsql $sql 70 expr [reads] - $nRead 71 } 72 73 do_test 1.4 { 74 set nRead [reads] 75 execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'x' } 76 set nReadX [expr [reads] - $nRead] 77 #puts -nonewline "(nReadX=$nReadX)" 78 if {[detail_is_full]} { set expect 1000 } 79 if {[detail_is_col]} { set expect 250 } 80 if {[detail_is_none]} { set expect 80 } 81 82 expr $nReadX>$expect 83 } {1} 84 85 do_test 1.5 { 86 set fwd [execsql_reads {SELECT rowid FROM t1 WHERE t1 MATCH 'x' }] 87 set bwd [execsql_reads { 88 SELECT rowid FROM t1 WHERE t1 MATCH 'x' ORDER BY 1 ASC 89 }] 90 expr {$bwd < $fwd + 12} 91 } {1} 92 93 foreach {tn q res} " 94 1 { SELECT rowid FROM t1 WHERE t1 MATCH 'w + x' } [list $W] 95 2 { SELECT rowid FROM t1 WHERE t1 MATCH 'x + w' } [list $W] 96 3 { SELECT rowid FROM t1 WHERE t1 MATCH 'x AND w' } [list $W] 97 4 { SELECT rowid FROM t1 WHERE t1 MATCH 'y AND x' } [list $Y] 98 " { 99 if {[detail_is_full]==0 && ($tn==1 || $tn==2)} continue 100 101 if {[detail_is_full]} { set ratio 8 } 102 if {[detail_is_col]} { set ratio 4 } 103 if {[detail_is_none]} { set ratio 2 } 104 105 do_test 1.6.$tn.1 { 106 set n [execsql_reads $q] 107 #puts -nonewline "(n=$n nReadX=$nReadX)" 108 expr {$n < ($nReadX / $ratio)} 109 } {1} 110 111 do_test 1.6.$tn.2 { 112 set n [execsql_reads "$q ORDER BY rowid DESC"] 113 #puts -nonewline "(n=$n nReadX=$nReadX)" 114 expr {$n < ($nReadX / $ratio)} 115 } {1} 116 117 do_execsql_test 1.6.$tn.3 $q [lsort -int -incr $res] 118 do_execsql_test 1.6.$tn.4 "$q ORDER BY rowid DESC" [lsort -int -decr $res] 119 } 120 121 #------------------------------------------------------------------------- 122 # Now test that adding range constraints on the rowid field reduces the 123 # number of pages loaded from disk. 124 # 125 foreach {tn fraction tail cnt} { 126 1 0.6 {rowid > 5000} 5000 127 2 0.2 {rowid > 9000} 1000 128 3 0.2 {rowid < 1000} 999 129 4 0.2 {rowid BETWEEN 4000 AND 5000} 1001 130 5 0.6 {rowid >= 5000} 5001 131 6 0.2 {rowid >= 9000} 1001 132 7 0.2 {rowid <= 1000} 1000 133 8 0.6 {rowid > '5000'} 5000 134 9 0.2 {rowid > '9000'} 1000 135 10 0.1 {rowid = 444} 1 136 } { 137 set q "SELECT rowid FROM t1 WHERE t1 MATCH 'x' AND $tail" 138 set n [execsql_reads $q] 139 set ret [llength [execsql $q]] 140 141 # Because the position lists for 'x' are quite long in this db, the 142 # advantage is a bit smaller in detail=none mode. Update $fraction to 143 # reflect this. 144 if {[detail_is_none] && $fraction<0.5} { set fraction [expr $fraction*2] } 145 146 do_test "1.7.$tn.asc.(n=$n ret=$ret)" { 147 expr {$n < ($fraction*$nReadX) && $ret==$cnt} 148 } {1} 149 150 set q "SELECT rowid FROM t1 WHERE t1 MATCH 'x' AND $tail ORDER BY rowid DESC" 151 set n [execsql_reads $q] 152 set ret [llength [execsql $q]] 153 do_test "1.7.$tn.desc.(n=$n ret=$ret)" { 154 expr {$n < 2*$fraction*$nReadX && $ret==$cnt} 155 } {1} 156 } 157 158 do_execsql_test 1.8.1 { 159 SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND +rowid < 'text'; 160 } {10000} 161 do_execsql_test 1.8.2 { 162 SELECT count(*) FROM t1 WHERE t1 MATCH 'x' AND rowid < 'text'; 163 } {10000} 164 165 } ;# foreach_detail_mode 166 167 #db eval {SELECT rowid, fts5_decode(rowid, block) aS r FROM t1_data} {puts $r} 168 169 finish_test