fts5unindexed2.test 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. # 2024 Sep 13
  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. # The tests in this file focus on "unindexed" columns in contentless
  13. # tables.
  14. #
  15. source [file join [file dirname [info script]] fts5_common.tcl]
  16. set testprefix fts5unindexed2
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. do_execsql_test 1.1 {
  23. CREATE VIRTUAL TABLE t1 USING fts5(
  24. a, b UNINDEXED, content=, contentless_unindexed=1
  25. );
  26. } {}
  27. do_execsql_test 1.2 {
  28. INSERT INTO t1 VALUES('abc def', 'ghi jkl');
  29. }
  30. do_execsql_test 1.3 {
  31. SELECT rowid, a, b FROM t1
  32. } {1 {} {ghi jkl}}
  33. do_execsql_test 1.4 {
  34. INSERT INTO t1(rowid, a, b) VALUES(11, 'hello world', 'one two three');
  35. }
  36. do_execsql_test 1.5 {
  37. INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 1, 'abc def', 'ghi jkl');
  38. }
  39. do_execsql_test 1.6 {
  40. SELECT rowid, a, b FROM t1
  41. } {
  42. 11 {} {one two three}
  43. }
  44. do_execsql_test 1.7 {
  45. PRAGMA integrity_check
  46. } {ok}
  47. do_execsql_test 1.8 {
  48. INSERT INTO t1(rowid, a, b) VALUES(12, 'abc def', 'ghi jkl');
  49. }
  50. do_execsql_test 1.9 {
  51. SELECT rowid, a, b FROM t1('def')
  52. } {12 {} {ghi jkl}}
  53. do_execsql_test 1.10 {
  54. SELECT rowid, a, b FROM t1('def OR hello') ORDER BY rank
  55. } {11 {} {one two three} 12 {} {ghi jkl}}
  56. do_execsql_test 1.11 {
  57. SELECT rowid, a, b FROM t1 WHERE rowid=11
  58. } {11 {} {one two three}}
  59. do_execsql_test 1.12 {
  60. SELECT rowid, a, b FROM t1
  61. } {11 {} {one two three} 12 {} {ghi jkl}}
  62. fts5_aux_test_functions db
  63. do_execsql_test 1.12.2 {
  64. SELECT rowid, fts5_test_columntext(t1) FROM t1('def OR hello')
  65. } {11 {{} {one two three}} 12 {{} {ghi jkl}}}
  66. do_execsql_test 1.13 {
  67. INSERT INTO t1(t1) VALUES('delete-all');
  68. }
  69. do_execsql_test 1.14 {
  70. SELECT rowid, a, b FROM t1
  71. }
  72. do_execsql_test 1.15 {
  73. PRAGMA integrity_check
  74. } {ok}
  75. do_execsql_test 2.0 {
  76. CREATE VIRTUAL TABLE t4 USING fts5(
  77. x, y UNINDEXED, z, columnsize=0, content='', contentless_unindexed=1
  78. );
  79. }
  80. do_execsql_test 2.1 {
  81. INSERT INTO t4(rowid, x, y, z) VALUES(1, 'a a', 'b b b', 'c');
  82. }
  83. #-------------------------------------------------------------------------
  84. reset_db
  85. do_execsql_test 3.0 {
  86. CREATE VIRTUAL TABLE x1 USING fts5(
  87. a UNINDEXED, b, c UNINDEXED, d, content=, contentless_delete=1,
  88. contentless_unindexed=1
  89. );
  90. }
  91. do_execsql_test 3.1 {
  92. INSERT INTO x1(rowid, a, b, c, d) VALUES(131, 'aaa', 'bbb', 'ccc', 'ddd');
  93. }
  94. do_execsql_test 3.2 {
  95. SELECT * FROM x1
  96. } {aaa {} ccc {}}
  97. do_execsql_test 3.3 {
  98. INSERT INTO x1(rowid, a, b, c, d) VALUES(1000, 'AAA', 'BBB', 'CCC', 'DDD');
  99. }
  100. do_execsql_test 3.4 {
  101. SELECT rowid, * FROM x1
  102. } {
  103. 131 aaa {} ccc {}
  104. 1000 AAA {} CCC {}
  105. }
  106. do_execsql_test 3.5 {
  107. DELETE FROM x1 WHERE rowid=131;
  108. SELECT rowid, * FROM x1
  109. } {
  110. 1000 AAA {} CCC {}
  111. }
  112. do_execsql_test 3.6 {
  113. INSERT INTO x1(rowid, a, b, c, d) VALUES(112, 'aaa', 'bbb', 'ccc', 'ddd');
  114. SELECT rowid, * FROM x1
  115. } {
  116. 112 aaa {} ccc {}
  117. 1000 AAA {} CCC {}
  118. }
  119. do_execsql_test 3.7 {
  120. UPDATE x1 SET b='hello', d='world', rowid=1120 WHERE rowid=112
  121. }
  122. do_execsql_test 3.8 {
  123. SELECT rowid, * FROM x1
  124. } {
  125. 1000 AAA {} CCC {}
  126. 1120 aaa {} ccc {}
  127. }
  128. do_execsql_test 3.9 {
  129. SELECT rowid, * FROM x1('hello');
  130. } {
  131. 1120 aaa {} ccc {}
  132. }
  133. do_execsql_test 3.9 {
  134. SELECT rowid, * FROM x1('bbb');
  135. } {
  136. 1000 AAA {} CCC {}
  137. }
  138. fts5_aux_test_functions db
  139. do_execsql_test 3.10 {
  140. SELECT rowid, fts5_test_columntext(x1) FROM x1('b*')
  141. } {1000 {AAA {} CCC {}}}
  142. #-------------------------------------------------------------------------
  143. # Check that if contentless_unindexed=1 is not specified, the values
  144. # of UNINDEXED columns are not stored in the database.
  145. #
  146. # Also check that contentless_unindexed=1 is not allowed unless the table
  147. # is actually contentless.
  148. #
  149. reset_db
  150. do_execsql_test 4.0 {
  151. CREATE VIRTUAL TABLE ft USING fts5(a, b, c UNINDEXED, content='');
  152. INSERT INTO ft VALUES('one', 'two', 'three');
  153. SELECT rowid, * FROM ft;
  154. } {1 {} {} {}}
  155. do_execsql_test 4.1 {
  156. SELECT name FROM sqlite_schema ORDER BY 1
  157. } {
  158. ft ft_config ft_data ft_docsize ft_idx
  159. }
  160. do_catchsql_test 4.2 {
  161. CREATE VIRTUAL TABLE ft2 USING fts5(
  162. a, b, c UNINDEXED, contentless_unindexed=1
  163. );
  164. } {1 {contentless_unindexed=1 requires a contentless table}}
  165. do_catchsql_test 4.3 {
  166. DELETE FROM ft WHERE rowid=1
  167. } {1 {cannot DELETE from contentless fts5 table: ft}}
  168. #-------------------------------------------------------------------------
  169. # Check that the usual restrictions on contentless tables apply to
  170. # contentless_unindexed=1 tables.
  171. #
  172. reset_db
  173. do_execsql_test 5.0 {
  174. CREATE VIRTUAL TABLE ft USING fts5(
  175. a, b UNINDEXED, c, content='', contentless_unindexed=1
  176. );
  177. INSERT INTO ft VALUES('one', 'two', 'three');
  178. INSERT INTO ft VALUES('four', 'five', 'six');
  179. INSERT INTO ft VALUES('seven', 'eight', 'nine');
  180. SELECT rowid, * FROM ft;
  181. } {
  182. 1 {} two {}
  183. 2 {} five {}
  184. 3 {} eight {}
  185. }
  186. do_execsql_test 5.1 {
  187. PRAGMA integrity_check
  188. } {ok}
  189. do_catchsql_test 5.2 {
  190. DELETE FROM ft WHERE rowid=2
  191. } {1 {cannot DELETE from contentless fts5 table: ft}}
  192. do_execsql_test 5.3 {
  193. SELECT rowid, * FROM ft('six')
  194. } {
  195. 2 {} five {}
  196. }
  197. do_catchsql_test 5.4 {
  198. UPDATE ft SET a='x', b='y', c='z' WHERE rowid=3
  199. } {1 {cannot UPDATE contentless fts5 table: ft}}
  200. fts5_aux_test_functions db
  201. do_execsql_test 5.5 {
  202. SELECT fts5_test_columntext(ft) FROM ft WHERE rowid=3
  203. } {
  204. {{} eight {}}
  205. }
  206. do_execsql_test 5.6 {
  207. SELECT fts5_test_columntext(ft) FROM ft('three');
  208. } {
  209. {{} two {}}
  210. }
  211. #-------------------------------------------------------------------------
  212. # Check that it is possible to UPDATE a contentless_unindexed=1 table
  213. # if the only columns being modified are UNINDEXED.
  214. #
  215. # If the contentless_unindexed=1 table is also contentless_delete=1, then
  216. # it is also possible to update indexed columns - but only if *all* indexed
  217. # columns are updated.
  218. #
  219. reset_db
  220. do_execsql_test 6.0 {
  221. CREATE VIRTUAL TABLE ft1 USING fts5(a, b UNINDEXED, c UNINDEXED, d,
  222. contentless_unindexed=1, content=''
  223. );
  224. INSERT INTO ft1(rowid, a, b, c, d) VALUES
  225. (100, 'x y', 'b1', 'c1', 'a b'),
  226. (200, 'c d', 'b2', 'c2', 'a b'),
  227. (300, 'e f', 'b3', 'c3', 'a b');
  228. }
  229. do_execsql_test 6.1 {
  230. UPDATE ft1 SET b='b1.1', c='c1.1' WHERE rowid=100;
  231. }
  232. do_execsql_test 6.2 {
  233. UPDATE ft1 SET b='b2.1' WHERE rowid=200;
  234. }
  235. do_execsql_test 6.3 {
  236. UPDATE ft1 SET c='c3.1' WHERE rowid=300;
  237. }
  238. do_execsql_test 6.4 {
  239. SELECT rowid, a, b, c, d FROM ft1
  240. } {
  241. 100 {} b1.1 c1.1 {}
  242. 200 {} b2.1 c2 {}
  243. 300 {} b3 c3.1 {}
  244. }
  245. finish_test