fts5aj.test 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. source [file join [file dirname [info script]] fts5_common.tcl]
  19. set testprefix fts5aj
  20. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  21. ifcapable !fts5 {
  22. finish_test
  23. return
  24. }
  25. proc doc {} {
  26. 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]
  27. set res [list]
  28. for {set i 0} {$i < 20} {incr i} {
  29. lappend res [lindex $dict [expr int(rand() * 26)]]
  30. }
  31. set res
  32. }
  33. proc structure {} {
  34. set val [db one {SELECT fts5_decode(rowid,block) FROM t1_data WHERE rowid=10}]
  35. foreach lvl [lrange $val 1 end] {
  36. lappend res [expr [llength $lvl]-2]
  37. }
  38. set res
  39. }
  40. expr srand(0)
  41. do_execsql_test 1.0 {
  42. CREATE VIRTUAL TABLE t1 USING fts5(x);
  43. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  44. }
  45. for {set iTest 0} {$iTest < 50000} {incr iTest} {
  46. if {$iTest > 1000} { execsql { DELETE FROM t1 WHERE rowid=($iTest-1000) } }
  47. set new [doc]
  48. execsql { INSERT INTO t1 VALUES($new) }
  49. if {$iTest==10000} { set sz1 [db one {SELECT count(*) FROM t1_data}] }
  50. if {0==($iTest % 1000)} {
  51. set sz [db one {SELECT count(*) FROM t1_data}]
  52. set s [structure]
  53. do_execsql_test 1.$iTest.$sz.{$s} {
  54. INSERT INTO t1(t1) VALUES('integrity-check')
  55. }
  56. }
  57. }
  58. do_execsql_test 2.0 { INSERT INTO t1(t1) VALUES('integrity-check') }
  59. finish_test