sl@0
|
1 |
# 2007 August 20
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#*************************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. This
|
sl@0
|
12 |
# script tests for the fts2 rowid-versus-vacuum problem (ticket #2566).
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# $Id: fts3b.test,v 1.3 2007/09/13 18:14:49 shess Exp $
|
sl@0
|
15 |
#
|
sl@0
|
16 |
|
sl@0
|
17 |
set testdir [file dirname $argv0]
|
sl@0
|
18 |
source $testdir/tester.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
|
sl@0
|
21 |
ifcapable !fts3 {
|
sl@0
|
22 |
finish_test
|
sl@0
|
23 |
return
|
sl@0
|
24 |
}
|
sl@0
|
25 |
|
sl@0
|
26 |
db eval {
|
sl@0
|
27 |
CREATE VIRTUAL TABLE t1 USING fts3(c);
|
sl@0
|
28 |
INSERT INTO t1 (c) VALUES('this is a test');
|
sl@0
|
29 |
INSERT INTO t1 (c) VALUES('that was a test');
|
sl@0
|
30 |
INSERT INTO t1 (c) VALUES('this is fun');
|
sl@0
|
31 |
DELETE FROM t1 WHERE c = 'that was a test';
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
# Baseline test.
|
sl@0
|
35 |
do_test fts3b-1.1 {
|
sl@0
|
36 |
execsql {
|
sl@0
|
37 |
SELECT rowid FROM t1 WHERE c MATCH 'this';
|
sl@0
|
38 |
}
|
sl@0
|
39 |
} {1 3}
|
sl@0
|
40 |
|
sl@0
|
41 |
db eval {VACUUM}
|
sl@0
|
42 |
|
sl@0
|
43 |
# The VACUUM renumbered the t1_content table in fts2, which breaks
|
sl@0
|
44 |
# this.
|
sl@0
|
45 |
do_test fts3b-1.2 {
|
sl@0
|
46 |
execsql {
|
sl@0
|
47 |
SELECT rowid FROM t1 WHERE c MATCH 'this';
|
sl@0
|
48 |
}
|
sl@0
|
49 |
} {1 3}
|
sl@0
|
50 |
|
sl@0
|
51 |
# The t2 table is unfortunately pretty contrived. We need documents
|
sl@0
|
52 |
# that are bigger than ROOT_MAX (1024) to force segments out of the
|
sl@0
|
53 |
# segdir and into %_segments. We also need to force segment merging
|
sl@0
|
54 |
# to generate a hole in the %_segments table, which needs more than 16
|
sl@0
|
55 |
# docs. Beyond that, to test correct operation of BLOCK_SELECT_STMT,
|
sl@0
|
56 |
# we need to merge a mult-level tree, which is where the 10,000 comes
|
sl@0
|
57 |
# from. Which is slow, thus the set of transactions, with the 500
|
sl@0
|
58 |
# being a number such that 10,000/500 > 16.
|
sl@0
|
59 |
set text {
|
sl@0
|
60 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
|
sl@0
|
61 |
iaculis mollis ipsum. Praesent rhoncus placerat justo. Duis non quam
|
sl@0
|
62 |
sed turpis posuere placerat. Curabitur et lorem in lorem porttitor
|
sl@0
|
63 |
aliquet. Pellentesque bibendum tincidunt diam. Vestibulum blandit
|
sl@0
|
64 |
ante nec elit. In sapien diam, facilisis eget, dictum sed, viverra
|
sl@0
|
65 |
at, felis. Vestibulum magna. Sed magna dolor, vestibulum rhoncus,
|
sl@0
|
66 |
ornare vel, vulputate sit amet, felis. Integer malesuada, tellus at
|
sl@0
|
67 |
luctus gravida, diam nunc porta nibh, nec imperdiet massa metus eu
|
sl@0
|
68 |
lectus. Aliquam nisi. Nunc fringilla nulla at lectus. Suspendisse
|
sl@0
|
69 |
potenti. Cum sociis natoque penatibus et magnis dis parturient
|
sl@0
|
70 |
montes, nascetur ridiculus mus. Pellentesque odio nulla, feugiat eu,
|
sl@0
|
71 |
suscipit nec, consequat quis, risus.
|
sl@0
|
72 |
}
|
sl@0
|
73 |
append text $text
|
sl@0
|
74 |
|
sl@0
|
75 |
db eval {CREATE VIRTUAL TABLE t2 USING fts3(c)}
|
sl@0
|
76 |
set res {}
|
sl@0
|
77 |
db eval {BEGIN}
|
sl@0
|
78 |
for {set ii 0} {$ii<10000} {incr ii} {
|
sl@0
|
79 |
db eval {INSERT INTO t2 (c) VALUES ($text)}
|
sl@0
|
80 |
lappend res [expr {$ii+1}]
|
sl@0
|
81 |
if {($ii%500)==0} {
|
sl@0
|
82 |
db eval {
|
sl@0
|
83 |
COMMIT;
|
sl@0
|
84 |
BEGIN;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
}
|
sl@0
|
87 |
}
|
sl@0
|
88 |
db eval {COMMIT}
|
sl@0
|
89 |
|
sl@0
|
90 |
do_test fts3b-2.1 {
|
sl@0
|
91 |
execsql {
|
sl@0
|
92 |
SELECT rowid FROM t2 WHERE c MATCH 'lorem';
|
sl@0
|
93 |
}
|
sl@0
|
94 |
} $res
|
sl@0
|
95 |
|
sl@0
|
96 |
db eval {VACUUM}
|
sl@0
|
97 |
|
sl@0
|
98 |
# The VACUUM renumbered the t2_segment table in fts2, which would
|
sl@0
|
99 |
# break the following.
|
sl@0
|
100 |
do_test fts3b-2.2 {
|
sl@0
|
101 |
execsql {
|
sl@0
|
102 |
SELECT rowid FROM t2 WHERE c MATCH 'lorem';
|
sl@0
|
103 |
}
|
sl@0
|
104 |
} $res
|
sl@0
|
105 |
|
sl@0
|
106 |
# Since fts3 is already an API break, I've marked the table-named
|
sl@0
|
107 |
# column HIDDEN.
|
sl@0
|
108 |
|
sl@0
|
109 |
db eval {
|
sl@0
|
110 |
CREATE VIRTUAL TABLE t3 USING fts3(c);
|
sl@0
|
111 |
INSERT INTO t3 (c) VALUES('this is a test');
|
sl@0
|
112 |
INSERT INTO t3 (c) VALUES('that was a test');
|
sl@0
|
113 |
INSERT INTO t3 (c) VALUES('this is fun');
|
sl@0
|
114 |
DELETE FROM t3 WHERE c = 'that was a test';
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
# Test that the table-named column still works.
|
sl@0
|
118 |
do_test fts3b-3.1 {
|
sl@0
|
119 |
execsql {
|
sl@0
|
120 |
SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'test';
|
sl@0
|
121 |
}
|
sl@0
|
122 |
} {{this is a <b>test</b>}}
|
sl@0
|
123 |
|
sl@0
|
124 |
# Test that the column doesn't appear when selecting all columns.
|
sl@0
|
125 |
do_test fts3b-3.2 {
|
sl@0
|
126 |
execsql {
|
sl@0
|
127 |
SELECT * FROM t3 WHERE rowid = 1;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
} {{this is a test}}
|
sl@0
|
130 |
|
sl@0
|
131 |
# Test that the column doesn't conflict with inserts that don't name
|
sl@0
|
132 |
# columns.
|
sl@0
|
133 |
do_test fts3b-3.3 {
|
sl@0
|
134 |
execsql {
|
sl@0
|
135 |
INSERT INTO t3 VALUES ('another test');
|
sl@0
|
136 |
}
|
sl@0
|
137 |
} {}
|
sl@0
|
138 |
|
sl@0
|
139 |
# fts3 adds a new implicit column, docid, which acts as an alias for
|
sl@0
|
140 |
# rowid.
|
sl@0
|
141 |
|
sl@0
|
142 |
db eval {
|
sl@0
|
143 |
CREATE VIRTUAL TABLE t4 USING fts3(c);
|
sl@0
|
144 |
INSERT INTO t4 (c) VALUES('this is a test');
|
sl@0
|
145 |
INSERT INTO t4 (c) VALUES('that was a test');
|
sl@0
|
146 |
INSERT INTO t4 (c) VALUES('this is fun');
|
sl@0
|
147 |
DELETE FROM t4 WHERE c = 'that was a test';
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
# Test that docid is present and identical to rowid.
|
sl@0
|
151 |
do_test fts3b-4.1 {
|
sl@0
|
152 |
execsql {
|
sl@0
|
153 |
SELECT rowid FROM t4 WHERE rowid <> docid;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
} {}
|
sl@0
|
156 |
|
sl@0
|
157 |
# Test that docid is hidden.
|
sl@0
|
158 |
do_test fts3b-4.2 {
|
sl@0
|
159 |
execsql {
|
sl@0
|
160 |
SELECT * FROM t4 WHERE rowid = 1;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
} {{this is a test}}
|
sl@0
|
163 |
|
sl@0
|
164 |
# Test that docid can be selected.
|
sl@0
|
165 |
do_test fts3b-4.3 {
|
sl@0
|
166 |
execsql {
|
sl@0
|
167 |
SELECT docid, * FROM t4 WHERE rowid = 1;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
} {1 {this is a test}}
|
sl@0
|
170 |
|
sl@0
|
171 |
# Test that docid can be used in WHERE.
|
sl@0
|
172 |
do_test fts3b-4.4 {
|
sl@0
|
173 |
execsql {
|
sl@0
|
174 |
SELECT docid, * FROM t4 WHERE docid = 1;
|
sl@0
|
175 |
}
|
sl@0
|
176 |
} {1 {this is a test}}
|
sl@0
|
177 |
|
sl@0
|
178 |
# Test that the column doesn't conflict with inserts that don't name
|
sl@0
|
179 |
# columns. [Yes, this is the same as fts3b-3.3, here just in case the
|
sl@0
|
180 |
# goals of that test change.]
|
sl@0
|
181 |
do_test fts3b-4.5 {
|
sl@0
|
182 |
execsql {
|
sl@0
|
183 |
INSERT INTO t4 VALUES ('another test');
|
sl@0
|
184 |
}
|
sl@0
|
185 |
} {}
|
sl@0
|
186 |
|
sl@0
|
187 |
# Test that the docid can be forced on insert.
|
sl@0
|
188 |
do_test fts3b-4.6 {
|
sl@0
|
189 |
execsql {
|
sl@0
|
190 |
INSERT INTO t4 (docid, c) VALUES (10, 'yet another test');
|
sl@0
|
191 |
SELECT * FROM t4 WHERE docid = 10;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
} {{yet another test}}
|
sl@0
|
194 |
|
sl@0
|
195 |
# Test that rowid can also be forced.
|
sl@0
|
196 |
do_test fts3b-4.7 {
|
sl@0
|
197 |
execsql {
|
sl@0
|
198 |
INSERT INTO t4 (docid, c) VALUES (12, 'still testing');
|
sl@0
|
199 |
SELECT * FROM t4 WHERE docid = 12;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
} {{still testing}}
|
sl@0
|
202 |
|
sl@0
|
203 |
# If an insert tries to set both docid and rowid, require an error.
|
sl@0
|
204 |
do_test fts3b-4.8 {
|
sl@0
|
205 |
catchsql {
|
sl@0
|
206 |
INSERT INTO t4 (rowid, docid, c) VALUES (14, 15, 'bad test');
|
sl@0
|
207 |
SELECT * FROM t4 WHERE docid = 14;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
} {1 {SQL logic error or missing database}}
|
sl@0
|
210 |
|
sl@0
|
211 |
# Don't allow update of docid, to match rowid behaviour.
|
sl@0
|
212 |
do_test fts3b-4.9 {
|
sl@0
|
213 |
catchsql {
|
sl@0
|
214 |
UPDATE t4 SET docid = 14 WHERE docid = 12;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
} {1 {SQL logic error or missing database}}
|
sl@0
|
217 |
|
sl@0
|
218 |
finish_test
|