fts3defer3.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # 2010 October 23
  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. # This file contains a very simple test to show that the deferred tokens
  13. # optimization is doing something.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. source $testdir/malloc_common.tcl
  18. ifcapable !fts3||!fts4_deferred {
  19. finish_test
  20. return
  21. }
  22. set testprefix fts3defer3
  23. set nDoclist 3204
  24. set nDoc 800
  25. # Set up a database that contains 800 rows. Each row contains the document
  26. # "b b", except for the row with docid=200, which contains "a b". Hence
  27. # token "b" is extremely common and token "a" is not.
  28. #
  29. do_test 1.1 {
  30. execsql {
  31. CREATE VIRTUAL TABLE t1 USING fts4;
  32. BEGIN;
  33. }
  34. for {set i 1} {$i <= $nDoc} {incr i} {
  35. set document "b b"
  36. if {$i==200} { set document "a b" }
  37. execsql { INSERT INTO t1 (docid, content) VALUES($i, $document) }
  38. }
  39. execsql COMMIT
  40. } {}
  41. # Check that the db contains two doclists. A small one for "a" and a
  42. # larger one for "b".
  43. #
  44. do_execsql_test 1.2 {
  45. SELECT blockid, length(block) FROM t1_segments;
  46. } [list 1 8 2 $nDoclist]
  47. # Query for 'a b'. Although this test doesn't prove so, token "b" will
  48. # be deferred because of the very large associated doclist.
  49. #
  50. do_execsql_test 1.3 {
  51. SELECT docid, content FROM t1 WHERE t1 MATCH 'a b';
  52. } {200 {a b}}
  53. # Zero out the doclist for token "b" within the database file. Now the
  54. # only queries that use token "b" that will work are those that defer
  55. # it. Any query that tries to use the doclist belonging to token "b"
  56. # will fail.
  57. #
  58. do_test 1.4 {
  59. set fd [db incrblob t1_segments block 2]
  60. puts -nonewline $fd [string repeat "\00" $nDoclist]
  61. close $fd
  62. } {}
  63. # The first two queries succeed, as they defer token "b". The last one
  64. # fails, as it tries to load the corrupt doclist.
  65. #
  66. do_execsql_test 1.5 {
  67. SELECT docid, content FROM t1 WHERE t1 MATCH 'a b';
  68. } {200 {a b}}
  69. do_execsql_test 1.6 {
  70. SELECT count(*) FROM t1 WHERE t1 MATCH 'a b';
  71. } {1}
  72. do_catchsql_test 1.7 {
  73. SELECT count(*) FROM t1 WHERE t1 MATCH 'b';
  74. } {1 {database disk image is malformed}}
  75. finish_test