| 1 |
# 2014 June 17 |
| 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 FTS5 module. |
| 13 |
# |
| 14 |
# Specifically, this tests that, provided the amount of data remains |
| 15 |
# constant, the FTS index does not grow indefinitely as rows are inserted |
| 16 |
# and deleted, |
| 17 |
# |
| 18 |
|
| 19 |
source [file join [file dirname [info script]] fts5_common.tcl] |
| 20 |
set testprefix fts5aj |
| 21 |
|
| 22 |
# If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 23 |
ifcapable !fts5 { |
| 24 |
finish_test |
| 25 |
return |
| 26 |
} |
| 27 |
|
| 28 |
proc doc {} { |
| 29 |
set dict [list a b c d e f g h i j k l m n o p q r s t u v w x y z] |
| 30 |
set res [list] |
| 31 |
for {set i 0} {$i < 20} {incr i} { |
| 32 |
lappend res [lindex $dict [expr int(rand() * 26)]] |
| 33 |
} |
| 34 |
set res |
| 35 |
} |
| 36 |
|
| 37 |
proc structure {} { |
| 38 |
set val [db one {SELECT fts5_decode(rowid,block) FROM t1_data WHERE rowid=10}] |
| 39 |
foreach lvl [lrange $val 1 end] { |
| 40 |
lappend res [expr [llength $lvl]-2] |
| 41 |
} |
| 42 |
set res |
| 43 |
} |
| 44 |
|
| 45 |
expr srand(0) |
| 46 |
do_execsql_test 1.0 { |
| 47 |
CREATE VIRTUAL TABLE t1 USING fts5(x); |
| 48 |
INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 49 |
} |
| 50 |
|
| 51 |
for {set iTest 0} {$iTest < 50000} {incr iTest} { |
| 52 |
if {$iTest > 1000} { execsql { DELETE FROM t1 WHERE rowid=($iTest-1000) } } |
| 53 |
set new [doc] |
| 54 |
execsql { INSERT INTO t1 VALUES($new) } |
| 55 |
if {$iTest==10000} { set sz1 [db one {SELECT count(*) FROM t1_data}] } |
| 56 |
if {0==($iTest % 1000)} { |
| 57 |
set sz [db one {SELECT count(*) FROM t1_data}] |
| 58 |
set s [structure] |
| 59 |
do_execsql_test 1.$iTest.$sz.{$s} { |
| 60 |
INSERT INTO t1(t1) VALUES('integrity-check') |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
do_execsql_test 2.0 { INSERT INTO t1(t1) VALUES('integrity-check') } |
| 66 |
|
| 67 |
|
| 68 |
finish_test |