Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/fts5/test/fts5contentless2.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / fts5 / test / fts5contentless2.test` 207 lines ยท 5032 bytes Raw Blame History 1 # 2023 July 19 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 file contains tests for the content= and content_rowid= options. 13 # 14 15 source [file join [file dirname [info script]] fts5_common.tcl] 16 set testprefix fts5contentless2 17 18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. 19 ifcapable !fts5 { 20 finish_test 21 return 22 } 23 24 proc vocab {} { 25 list aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp 26 } 27 28 proc document {nToken} { 29 set doc [list] 30 set vocab [vocab] 31 for {set ii 0} {$ii < $nToken} {incr ii} { 32 lappend doc [lindex $vocab [expr int(rand()*[llength $vocab])]] 33 } 34 set doc 35 } 36 db func document document 37 38 proc contains {doc token} { 39 expr {[lsearch $doc $token]>=0} 40 } 41 db func contains contains 42 43 proc do_compare_tables_test {tn} { 44 uplevel [list do_test $tn { 45 foreach v [vocab] { 46 set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $v) }] 47 set l2 [execsql { SELECT rowid FROM t2($v) }] 48 if {$l1!=$l2} { error "1: query mismatch ($l1) ($l2)" } 49 50 set w "[string range $v 0 1]*" 51 set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $w) }] 52 set l2 [execsql { SELECT rowid FROM t2($w) }] 53 if {$l1!=$l2} { error "2: query mismatch ($l1) ($l2)" } 54 55 set w "[string range $v 0 0]*" 56 set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $w) }] 57 set l2 [execsql { SELECT rowid FROM t2($w) }] 58 if {$l1!=$l2} { error "2: query mismatch ($l1) ($l2)" } 59 60 set l1 [execsql { 61 SELECT rowid FROM t1 WHERE contains(doc, $v) ORDER BY rowid DESC 62 }] 63 set l2 [execsql { SELECT rowid FROM t2($v) ORDER BY rowid DESC }] 64 if {$l1!=$l2} { error "1: query mismatch ($l1) ($l2)" } 65 } 66 set {} {} 67 } {}] 68 } 69 70 proc lshuffle {in} { 71 set L [list] 72 set ret [list] 73 foreach elem $in { lappend L [list [expr rand()] $elem] } 74 foreach pair [lsort -index 0 $L] { lappend ret [lindex $pair 1] } 75 set ret 76 } 77 78 expr srand(0) 79 80 do_execsql_test 1.0 { 81 CREATE VIRTUAL TABLE t2 USING fts5( 82 doc, prefix=2, content=, contentless_delete=1 83 ); 84 85 CREATE TABLE t1(doc); 86 CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN 87 DELETE FROM t2 WHERE rowid = old.rowid; 88 END; 89 } 90 91 set SMALLEST64 -`9223372036854775808` 92 set LARGEST64 `9223372036854775807` 93 94 foreach {tn r1 r2} { 95 1 0 50 96 2 $SMALLEST64 $SMALLEST64+50 97 3 $LARGEST64-50 $LARGEST64 98 4 -50 -1 99 } { 100 set r1 [expr $r1] 101 set r2 [expr $r2] 102 103 do_test 1.1.$tn { 104 execsql BEGIN 105 for {set ii $r1} {$ii <= $r2} {incr ii} { 106 execsql { INSERT INTO t1(rowid, doc) VALUES ($ii, document(8)); } 107 } 108 execsql COMMIT 109 } {} 110 } 111 do_test 1.2 { 112 db eval { SELECT rowid, doc FROM t1 } { 113 execsql { INSERT INTO t2(rowid, doc) VALUES($rowid, $doc) } 114 } 115 } {} 116 117 foreach {tn rowid} { 118 1 $SMALLEST64 119 2 0 120 3 -5 121 4 -30 122 5 $LARGEST64 123 6 $LARGEST64-1 124 } { 125 set rowid [expr $rowid] 126 do_execsql_test 1.3.$tn.1 { 127 DELETE FROM t1 WHERE rowid=$rowid 128 } 129 do_compare_tables_test 1.3.$tn.2 130 } 131 132 set iTest 1 133 foreach r [lshuffle [execsql {SELECT rowid FROM t1}]] { 134 if {($iTest % 50)==0} { 135 execsql { INSERT INTO t2(t2) VALUES('optimize') } 136 } 137 if {($iTest % 5)==0} { 138 execsql { INSERT INTO t2(t2, rank) VALUES('merge', 5) } 139 } 140 do_execsql_test 1.4.$iTest.1($r) { 141 DELETE FROM t1 WHERE rowid=$r 142 } 143 do_compare_tables_test 1.4.$iTest.2 144 incr iTest 145 } 146 147 do_execsql_test 1.5 { 148 SELECT * FROM t1 149 } {} 150 151 #------------------------------------------------------------------------- 152 reset_db 153 db func document document 154 155 do_execsql_test 2.0 { 156 CREATE VIRTUAL TABLE t2 USING fts5(doc, content=, contentless_delete=1); 157 WITH s(i) AS ( 158 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000 159 ) 160 INSERT INTO t2(rowid, doc) SELECT i, i || ' ' || i FROM s; 161 } 162 163 do_execsql_test 2.1 { 164 BEGIN; 165 DELETE FROM t2 WHERE rowid=32; 166 DELETE FROM t2 WHERE rowid=64; 167 DELETE FROM t2 WHERE rowid=96; 168 DELETE FROM t2 WHERE rowid=128; 169 DELETE FROM t2 WHERE rowid=160; 170 DELETE FROM t2 WHERE rowid=192; 171 COMMIT; 172 } 173 174 do_execsql_test 2.2 { 175 SELECT * FROM t2('128'); 176 } {} 177 178 #------------------------------------------------------------------------- 179 180 foreach {tn step} { 181 1 3 182 2 7 183 3 15 184 } { 185 set step [expr $step] 186 187 reset_db 188 db func document document 189 do_execsql_test 3.$tn.0 { 190 CREATE VIRTUAL TABLE t2 USING fts5(doc, content=, contentless_delete=1); 191 INSERT INTO t2(t2, rank) VALUES('pgsz', 100); 192 WITH s(i) AS ( 193 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000 194 ) 195 INSERT INTO t2(rowid, doc) SELECT i, i || ' ' || i FROM s; 196 } 197 do_execsql_test 3.$tn.1 { 198 DELETE FROM t2 WHERE (rowid % $step)==0 199 } 200 do_execsql_test 3.$tn.2 { 201 SELECT * FROM t2( $step * 5 ) 202 } {} 203 } 204 205 206 207 finish_test