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 # This file contains tests for the content= and content_rowid= options.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5contentless3
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 CREATE VIRTUAL TABLE ft USING fts5(x, content=, contentless_delete=1);
27 INSERT INTO ft VALUES('one one one');
28 INSERT INTO ft VALUES('two two two');
29 INSERT INTO ft VALUES('three three three');
30 INSERT INTO ft VALUES('four four four');
31 INSERT INTO ft VALUES('five five five');
32 INSERT INTO ft VALUES('six six six');
33 INSERT INTO ft VALUES('seven seven seven');
34 INSERT INTO ft VALUES('eight eight eight');
35 INSERT INTO ft VALUES('nine nine nine');
38 DELETE FROM ft WHERE rowid=3;
41 proc myhex {hex} { binary decode hex $hex }
45 UPDATE ft_data SET block =
46 myhex('04000000 00000001' ||
47 '01020304 01020304 01020304 01020304' ||
48 '01020304 01020304 01020304 01020304'
50 WHERE id = (SELECT max(id) FROM ft_data);
54 DELETE FROM ft WHERE rowid=1
58 SELECT rowid FROM ft('two');
62 UPDATE ft_data SET block =
63 myhex('08000000 00000001' ||
64 '0000000001020304 0000000001020304 0000000001020304 0000000001020304' ||
65 '0000000001020304 0000000001020304 0000000001020304 0000000001020304'
67 WHERE id = (SELECT max(id) FROM ft_data);
71 SELECT rowid FROM ft('two');
75 DELETE FROM ft WHERE rowid=4
79 UPDATE ft_data SET block = myhex('04000000 00000000')
80 WHERE id = (SELECT max(id) FROM ft_data);
83 SELECT rowid FROM ft('two');
87 UPDATE ft_data SET block = myhex('04000000 00000000')
88 WHERE id = (SELECT max(id) FROM ft_data);
91 DELETE FROM ft WHERE rowid=8
94 #-------------------------------------------------------------------------
97 CREATE VIRTUAL TABLE ft USING fts5(x, content=, contentless_delete=1);
98 INSERT INTO ft VALUES('one one one');
99 INSERT INTO ft VALUES('two two two');
100 INSERT INTO ft VALUES('three three three');
101 INSERT INTO ft VALUES('four four four');
102 INSERT INTO ft VALUES('five five five');
103 INSERT INTO ft VALUES('six six six');
104 INSERT INTO ft VALUES('seven seven seven');
105 INSERT INTO ft VALUES('eight eight eight');
106 INSERT INTO ft VALUES('nine nine nine');
109 do_execsql_test 2.1 {
110 INSERT INTO ft(ft) VALUES('optimize');
112 do_execsql_test 2.2 {
113 SELECT count(*) FROM ft_data
115 do_execsql_test 2.3 {
116 DELETE FROM ft WHERE rowid=5
118 do_execsql_test 2.4 {
119 SELECT count(*) FROM ft_data
122 # Check that an 'optimize' works (rewrites the index) if there is a single
123 # segment with one or more tombstone hash pages.
124 do_execsql_test 2.5 {
125 INSERT INTO ft(ft) VALUES('optimize');
127 do_execsql_test 2.6 {
128 SELECT count(*) FROM ft_data
131 # Check that an 'optimize' is a no-op if there is a single segment
132 # and no tombstone hash pages.
133 do_execsql_test 2.7 {
134 INSERT INTO ft(ft) VALUES('optimize');
135 SELECT rowid FROM ft_data;
136 } [db eval {SELECT rowid FROM ft_data}]
138 #-------------------------------------------------------------------------
140 do_execsql_test 3.0 {
141 CREATE VIRTUAL TABLE ft USING fts5(x, content=, contentless_delete=1);
142 INSERT INTO ft(ft, rank) VALUES('pgsz', 64);
144 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
146 INSERT INTO ft(rowid, x) SELECT i, i||' '||i||' '||i||' '||i FROM s;
147 INSERT INTO ft(ft) VALUES('optimize');
150 do_execsql_test 3.1 {
151 SELECT count(*) FROM ft_data
154 do_execsql_test 3.2 {
155 DELETE FROM ft WHERE (rowid % 50)==0;
156 SELECT count(*) FROM ft_data;
159 do_execsql_test 3.3 {
160 INSERT INTO ft(ft, rank) VALUES('merge', 500);
161 SELECT rowid FROM ft_data;
162 } [db eval {SELECT rowid FROM ft_data}]
164 do_execsql_test 3.4 {
165 INSERT INTO ft(ft, rank) VALUES('merge', -1000);
166 SELECT count(*) FROM ft_data;
169 do_execsql_test 3.5 {
170 DELETE FROM ft WHERE (rowid % 50)==1;
171 SELECT count(*) FROM ft_data;
174 do_execsql_test 3.6 {
175 SELECT level, segment, npgtombstone FROM fts5_structure(
176 (SELECT block FROM ft_data WHERE id=10)
182 set nChange [db total_changes]
183 execsql { INSERT INTO ft(ft, rank) VALUES('merge', -5) }
184 if {([db total_changes] - $nChange)<2} break
188 do_execsql_test 3.7 {
189 SELECT level, segment, npgtombstone FROM fts5_structure(
190 (SELECT block FROM ft_data WHERE id=10)