fts5optimize.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # 2014 Dec 20
  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. #
  12. #
  13. source [file join [file dirname [info script]] fts5_common.tcl]
  14. set testprefix fts5optimize
  15. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  16. ifcapable !fts5 {
  17. finish_test
  18. return
  19. }
  20. #
  21. # 1.* - Warm body tests for index optimization using ('optimize')
  22. #
  23. # 2.* - Warm body tests for index optimization using ('merge', -1)
  24. #
  25. proc rnddoc {nWord} {
  26. set vocab {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 nVocab [llength $vocab]
  28. set ret [list]
  29. for {set i 0} {$i < $nWord} {incr i} {
  30. lappend ret [lindex $vocab [expr {int(rand() * $nVocab)}]]
  31. }
  32. return $ret
  33. }
  34. foreach {tn nStep} {
  35. 1 2
  36. 2 10
  37. 3 50
  38. 4 500
  39. } {
  40. reset_db
  41. db func rnddoc rnddoc
  42. do_execsql_test 1.$tn.1 {
  43. CREATE VIRTUAL TABLE t1 USING fts5(x, y);
  44. }
  45. do_test 1.$tn.2 {
  46. for {set i 0} {$i < $nStep} {incr i} {
  47. execsql { INSERT INTO t1 VALUES( rnddoc(5), rnddoc(5) ) }
  48. }
  49. } {}
  50. do_execsql_test 1.$tn.3 {
  51. INSERT INTO t1(t1) VALUES('integrity-check');
  52. }
  53. do_execsql_test 1.$tn.4 {
  54. INSERT INTO t1(t1) VALUES('optimize');
  55. }
  56. do_execsql_test 1.$tn.5 {
  57. INSERT INTO t1(t1) VALUES('integrity-check');
  58. }
  59. do_test 1.$tn.6 { fts5_segcount t1 } 1
  60. }
  61. foreach {tn nStep} {
  62. 1 2
  63. 2 10
  64. 3 50
  65. 4 500
  66. } {
  67. reset_db
  68. db func rnddoc rnddoc
  69. do_execsql_test 1.$tn.1 {
  70. CREATE VIRTUAL TABLE t1 USING fts5(x, y);
  71. }
  72. do_test 2.$tn.2 {
  73. for {set i 0} {$i < $nStep} {incr i} {
  74. execsql { INSERT INTO t1 VALUES( rnddoc(5), rnddoc(5) ) }
  75. }
  76. } {}
  77. do_execsql_test 2.$tn.3 {
  78. INSERT INTO t1(t1) VALUES('integrity-check');
  79. }
  80. do_test 2.$tn.4 {
  81. execsql { INSERT INTO t1(t1, rank) VALUES('merge', -1) }
  82. while 1 {
  83. set c [db total_changes]
  84. execsql { INSERT INTO t1(t1, rank) VALUES('merge', 1) }
  85. set c [expr [db total_changes]-$c]
  86. if {$c<2} break
  87. }
  88. } {}
  89. do_execsql_test 2.$tn.5 {
  90. INSERT INTO t1(t1) VALUES('integrity-check');
  91. }
  92. do_test 2.$tn.6 { fts5_segcount t1 } 1
  93. }
  94. finish_test