fts4noti.test 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # 2013 June 21
  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 notindexed=xxx FTS4 option.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. set ::testprefix fts4noti
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts3 {
  19. finish_test
  20. return
  21. }
  22. #-------------------------------------------------------------------------
  23. # Test that typos in "notindexed=" column names are detected.
  24. #
  25. do_execsql_test 1.0 {
  26. CREATE TABLE cc(a, b, c);
  27. }
  28. foreach {tn arg res} {
  29. 1 "(b, c, notindexed=a)" {1 {no such column: a}}
  30. 2 "(a, b, notindexed=a)" {0 {}}
  31. 3 "(a, b, notindexed=a, notindexed=a)" {0 {}}
  32. 4 "(notindexed=a, a, b)" {0 {}}
  33. 5 "(notindexed=a, notindexed=b, notindexed=c, a, b, c, d)" {0 {}}
  34. 6 "(notindexed=a, notindexed=B, notindexed=c, a, b, c, d)" {0 {}}
  35. 7 "(notindexed=a, notindexed=b, notindexed=c, a, B, c, d)" {0 {}}
  36. 8 "(notindexed=d, content=cc)" {1 {no such column: d}}
  37. 9 "(notindexed=a, content=cc)" {0 {}}
  38. 10 "(notindexed=a, notindexed=b, a)" {1 {no such column: b}}
  39. 11 "(notindexed=a, notindexed=b, b)" {1 {no such column: a}}
  40. } {
  41. do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts4 $arg" $res
  42. if {[lindex $res 0]==0} { execsql "DROP TABLE t1" }
  43. }
  44. do_execsql_test 1.x { SELECT name FROM sqlite_master } {cc}
  45. #-------------------------------------------------------------------------
  46. # Test that notindexed columns are not indexed.
  47. #
  48. foreach {tn schema} {
  49. 1 {
  50. CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, notindexed=b);
  51. }
  52. 2 {
  53. CREATE TABLE c1(a, b, c);
  54. INSERT INTO c1 VALUES('one two', 'three four', 'five six');
  55. INSERT INTO c1 VALUES('three four', 'five six', 'one two');
  56. CREATE VIRTUAL TABLE t1 USING fts4(content=c1, notindexed=b);
  57. }
  58. 3 {
  59. CREATE VIRTUAL TABLE t1 USING fts4(content="", a, b, c, notindexed=b);
  60. }
  61. } {
  62. execsql $schema
  63. do_execsql_test 2.$tn.1 {
  64. INSERT INTO t1(docid,a,b,c) VALUES(1, 'one two', 'three four', 'five six');
  65. INSERT INTO t1(docid,a,b,c) VALUES(2, 'three four', 'five six', 'one two');
  66. }
  67. do_execsql_test 2.$tn.2 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2}
  68. do_execsql_test 2.$tn.3 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2}
  69. do_execsql_test 2.$tn.4 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1}
  70. do_execsql_test 2.$tn.5 { INSERT INTO t1(t1) VALUES('optimize') }
  71. do_execsql_test 2.$tn.6 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2}
  72. do_execsql_test 2.$tn.7 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2}
  73. do_execsql_test 2.$tn.8 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1}
  74. if {$tn!=3} {
  75. do_execsql_test 2.$tn.9 { INSERT INTO t1(t1) VALUES('rebuild') }
  76. do_execsql_test 2.$tn.10 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2}
  77. do_execsql_test 2.$tn.11 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2}
  78. do_execsql_test 2.$tn.12 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1}
  79. do_execsql_test 2.$tn.13 {
  80. SELECT a,b,c FROM t1 WHERE docid=1
  81. } {{one two} {three four} {five six}}
  82. do_execsql_test 2.$tn.14 {
  83. SELECT a,b,c FROM t1 WHERE docid=2
  84. } {{three four} {five six} {one two}}
  85. }
  86. do_execsql_test 2.x { DROP TABLE t1 }
  87. }
  88. #-------------------------------------------------------------------------
  89. # Test that notindexed columns are not scanned for deferred tokens.
  90. #
  91. do_execsql_test 3.1 {
  92. CREATE VIRTUAL TABLE t2 USING fts4(x, y, notindexed=x);
  93. }
  94. do_test 3.2 {
  95. set v [string repeat " 1" 50000]
  96. set v1 "x $v"
  97. set v2 "y $v"
  98. execsql {
  99. INSERT INTO t2 VALUES(1, 'x y z');
  100. INSERT INTO t2 VALUES(2, $v1);
  101. INSERT INTO t2 VALUES(3, $v2);
  102. INSERT INTO t2 VALUES(4, $v2);
  103. INSERT INTO t2 VALUES(5, $v2);
  104. INSERT INTO t2 VALUES(6, $v2);
  105. }
  106. } {}
  107. do_execsql_test 3.3 { SELECT x FROM t2 WHERE t2 MATCH '2' } {}
  108. do_execsql_test 3.4 { SELECT x FROM t2 WHERE t2 MATCH '1' } {2 3 4 5 6}
  109. do_execsql_test 3.5 { SELECT x FROM t2 WHERE t2 MATCH 'x' } {1 2}
  110. do_execsql_test 3.6 { SELECT x FROM t2 WHERE t2 MATCH 'x 1' } {2}
  111. do_execsql_test 3.x { DROP TABLE t2 }
  112. #-------------------------------------------------------------------------
  113. # Test that the types of notindexed columns are not modified.
  114. #
  115. do_execsql_test 4.1 {
  116. CREATE VIRTUAL TABLE t2 USING fts4(poi, addr, notindexed=poi);
  117. INSERT INTO t2 VALUES(114, 'x x x');
  118. INSERT INTO t2 VALUES(X'1234', 'y y y');
  119. INSERT INTO t2 VALUES(NULL, 'z z z');
  120. INSERT INTO t2 VALUES(113.2, 'w w w');
  121. INSERT INTO t2 VALUES('poi', 'v v v');
  122. }
  123. do_execsql_test 4.2 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'x' } {integer}
  124. do_execsql_test 4.3 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'y' } {blob}
  125. do_execsql_test 4.4 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'z' } {null}
  126. do_execsql_test 4.5 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'w' } {real}
  127. do_execsql_test 4.6 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'v' } {text}
  128. do_execsql_test 4.x { DROP TABLE t2 }
  129. #-------------------------------------------------------------------------
  130. # Test that multiple notindexed options on a single table work as expected.
  131. #
  132. do_execsql_test 5.1 {
  133. CREATE VIRTUAL TABLE t2 USING fts4(
  134. notindexed="three", one, two, three, notindexed="one",
  135. );
  136. INSERT INTO t2 VALUES('a', 'b', 'c');
  137. INSERT INTO t2 VALUES('c', 'a', 'b');
  138. INSERT INTO t2 VALUES('b', 'c', 'a');
  139. }
  140. do_execsql_test 5.2 { SELECT docid FROM t2 WHERE t2 MATCH 'a' } {2}
  141. do_execsql_test 5.3 { SELECT docid FROM t2 WHERE t2 MATCH 'b' } {1}
  142. do_execsql_test 5.4 { SELECT docid FROM t2 WHERE t2 MATCH 'c' } {3}
  143. do_execsql_test 5.x { DROP TABLE t2 }
  144. finish_test