xref: /sqlite-3.40.0/test/fts4merge4.test (revision 9c5e1e40)
1# 2013 May 29
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#*************************************************************************
11# This file implements regression tests for SQLite library.
12#
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16source $testdir/fts3_common.tcl
17set ::testprefix fts4merge4
18
19ifcapable !fts3||!shared_cache {
20  finish_test
21  return
22}
23
24set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
25
26do_execsql_test 1.1 { CREATE VIRTUAL TABLE t1 USING fts4 }
27
28do_test 1.2 {
29  for {set i 0} {$i < 2000} {incr i} {
30    execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');}
31  }
32} {}
33
34do_test 1.3 {
35  execsql BEGIN
36  for {set i 0} {$i < 2000} {incr i} {
37    execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');}
38  }
39  execsql {
40    INSERT INTO t1(t1) VALUES('merge=8,50');
41    COMMIT
42  }
43} {}
44
45reset_db
46do_execsql_test 2.0 { CREATE VIRTUAL TABLE t1 USING fts4 }
47do_test 2.1 {
48  for {set i 0} {$i < 2000} {incr i} {
49    execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');}
50  }
51} {}
52do_execsql_test 2.2 { SELECT count(*) FROM t1_segdir; } 35
53do_execsql_test 2.3 { INSERT INTO t1(t1) VALUES('optimize') } {}
54do_execsql_test 2.4 { SELECT count(*) FROM t1_segdir; } 1
55
56#-------------------------------------------------------------------------
57# Now test that the automerge=? option appears to work.
58#
59do_execsql_test 2.1 { CREATE VIRTUAL TABLE t2 USING fts4; }
60
61set doc ""
62foreach c1 "a b c d e f g h i j" {
63  foreach c2 "a b c d e f g h i j" {
64    foreach c3 "a b c d e f g h i j" {
65      lappend doc "$c1$c2$c3"
66    }
67  }
68}
69set doc [string repeat $doc 10]
70
71foreach {tn am expected} {
72  1 {automerge=2} {1 1   2 1   4 1   6 1}
73  2 {automerge=4} {1 2   2 1   3 1}
74  3 {automerge=8} {0 4   1 3   2 1}
75  4 {automerge=1} {0 4   1 3   2 1}
76} {
77  foreach {tn2 openclose} {1 {} 2 { db close ; sqlite3 db test.db }} {
78    do_test 2.2.$tn.$tn2 {
79      execsql { DELETE FROM t2 }
80      execsql { INSERT INTO t2(t2) VALUES($am) };
81
82      eval $openclose
83
84      for {set i 0} {$i < 100} {incr i} {
85        execsql {
86          BEGIN;
87            INSERT INTO t2 VALUES($doc);
88            INSERT INTO t2 VALUES($doc);
89            INSERT INTO t2 VALUES($doc);
90            INSERT INTO t2 VALUES($doc);
91            INSERT INTO t2 VALUES($doc);
92          COMMIT;
93        }
94      }
95
96      execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level }
97    } [list {*}$expected]
98  }
99}
100
101sqlite3_enable_shared_cache $::enable_shared_cache
102finish_test
103