xref: /sqlite-3.40.0/test/fts3e.test (revision 9eb7c2ad)
1*9eb7c2adSshess# 2008 July 29
2*9eb7c2adSshess#
3*9eb7c2adSshess# The author disclaims copyright to this source code.  In place of
4*9eb7c2adSshess# a legal notice, here is a blessing:
5*9eb7c2adSshess#
6*9eb7c2adSshess#    May you do good and not evil.
7*9eb7c2adSshess#    May you find forgiveness for yourself and forgive others.
8*9eb7c2adSshess#    May you share freely, never taking more than you give.
9*9eb7c2adSshess#
10*9eb7c2adSshess#*************************************************************************
11*9eb7c2adSshess# These tests exercise the various types of fts3 cursors.
12*9eb7c2adSshess#
13*9eb7c2adSshess# $Id: fts3e.test,v 1.1 2008/07/29 20:24:46 shess Exp $
14*9eb7c2adSshess#
15*9eb7c2adSshess
16*9eb7c2adSshessset testdir [file dirname $argv0]
17*9eb7c2adSshesssource $testdir/tester.tcl
18*9eb7c2adSshess
19*9eb7c2adSshess# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
20*9eb7c2adSshessifcapable !fts3 {
21*9eb7c2adSshess  finish_test
22*9eb7c2adSshess  return
23*9eb7c2adSshess}
24*9eb7c2adSshess
25*9eb7c2adSshess#*************************************************************************
26*9eb7c2adSshess# Test table scan (QUERY_GENERIC).  This kind of query happens for
27*9eb7c2adSshess# queries with no WHERE clause, or for WHERE clauses which cannot be
28*9eb7c2adSshess# satisfied by an index.
29*9eb7c2adSshessdb eval {
30*9eb7c2adSshess  DROP TABLE IF EXISTS t1;
31*9eb7c2adSshess  CREATE VIRTUAL TABLE t1 USING fts3(c);
32*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (1, 'This is a test');
33*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (2, 'That was a test');
34*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (3, 'This is a test');
35*9eb7c2adSshess}
36*9eb7c2adSshess
37*9eb7c2adSshessdo_test fts3e-1.1 {
38*9eb7c2adSshess  execsql {
39*9eb7c2adSshess    SELECT docid FROM t1 ORDER BY docid;
40*9eb7c2adSshess  }
41*9eb7c2adSshess} {1 2 3}
42*9eb7c2adSshess
43*9eb7c2adSshessdo_test fts3e-1.2 {
44*9eb7c2adSshess  execsql {
45*9eb7c2adSshess    SELECT docid FROM t1 WHERE c LIKE '%test' ORDER BY docid;
46*9eb7c2adSshess  }
47*9eb7c2adSshess} {1 2 3}
48*9eb7c2adSshess
49*9eb7c2adSshessdo_test fts3e-1.3 {
50*9eb7c2adSshess  execsql {
51*9eb7c2adSshess    SELECT docid FROM t1 WHERE c LIKE 'That%' ORDER BY docid;
52*9eb7c2adSshess  }
53*9eb7c2adSshess} {2}
54*9eb7c2adSshess
55*9eb7c2adSshess#*************************************************************************
56*9eb7c2adSshess# Test lookup by docid (QUERY_DOCID).  This kind of query happens for
57*9eb7c2adSshess# queries which select by the docid/rowid implicit index.
58*9eb7c2adSshessdb eval {
59*9eb7c2adSshess  DROP TABLE IF EXISTS t1;
60*9eb7c2adSshess  DROP TABLE IF EXISTS t2;
61*9eb7c2adSshess  CREATE VIRTUAL TABLE t1 USING fts3(c);
62*9eb7c2adSshess  CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
63*9eb7c2adSshess  INSERT INTO t2 VALUES (null, 10);
64*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
65*9eb7c2adSshess  INSERT INTO t2 VALUES (null, 5);
66*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test');
67*9eb7c2adSshess  INSERT INTO t2 VALUES (null, 20);
68*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
69*9eb7c2adSshess}
70*9eb7c2adSshess
71*9eb7c2adSshess# TODO(shess): This actually is doing QUERY_GENERIC?  I'd have
72*9eb7c2adSshess# expected QUERY_DOCID in this case, as for a very large table the
73*9eb7c2adSshess# full scan is less efficient.
74*9eb7c2adSshessdo_test fts3e-2.1 {
75*9eb7c2adSshess  execsql {
76*9eb7c2adSshess    SELECT docid FROM t1 WHERE docid in (1, 2, 10);
77*9eb7c2adSshess    SELECT rowid FROM t1 WHERE rowid in (1, 2, 10);
78*9eb7c2adSshess  }
79*9eb7c2adSshess} {1 2 1 2}
80*9eb7c2adSshess
81*9eb7c2adSshessdo_test fts3e-2.2 {
82*9eb7c2adSshess  execsql {
83*9eb7c2adSshess    SELECT docid, weight FROM t1, t2 WHERE t2.id = t1.docid ORDER BY weight;
84*9eb7c2adSshess    SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight;
85*9eb7c2adSshess  }
86*9eb7c2adSshess} {2 5 1 10 3 20 2 5 1 10 3 20}
87*9eb7c2adSshess
88*9eb7c2adSshessdo_test fts3e-2.3 {
89*9eb7c2adSshess  execsql {
90*9eb7c2adSshess    SELECT docid, weight FROM t1, t2
91*9eb7c2adSshess           WHERE t2.weight>5 AND t2.id = t1.docid ORDER BY weight;
92*9eb7c2adSshess    SELECT t1.rowid, weight FROM t1, t2
93*9eb7c2adSshess           WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight;
94*9eb7c2adSshess  }
95*9eb7c2adSshess} {1 10 3 20 1 10 3 20}
96*9eb7c2adSshess
97*9eb7c2adSshess#*************************************************************************
98*9eb7c2adSshess# Test lookup by MATCH (QUERY_FULLTEXT).  This is the fulltext index.
99*9eb7c2adSshessdb eval {
100*9eb7c2adSshess  DROP TABLE IF EXISTS t1;
101*9eb7c2adSshess  DROP TABLE IF EXISTS t2;
102*9eb7c2adSshess  CREATE VIRTUAL TABLE t1 USING fts3(c);
103*9eb7c2adSshess  CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
104*9eb7c2adSshess  INSERT INTO t2 VALUES (null, 10);
105*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
106*9eb7c2adSshess  INSERT INTO t2 VALUES (null, 5);
107*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test');
108*9eb7c2adSshess  INSERT INTO t2 VALUES (null, 20);
109*9eb7c2adSshess  INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
110*9eb7c2adSshess}
111*9eb7c2adSshess
112*9eb7c2adSshessdo_test fts3e-3.1 {
113*9eb7c2adSshess  execsql {
114*9eb7c2adSshess    SELECT docid FROM t1 WHERE t1 MATCH 'this' ORDER BY docid;
115*9eb7c2adSshess  }
116*9eb7c2adSshess} {1 3}
117*9eb7c2adSshess
118*9eb7c2adSshessdo_test fts3e-3.2 {
119*9eb7c2adSshess  execsql {
120*9eb7c2adSshess    SELECT docid, weight FROM t1, t2
121*9eb7c2adSshess     WHERE t1 MATCH 'this' AND t1.docid = t2.id ORDER BY weight;
122*9eb7c2adSshess  }
123*9eb7c2adSshess} {1 10 3 20}
124*9eb7c2adSshess
125*9eb7c2adSshessfinish_test
126