blob: 08b68b97d9653669b0e8a9f9edf40fc0f3f1f5c7 [file] [log] [blame]
dan74f47e12012-03-21 14:34:23 +00001# 2012 March 06
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. The
12# focus of this script is testing the incremental merge function.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17source $testdir/fts3_common.tcl
18source $testdir/lock_common.tcl
19source $testdir/bc_common.tcl
20
21set ::testprefix fts4merge3
22
danc8f86162012-04-03 18:34:24 +000023ifcapable !fts3 {
24 finish_test
25 return
26}
27
dan74f47e12012-03-21 14:34:23 +000028if {"" == [bc_find_binaries backcompat.test]} {
29 finish_test
30 return
31}
32
drhccdf2022012-03-30 13:34:17 +000033db close
dan74f47e12012-03-21 14:34:23 +000034do_all_bc_test {
35
36 sql2 { PRAGMA page_size = 512 }
37 if { 0==[catch { sql2 { CREATE VIRTUAL TABLE x USING fts4 } } ] } {
38
39 # Build a large database.
40 set msg "this takes around 12 seconds"
41 do_test "1.1 ($msg)" { fts3_build_db_2 20000 } {}
42
43 # Run some queries on it, using the old and new versions.
44 do_test 1.2 { sql1 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485}
45 do_test 1.3 { sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485}
46
drh7ed243b2012-04-19 17:19:51 +000047 do_test 1.4 {
48 set x [sql2 "PRAGMA page_count"]
49 expr {$x>=1284 && $x<=1286}
50 } {1}
dan74f47e12012-03-21 14:34:23 +000051 do_test 1.5 { sql2 {
52 SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
53 } } [list 0 15 1 1 2 14 3 4]
54
55 # Run some incr-merge operations on the db.
56 for {set i 0} {$i<10} {incr i} {
57 do_test 1.6.$i.1 { sql1 { INSERT INTO t2(t2) VALUES('merge=2,2') } } {}
58 do_test 1.6.$i.2 {
59 sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
60 } {1485}
61 }
62
63 do_test 1.7 { sql2 {
64 SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
danc7dbce02016-03-08 15:37:48 +000065 } } {2 15 3 5}
dan74f47e12012-03-21 14:34:23 +000066
67 # Using the old connection, insert many rows.
68 do_test 1.8 {
69 for {set i 0} {$i < 1500} {incr i} {
70 sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i"
71 }
72 } {}
73
74 do_test 1.9 { sql2 {
75 SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
danc7dbce02016-03-08 15:37:48 +000076 } } [list 0 12 1 13 2 4 3 6]
dan74f47e12012-03-21 14:34:23 +000077
78 # Run a big incr-merge operation on the db.
79 do_test 1.10 { sql1 { INSERT INTO t2(t2) VALUES('merge=2000,2') } } {}
80 do_test 1.11 {
81 sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
82 } {1485 21485}
83
84 do_test 1.12 {
85 for {set i 0} {$i < 1500} {incr i} {
86 sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i"
87 }
88 } {}
89 do_test 1.13 {
90 sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
91 } {1485 21485 22985}
92
93 do_test 1.14 {
94 sql2 "INSERT INTO t2(t2) VALUES('optimize')"
95 sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
96 } {1485 21485 22985}
97
98 do_test 1.15 { sql2 {
99 SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
danc7dbce02016-03-08 15:37:48 +0000100 } } {4 1}
dan74f47e12012-03-21 14:34:23 +0000101 }
102}
103
104
105finish_test