sl@0: # 2007 August 20 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #************************************************************************* sl@0: # This file implements regression tests for SQLite library. This sl@0: # script tests for the fts2 rowid-versus-vacuum problem (ticket #2566). sl@0: # sl@0: # $Id: fts3b.test,v 1.3 2007/09/13 18:14:49 shess Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If SQLITE_ENABLE_FTS3 is not defined, omit this file. sl@0: ifcapable !fts3 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts3(c); sl@0: INSERT INTO t1 (c) VALUES('this is a test'); sl@0: INSERT INTO t1 (c) VALUES('that was a test'); sl@0: INSERT INTO t1 (c) VALUES('this is fun'); sl@0: DELETE FROM t1 WHERE c = 'that was a test'; sl@0: } sl@0: sl@0: # Baseline test. sl@0: do_test fts3b-1.1 { sl@0: execsql { sl@0: SELECT rowid FROM t1 WHERE c MATCH 'this'; sl@0: } sl@0: } {1 3} sl@0: sl@0: db eval {VACUUM} sl@0: sl@0: # The VACUUM renumbered the t1_content table in fts2, which breaks sl@0: # this. sl@0: do_test fts3b-1.2 { sl@0: execsql { sl@0: SELECT rowid FROM t1 WHERE c MATCH 'this'; sl@0: } sl@0: } {1 3} sl@0: sl@0: # The t2 table is unfortunately pretty contrived. We need documents sl@0: # that are bigger than ROOT_MAX (1024) to force segments out of the sl@0: # segdir and into %_segments. We also need to force segment merging sl@0: # to generate a hole in the %_segments table, which needs more than 16 sl@0: # docs. Beyond that, to test correct operation of BLOCK_SELECT_STMT, sl@0: # we need to merge a mult-level tree, which is where the 10,000 comes sl@0: # from. Which is slow, thus the set of transactions, with the 500 sl@0: # being a number such that 10,000/500 > 16. sl@0: set text { sl@0: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sl@0: iaculis mollis ipsum. Praesent rhoncus placerat justo. Duis non quam sl@0: sed turpis posuere placerat. Curabitur et lorem in lorem porttitor sl@0: aliquet. Pellentesque bibendum tincidunt diam. Vestibulum blandit sl@0: ante nec elit. In sapien diam, facilisis eget, dictum sed, viverra sl@0: at, felis. Vestibulum magna. Sed magna dolor, vestibulum rhoncus, sl@0: ornare vel, vulputate sit amet, felis. Integer malesuada, tellus at sl@0: luctus gravida, diam nunc porta nibh, nec imperdiet massa metus eu sl@0: lectus. Aliquam nisi. Nunc fringilla nulla at lectus. Suspendisse sl@0: potenti. Cum sociis natoque penatibus et magnis dis parturient sl@0: montes, nascetur ridiculus mus. Pellentesque odio nulla, feugiat eu, sl@0: suscipit nec, consequat quis, risus. sl@0: } sl@0: append text $text sl@0: sl@0: db eval {CREATE VIRTUAL TABLE t2 USING fts3(c)} sl@0: set res {} sl@0: db eval {BEGIN} sl@0: for {set ii 0} {$ii<10000} {incr ii} { sl@0: db eval {INSERT INTO t2 (c) VALUES ($text)} sl@0: lappend res [expr {$ii+1}] sl@0: if {($ii%500)==0} { sl@0: db eval { sl@0: COMMIT; sl@0: BEGIN; sl@0: } sl@0: } sl@0: } sl@0: db eval {COMMIT} sl@0: sl@0: do_test fts3b-2.1 { sl@0: execsql { sl@0: SELECT rowid FROM t2 WHERE c MATCH 'lorem'; sl@0: } sl@0: } $res sl@0: sl@0: db eval {VACUUM} sl@0: sl@0: # The VACUUM renumbered the t2_segment table in fts2, which would sl@0: # break the following. sl@0: do_test fts3b-2.2 { sl@0: execsql { sl@0: SELECT rowid FROM t2 WHERE c MATCH 'lorem'; sl@0: } sl@0: } $res sl@0: sl@0: # Since fts3 is already an API break, I've marked the table-named sl@0: # column HIDDEN. sl@0: sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t3 USING fts3(c); sl@0: INSERT INTO t3 (c) VALUES('this is a test'); sl@0: INSERT INTO t3 (c) VALUES('that was a test'); sl@0: INSERT INTO t3 (c) VALUES('this is fun'); sl@0: DELETE FROM t3 WHERE c = 'that was a test'; sl@0: } sl@0: sl@0: # Test that the table-named column still works. sl@0: do_test fts3b-3.1 { sl@0: execsql { sl@0: SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'test'; sl@0: } sl@0: } {{this is a test}} sl@0: sl@0: # Test that the column doesn't appear when selecting all columns. sl@0: do_test fts3b-3.2 { sl@0: execsql { sl@0: SELECT * FROM t3 WHERE rowid = 1; sl@0: } sl@0: } {{this is a test}} sl@0: sl@0: # Test that the column doesn't conflict with inserts that don't name sl@0: # columns. sl@0: do_test fts3b-3.3 { sl@0: execsql { sl@0: INSERT INTO t3 VALUES ('another test'); sl@0: } sl@0: } {} sl@0: sl@0: # fts3 adds a new implicit column, docid, which acts as an alias for sl@0: # rowid. sl@0: sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t4 USING fts3(c); sl@0: INSERT INTO t4 (c) VALUES('this is a test'); sl@0: INSERT INTO t4 (c) VALUES('that was a test'); sl@0: INSERT INTO t4 (c) VALUES('this is fun'); sl@0: DELETE FROM t4 WHERE c = 'that was a test'; sl@0: } sl@0: sl@0: # Test that docid is present and identical to rowid. sl@0: do_test fts3b-4.1 { sl@0: execsql { sl@0: SELECT rowid FROM t4 WHERE rowid <> docid; sl@0: } sl@0: } {} sl@0: sl@0: # Test that docid is hidden. sl@0: do_test fts3b-4.2 { sl@0: execsql { sl@0: SELECT * FROM t4 WHERE rowid = 1; sl@0: } sl@0: } {{this is a test}} sl@0: sl@0: # Test that docid can be selected. sl@0: do_test fts3b-4.3 { sl@0: execsql { sl@0: SELECT docid, * FROM t4 WHERE rowid = 1; sl@0: } sl@0: } {1 {this is a test}} sl@0: sl@0: # Test that docid can be used in WHERE. sl@0: do_test fts3b-4.4 { sl@0: execsql { sl@0: SELECT docid, * FROM t4 WHERE docid = 1; sl@0: } sl@0: } {1 {this is a test}} sl@0: sl@0: # Test that the column doesn't conflict with inserts that don't name sl@0: # columns. [Yes, this is the same as fts3b-3.3, here just in case the sl@0: # goals of that test change.] sl@0: do_test fts3b-4.5 { sl@0: execsql { sl@0: INSERT INTO t4 VALUES ('another test'); sl@0: } sl@0: } {} sl@0: sl@0: # Test that the docid can be forced on insert. sl@0: do_test fts3b-4.6 { sl@0: execsql { sl@0: INSERT INTO t4 (docid, c) VALUES (10, 'yet another test'); sl@0: SELECT * FROM t4 WHERE docid = 10; sl@0: } sl@0: } {{yet another test}} sl@0: sl@0: # Test that rowid can also be forced. sl@0: do_test fts3b-4.7 { sl@0: execsql { sl@0: INSERT INTO t4 (docid, c) VALUES (12, 'still testing'); sl@0: SELECT * FROM t4 WHERE docid = 12; sl@0: } sl@0: } {{still testing}} sl@0: sl@0: # If an insert tries to set both docid and rowid, require an error. sl@0: do_test fts3b-4.8 { sl@0: catchsql { sl@0: INSERT INTO t4 (rowid, docid, c) VALUES (14, 15, 'bad test'); sl@0: SELECT * FROM t4 WHERE docid = 14; sl@0: } sl@0: } {1 {SQL logic error or missing database}} sl@0: sl@0: # Don't allow update of docid, to match rowid behaviour. sl@0: do_test fts3b-4.9 { sl@0: catchsql { sl@0: UPDATE t4 SET docid = 14 WHERE docid = 12; sl@0: } sl@0: } {1 {SQL logic error or missing database}} sl@0: sl@0: finish_test