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/vec1/test/vec1intck.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 / vec1 / test / vec1intck.test` 293 lines ยท 7631 bytes Raw Blame History 1 # 2026-04-01 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 # 13 14 source [file join [file dirname [info script]] vec1_common.tcl] 15 set testprefix vec1intck 16 vec1_load db 17 18 do_execsql_test 1.0 { 19 CREATE VIRTUAL TABLE mytbl USING vec1(a, b); 20 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000 ) 21 INSERT INTO mytbl SELECT random_vector(32), 'val'||i FROM s; 22 23 INSERT INTO mytbl(cmd, arg) VALUES('rebuild', ( 24 SELECT vec1_train(a, '{codesize:8}') FROM mytbl 25 )); 26 } 27 28 do_execsql_test 1.1 { 29 SELECT length(val) FROM mytbl_idx; 30 } {12076} 31 32 do_execsql_test 1.2 { 33 PRAGMA integrity_check 34 } {ok} 35 36 proc set_ntombstone {val n} { 37 set be32 [binary format I $n] 38 return [string replace $val 8 11 $be32] 39 } 40 db funct set_ntombstone set_ntombstone 41 42 do_execsql_test 1.3 { 43 UPDATE mytbl_idx SET val = set_ntombstone(val, 4); 44 } {} 45 46 do_execsql_test 1.4 { 47 PRAGMA integrity_check 48 } {{mytbl: bad tombstone count}} 49 50 do_execsql_test 2.0 { 51 INSERT INTO mytbl(cmd) VALUES('rebuild'); 52 } 53 54 proc zero_pq {val i} { 55 set iOff [expr 12 + 1000*4 + $i] 56 set ret $val 57 for {set jj 0} {$jj < 8} {incr jj} { 58 set ret [string replace $ret $iOff $iOff [binary format c 0]] 59 incr iOff 16 60 } 61 return $ret 62 } 63 db func zero_pq zero_pq 64 65 do_execsql_test 2.1 { 66 UPDATE mytbl_idx SET val = zero_pq(val, 4); 67 } {} 68 69 do_execsql_test 2.2 { 70 PRAGMA integrity_check 71 } {{mytbl: %_idx PQ does not match calculated PQ for row 5}} 72 73 #------------------------------------------------------------------ 74 75 do_execsql_test 3.0 { 76 INSERT INTO mytbl(cmd, arg) VALUES('rebuild', ( 77 SELECT vec1_train(a, '{nbucket:16,codesize:32}') FROM mytbl 78 )); 79 } 80 81 # Replace the vector for row 555 with a copy of the bucket vector that 82 # is most distant from the current vector. The idea being to pick a 83 # value guaranteed to be assigned to a different bucket than the current 84 # vector. 85 model2tbl model mytbl 86 do_execsql_test 3.1 { 87 UPDATE mytbl_base SET vector = 88 (SELECT coarse FROM model ORDER BY vec1_l2_distance(vector, coarse) DESC) 89 WHERE id=555; 90 } 91 92 do_execsql_test 3.2 { 93 PRAGMA integrity_check 94 } {{mytbl: vector from row 555 is in wrong bucket}} 95 96 do_execsql_test 3.3 { 97 UPDATE mytbl_base SET vector = random_vector(31) WHERE id=555; 98 } 99 100 do_execsql_test 3.4 { 101 PRAGMA integrity_check 102 } {{mytbl: vector in %_base row 555 is wrong size}} 103 104 do_execsql_test 3.5 { 105 UPDATE mytbl_base SET vector = random_vector(32); 106 INSERT INTO mytbl(cmd, arg) VALUES('rebuild', ( 107 SELECT vec1_train(a, '{nbucket:16,codesize:32}') FROM mytbl 108 )); 109 } 110 111 do_execsql_test 3.6 { 112 UPDATE mytbl_base SET c0 = 'hello world' WHERE id=555 113 } 114 115 do_execsql_test 3.7 { 116 PRAGMA integrity_check 117 } {{mytbl: meta-value value mismatch for row 555}} 118 119 do_execsql_test 3.8 { 120 UPDATE mytbl_base SET vector = random_vector(32); 121 INSERT INTO mytbl(cmd, arg) VALUES('rebuild', ( 122 SELECT vec1_train(a, '{codesize:16}') FROM mytbl 123 )); 124 } 125 126 proc shorten {val} { 127 string range $val 0 end-1 128 } 129 db func shorten shorten 130 131 do_execsql_test 3.9 { 132 UPDATE mytbl_idx SET val = shorten(val); 133 PRAGMA integrity_check; 134 } { 135 {mytbl: %_idx entry id=1 is corrupt} 136 } 137 138 do_execsql_test 3.10 { 139 INSERT INTO mytbl(cmd, arg) VALUES('rebuild', ( 140 SELECT vec1_train(a, '{nbucket:16}') FROM mytbl 141 )); 142 } 143 144 do_execsql_test 3.11 { 145 UPDATE mytbl_base SET vector = vector+1 WHERE id=555; 146 PRAGMA integrity_check; 147 } { 148 {mytbl: bucket value in %_base row 555 is incorrect} 149 } 150 151 #------------------------------------------------------------------------- 152 reset_db 153 vec1_load db 154 155 do_execsql_test 4.0 { 156 CREATE VIRTUAL TABLE v1 USING vec1(x, a, b); 157 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 ) 158 INSERT INTO v1(rowid, x, a, b) 159 SELECT 10_000_000_000 + i, random_vector(8), 20_000_000_000+i, i FROM s; 160 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 161 } 162 163 do_execsql_test 4.1 { 164 SELECT count(*) FROM v1; 165 DELETE FROM v1 WHERE rowid = 10_000_000_000 + 35; 166 SELECT count(*) FROM v1; 167 } {100 99} 168 169 do_execsql_test 4.2 { 170 PRAGMA integrity_check 171 } {ok} 172 173 #------------------------------------------------------------------------- 174 reset_db 175 vec1_load db 176 177 do_execsql_test 5.0 { 178 CREATE VIRTUAL TABLE v1 USING vec1(x, a); 179 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 180 181 INSERT INTO v1 VALUES(random_vector(8), 'helloworld'); 182 INSERT INTO v1 VALUES(random_vector(8), 4.5); 183 INSERT INTO v1 VALUES(random_vector(8), 1000); 184 INSERT INTO v1 VALUES(random_vector(8), X'`12345678`'); 185 186 PRAGMA integrity_check 187 } {ok} 188 189 foreach {tn update err} { 190 1 { UPDATE v1_base SET c0='helloWORLD' WHERE id=1 } 191 {v1: meta-value value mismatch for row 1} 192 193 2 { UPDATE v1_base SET c0='helloworld2' WHERE id=1 } 194 {v1: meta-value value mismatch for row 1} 195 196 3 { UPDATE v1_base SET c0=4.5 WHERE id=1 } 197 {v1: meta-value value mismatch for row 1} 198 199 4 { UPDATE v1_base SET c0=5.5 WHERE id=2 } 200 {v1: meta-value value mismatch for row 2} 201 202 5 { UPDATE v1_base SET c0=1001 WHERE id=3 } 203 {v1: meta-value value mismatch for row 3} 204 205 6 { UPDATE v1_base SET c0=5 WHERE id=2 } 206 {v1: meta-value value mismatch for row 2} 207 208 7 { UPDATE v1_base SET c0='textvalue' WHERE id=2 } 209 {v1: meta-value value mismatch for row 2} 210 211 8 { UPDATE v1_base SET c0=X'ABCDEF' WHERE id=2 } 212 {v1: meta-value value mismatch for row 2} 213 214 9 { UPDATE v1_base SET c0=X'ABCDEF' WHERE id=4 } 215 {v1: meta-value value mismatch for row 4} 216 217 10 { UPDATE v1_base SET c0=X'00ABCDEF' WHERE id=4 } 218 {v1: meta-value value mismatch for row 4} 219 220 11 { DELETE FROM v1_base WHERE id=1 } 221 {v1: %_idx row 1 missing from %_base} 222 223 12 { INSERT INTO v1_base(id, vector, c0) VALUES(555,random_vector(8),'xyz') } 224 {v1: wrong number of entries in %_base - have 5, expect 4} 225 226 } { 227 execsql BEGIN 228 execsql $update 229 do_execsql_test 5.$tn { 230 PRAGMA integrity_check 231 } [list $err] 232 execsql ROLLBACK 233 } 234 235 #------------------------------------------------------------------------- 236 reset_db 237 vec1_load db 238 239 execsql { SELECT vec1_config('nthread', 4) } 240 241 do_execsql_test 6.0 { 242 CREATE VIRTUAL TABLE v1 USING vec1(x, a); 243 244 INSERT INTO v1 VALUES(random_vector(8), 1.2); 245 INSERT INTO v1 VALUES(random_vector(8), 4.5); 246 INSERT INTO v1 VALUES(random_vector(8), 1000); 247 248 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 249 250 PRAGMA integrity_check; 251 } {ok} 252 253 do_execsql_test 6.1 { 254 UPDATE v1 SET a = (rowid*1000); 255 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 256 INSERT INTO v1 VALUES(random_vector(8), NULL); 257 PRAGMA integrity_check; 258 } {ok} 259 260 do_execsql_test 6.2.1 { 261 INSERT INTO v1 VALUES(random_vector(8), 1.234); 262 PRAGMA integrity_check; 263 } {ok} 264 265 do_execsql_test 6.2.2 { 266 INSERT INTO v1 VALUES(random_vector(8), 'text'); 267 PRAGMA integrity_check; 268 } {ok} 269 270 do_execsql_test 6.3 { 271 UPDATE v1 SET a = (rowid*1000); 272 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 273 INSERT INTO v1 VALUES(random_vector(8), 10_000_000_000); 274 PRAGMA integrity_check; 275 } {ok} 276 277 do_execsql_test 6.4 { 278 UPDATE v1 SET a = (rowid*1000); 279 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 280 INSERT INTO v1 VALUES(random_vector(8), -10_000_000_000); 281 PRAGMA integrity_check; 282 } {ok} 283 284 do_execsql_test 6.5 { 285 UPDATE v1 SET a = rowid; 286 INSERT INTO v1(cmd, arg) VALUES('rebuild', '{index:"flat"}'); 287 INSERT INTO v1 VALUES(random_vector(8), -1); 288 PRAGMA integrity_check; 289 } {ok} 290 291 292 finish_test 293