fts4merge3.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # 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. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. source $testdir/fts3_common.tcl
  17. source $testdir/lock_common.tcl
  18. source $testdir/bc_common.tcl
  19. set ::testprefix fts4merge3
  20. ifcapable !fts3 {
  21. finish_test
  22. return
  23. }
  24. if {"" == [bc_find_binaries backcompat.test]} {
  25. finish_test
  26. return
  27. }
  28. db close
  29. do_all_bc_test {
  30. sql2 { PRAGMA page_size = 512 }
  31. if { 0==[catch { sql2 { CREATE VIRTUAL TABLE x USING fts4 } } ] } {
  32. # Build a large database.
  33. set msg "this takes around 12 seconds"
  34. do_test "1.1 ($msg)" { fts3_build_db_2 20000 } {}
  35. # Run some queries on it, using the old and new versions.
  36. do_test 1.2 { sql1 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485}
  37. do_test 1.3 { sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485}
  38. do_test 1.4 {
  39. set x [sql2 "PRAGMA page_count"]
  40. expr {$x>=1284 && $x<=1286}
  41. } {1}
  42. do_test 1.5 { sql2 {
  43. SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
  44. } } [list 0 15 1 1 2 14 3 4]
  45. # Run some incr-merge operations on the db.
  46. for {set i 0} {$i<10} {incr i} {
  47. do_test 1.6.$i.1 { sql1 { INSERT INTO t2(t2) VALUES('merge=2,2') } } {}
  48. do_test 1.6.$i.2 {
  49. sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
  50. } {1485}
  51. }
  52. do_test 1.7 { sql2 {
  53. SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
  54. } } [list 0 1 2 18 3 5]
  55. # Using the old connection, insert many rows.
  56. do_test 1.8 {
  57. for {set i 0} {$i < 1500} {incr i} {
  58. sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i"
  59. }
  60. } {}
  61. do_test 1.9 { sql2 {
  62. SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
  63. } } [list 0 13 1 13 2 5 3 6]
  64. # Run a big incr-merge operation on the db.
  65. do_test 1.10 { sql1 { INSERT INTO t2(t2) VALUES('merge=2000,2') } } {}
  66. do_test 1.11 {
  67. sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
  68. } {1485 21485}
  69. do_test 1.12 {
  70. for {set i 0} {$i < 1500} {incr i} {
  71. sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i"
  72. }
  73. } {}
  74. do_test 1.13 {
  75. sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
  76. } {1485 21485 22985}
  77. do_test 1.14 {
  78. sql2 "INSERT INTO t2(t2) VALUES('optimize')"
  79. sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'"
  80. } {1485 21485 22985}
  81. do_test 1.15 { sql2 {
  82. SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1
  83. } } {6 1}
  84. }
  85. }
  86. finish_test