3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Tests of the scalar fts5_rowid() and fts5_decode() functions.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5rowid
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
24 do_catchsql_test 1.1 {
26 } {1 {should be: fts5_rowid(subject, ....)}}
28 do_catchsql_test 1.2 {
29 SELECT fts5_rowid('segment')
30 } {1 {should be: fts5_rowid('segment', segid, pgno))}}
33 SELECT fts5_rowid('segment', 1, 1)
36 do_catchsql_test 1.4 {
37 SELECT fts5_rowid('nosucharg');
38 } {1 {first arg to fts5_rowid() must be 'segment'}}
41 #-------------------------------------------------------------------------
42 # Tests of the fts5_decode() function.
46 CREATE VIRTUAL TABLE x1 USING fts5(a, b);
47 INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
51 set map [list 0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j]
53 for {set i 0} {$i < $n} {incr i} {
54 lappend doc [string map $map [format %.3d [expr int(rand()*100)]]]
62 SELECT rnddoc(6), rnddoc(6) UNION ALL
63 SELECT rnddoc(6), rnddoc(6) FROM r
65 INSERT INTO x1 SELECT * FROM r LIMIT 10000;
66 DELETE FROM x1 WHERE (rowid%2);
69 set res [db one {SELECT count(*) FROM x1_data}]
71 SELECT count(fts5_decode(rowid, block)) FROM x1_data;
73 sqlite3_db_config db DEFENSIVE 0
75 UPDATE x1_data SET block = X'';
76 SELECT count(fts5_decode(rowid, block)) FROM x1_data;
80 INSERT INTO x1(x1, rank) VALUES('pgsz', 1024);
81 INSERT INTO x1(x1) VALUES('rebuild');
84 set res [db one {SELECT count(*) FROM x1_data}]
86 SELECT count(fts5_decode(rowid, block)) FROM x1_data;
89 # This is really a corruption test...
90 #do_execsql_test 2.7 {
91 # UPDATE x1_data SET block = X'';
92 # SELECT count(fts5_decode(rowid, block)) FROM x1_data;
96 SELECT fts5_decode(fts5_rowid('segment', 1000, 1), X'AB')
99 #-------------------------------------------------------------------------
100 # Tests with very large tokens.
103 "[string repeat x 400]" \
104 "[string repeat x 300][string repeat w 100]" \
105 "[string repeat x 300][string repeat y 100]" \
106 "[string repeat x 300][string repeat z 600]" \
111 CREATE VIRTUAL TABLE x2 USING fts5(a);
113 foreach str $strlist { execsql { INSERT INTO x2 VALUES($str) } }
117 for {set tn 0} {$tn<[llength $strlist]} {incr tn} {
118 set str [lindex $strlist $tn]
119 do_execsql_test 3.1.$tn {
120 SELECT rowid FROM x2 WHERE x2 MATCH $str
124 set res [db one {SELECT count(*) FROM x2_data}]
125 do_execsql_test 3.2 {
126 SELECT count(fts5_decode(rowid, block)) FROM x2_data;
129 #-------------------------------------------------------------------------
130 # Leaf pages with no terms or rowids at all.
133 "[string repeat {w } 400]" \
134 "[string repeat {x } 400]" \
135 "[string repeat {y } 400]" \
136 "[string repeat {z } 400]" \
141 CREATE VIRTUAL TABLE x3 USING fts5(a);
142 INSERT INTO x3(x3, rank) VALUES('pgsz', 32);
144 foreach str $strlist { execsql { INSERT INTO x3 VALUES($str) } }
148 for {set tn 0} {$tn<[llength $strlist]} {incr tn} {
149 set str [lindex $strlist $tn]
150 do_execsql_test 4.1.$tn {
151 SELECT rowid FROM x3 WHERE x3 MATCH $str
155 set res [db one {SELECT count(*) FROM x3_data}]
156 do_execsql_test 4.2 {
157 SELECT count(fts5_decode(rowid, block)) FROM x3_data;
160 #-------------------------------------------------------------------------
161 # Position lists with large values.
164 "[string repeat {w } 400]a" \
165 "[string repeat {x } 400]a" \
166 "[string repeat {y } 400]a" \
167 "[string repeat {z } 400]a" \
172 CREATE VIRTUAL TABLE x4 USING fts5(a);
173 INSERT INTO x4(x4, rank) VALUES('pgsz', 32);
175 foreach str $strlist { execsql { INSERT INTO x4 VALUES($str) } }
179 do_execsql_test 5.1 {
180 SELECT rowid FROM x4 WHERE x4 MATCH 'a'
183 set res [db one {SELECT count(*) FROM x4_data}]
184 do_execsql_test 5.2 {
185 SELECT count(fts5_decode(rowid, block)) FROM x4_data;
188 #-------------------------------------------------------------------------
191 do_execsql_test 6.0 {
192 CREATE VIRTUAL TABLE x5 USING fts5(x, detail=none);
193 INSERT INTO x5(x5, rank) VALUES('pgsz', 32);
194 INSERT INTO x5 VALUES('a b c d e f');
195 INSERT INTO x5 VALUES('a b c d e f');
196 INSERT INTO x5 VALUES('a b c d e f');
199 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
200 ) INSERT INTO x5 SELECT 'a b c d e f' FROM s;
202 SELECT count(fts5_decode_none(rowid, block)) FROM x5_data;
205 do_execsql_test 6.1 {
206 DELETE FROM x5 WHERE rowid <= 2;
207 SELECT count(fts5_decode_none(rowid, block)) FROM x5_data;
210 do_execsql_test 6.2 {
211 UPDATE x5 SET x='a b c d e f' WHERE rowid=3;
212 SELECT count(fts5_decode_none(rowid, block)) FROM x5_data;
215 #db eval {SELECT rowid, fts5_decode_none(rowid, block) aS r FROM x5_data} {puts $r}