fts4incr.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # 2012 March 26
  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. set testdir [file dirname $argv0]
  13. source $testdir/tester.tcl
  14. source $testdir/fts3_common.tcl
  15. set ::testprefix fts4incr
  16. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  17. ifcapable !fts3 {
  18. finish_test
  19. return
  20. }
  21. # Create the fts_kjv_genesis procedure which fills and FTS3/4 table
  22. # with the complete text of the Book of Genesis.
  23. #
  24. source $testdir/genesis.tcl
  25. do_test 1.0 {
  26. execsql { CREATE VIRTUAL TABLE t1 USING fts4(words) }
  27. fts_kjv_genesis
  28. } {}
  29. do_execsql_test 1.1 {
  30. SELECT min(docid), max(docid) FROM t1;
  31. } {1001001 1050026}
  32. foreach {tn q res} {
  33. 1 { SELECT count(*) FROM t1 WHERE t1 MATCH 'and' AND docid < 1010000} 224
  34. 2 { SELECT count(*) FROM t1 WHERE t1 MATCH '"in the"' AND docid < 1010000} 47
  35. 3 { SELECT count(*) FROM t1 WHERE t1 MATCH '"And God"' AND docid < 1010000} 33
  36. 4 { SELECT count(*) FROM t1 WHERE t1
  37. MATCH '"land of canaan"' AND docid < 1030000 } 7
  38. } {
  39. foreach s {0 1} {
  40. execsql "INSERT INTO t1(t1) VALUES('test-no-incr-doclist=$s')"
  41. do_execsql_test 2.$tn.$s $q $res
  42. set t($s) [lindex [time [list execsql $q] 100] 0]
  43. }
  44. puts "with optimization: $t(0) without: $t(1)"
  45. }
  46. do_test 2.1 {
  47. execsql {
  48. CREATE VIRTUAL TABLE t2 USING fts4(order=DESC);
  49. }
  50. set num [list one two three four five six seven eight nine ten]
  51. execsql BEGIN
  52. for {set i 0} {$i < 10000} {incr i} {
  53. set x "[lindex $num [expr $i%10]] zero"
  54. execsql { INSERT INTO t2(docid, content) VALUES($i, $x) }
  55. }
  56. execsql COMMIT
  57. execsql { INSERT INTO t2(t2) VALUES('optimize') }
  58. } {}
  59. do_execsql_test 2.2 {
  60. SELECT count(*) FROM t2 WHERE t2 MATCH '"never zero"'
  61. } {0}
  62. do_execsql_test 2.3 {
  63. SELECT count(*) FROM t2 WHERE t2 MATCH '"two zero"'
  64. } {1000}
  65. finish_test