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 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS3 module.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix fts3join
19 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
26 CREATE VIRTUAL TABLE ft1 USING fts4(x);
27 INSERT INTO ft1 VALUES('aaa aaa');
28 INSERT INTO ft1 VALUES('aaa bbb');
29 INSERT INTO ft1 VALUES('bbb aaa');
30 INSERT INTO ft1 VALUES('bbb bbb');
32 CREATE TABLE t1(id, y);
33 INSERT INTO t1 VALUES(1, 'aaa');
34 INSERT INTO t1 VALUES(2, 'bbb');
38 SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1;
42 SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1 ORDER BY docid;
46 CREATE VIRTUAL TABLE ft2 USING fts4(x);
47 CREATE VIRTUAL TABLE ft3 USING fts4(y);
49 INSERT INTO ft2 VALUES('abc');
50 INSERT INTO ft2 VALUES('def');
51 INSERT INTO ft3 VALUES('ghi');
52 INSERT INTO ft3 VALUES('abc');
55 do_execsql_test 2.1 { SELECT * FROM ft2, ft3 WHERE x MATCH y; } {abc abc}
56 do_execsql_test 2.2 { SELECT * FROM ft2, ft3 WHERE y MATCH x; } {abc abc}
57 do_execsql_test 2.3 { SELECT * FROM ft3, ft2 WHERE x MATCH y; } {abc abc}
58 do_execsql_test 2.4 { SELECT * FROM ft3, ft2 WHERE y MATCH x; } {abc abc}
60 do_catchsql_test 2.5 {
61 SELECT * FROM ft3, ft2 WHERE y MATCH x AND x MATCH y;
62 } {1 {unable to use function MATCH in the requested context}}
65 CREATE VIRTUAL TABLE vt USING fts3(x);
66 INSERT INTO vt VALUES('abc');
67 INSERT INTO vt VALUES('xyz');
69 CREATE TABLE tt(a INTEGER PRIMARY KEY);
70 INSERT INTO tt VALUES(1), (2);
74 SELECT * FROM tt LEFT JOIN (
75 SELECT rowid AS rrr, * FROM vt WHERE vt MATCH 'abc'
80 SELECT * FROM tt LEFT JOIN vt ON (vt MATCH 'abc')
83 #-------------------------------------------------------------------------
84 # Test that queries of the form found in test case 4.2 use an automatic
85 # index to avoid running multiple fts queries.
88 CREATE VIRTUAL TABLE ft4 USING fts3(x);
89 CREATE TABLE t4(y, z);
90 CREATE INDEX t4y ON t1(y);
94 SELECT * FROM t4 LEFT JOIN (
95 SELECT docid, * FROM ft4 WHERE ft4 MATCH ?
96 ) AS rr ON t4.rowid=rr.docid
101 | `--SCAN ft4 VIRTUAL TABLE INDEX 3:
103 |--BLOOM FILTER ON rr (docid=?)
104 `--SEARCH rr USING AUTOMATIC COVERING INDEX (docid=?) LEFT-JOIN