fts5contentless4.test 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # 2023 July 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. #
  12. # This file contains tests for the content= and content_rowid= options.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5contentless4
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. proc document {n} {
  22. set vocab [list A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
  23. set ret [list]
  24. for {set ii 0} {$ii < $n} {incr ii} {
  25. lappend ret [lindex $vocab [expr int(rand()*[llength $vocab])]]
  26. }
  27. set ret
  28. }
  29. db func document document
  30. do_execsql_test 1.0 {
  31. CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
  32. INSERT INTO ft(ft, rank) VALUES('pgsz', 240);
  33. WITH s(i) AS (
  34. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
  35. )
  36. INSERT INTO ft SELECT document(12) FROM s;
  37. }
  38. do_execsql_test 1.1 {
  39. INSERT INTO ft(ft) VALUES('optimize');
  40. }
  41. do_execsql_test 1.2 {
  42. SELECT level, segment, nentry, nentrytombstone FROM fts5_structure((
  43. SELECT block FROM ft_data WHERE id=10
  44. ))
  45. } {0 0 1000 0}
  46. do_execsql_test 1.3 {
  47. DELETE FROM ft WHERE rowid < 50
  48. }
  49. do_execsql_test 1.4 {
  50. SELECT level, segment, nentry, nentrytombstone FROM fts5_structure((
  51. SELECT block FROM ft_data WHERE id=10
  52. ))
  53. } {0 0 1000 49}
  54. do_execsql_test 1.5 {
  55. DELETE FROM ft WHERE rowid < 1000
  56. }
  57. do_execsql_test 1.6 {
  58. SELECT level, segment, nentry, nentrytombstone FROM fts5_structure((
  59. SELECT block FROM ft_data WHERE id=10
  60. ))
  61. } {1 0 1 0}
  62. #--------------------------------------------------------------------------
  63. reset_db
  64. db func document document
  65. do_execsql_test 2.0 {
  66. CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
  67. }
  68. do_test 2.1 {
  69. for {set ii 0} {$ii < 5000} {incr ii} {
  70. execsql { INSERT INTO ft VALUES( document(12) ) }
  71. }
  72. } {}
  73. do_execsql_test 2.2 {
  74. SELECT sum(nentry) - sum(nentrytombstone) FROM fts5_structure((
  75. SELECT block FROM ft_data WHERE id=10
  76. ))
  77. } {5000}
  78. for {set ii 5000} {$ii >= 0} {incr ii -100} {
  79. do_execsql_test 2.3.$ii {
  80. DELETE FROM ft WHERE rowid > $ii
  81. }
  82. do_execsql_test 2.3.$ii.2 {
  83. SELECT
  84. CAST((total(nentry) - total(nentrytombstone)) AS integer)
  85. FROM
  86. fts5_structure( (SELECT block FROM ft_data WHERE id=10) )
  87. } $ii
  88. }
  89. execsql_pp {
  90. SELECT * FROM fts5_structure((
  91. SELECT block FROM ft_data WHERE id=10
  92. ))
  93. }
  94. do_test 2.4 {
  95. for {set ii 0} {$ii < 5000} {incr ii} {
  96. execsql { INSERT INTO ft VALUES( document(12) ) }
  97. }
  98. } {}
  99. for {set ii 1} {$ii <= 5000} {incr ii 10} {
  100. do_execsql_test 2.3.$ii {
  101. DELETE FROM ft WHERE rowid = $ii;
  102. INSERT INTO ft VALUES( document(12) );
  103. INSERT INTO ft(ft, rank) VALUES('merge', -10);
  104. }
  105. do_execsql_test 2.3.$ii.2 {
  106. SELECT
  107. CAST((total(nentry) - total(nentrytombstone)) AS integer)
  108. FROM
  109. fts5_structure( (SELECT block FROM ft_data WHERE id=10) )
  110. } 5000
  111. }
  112. #-------------------------------------------------------------------------
  113. reset_db
  114. db func document document
  115. do_execsql_test 3.0 {
  116. CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
  117. WITH s(i) AS (
  118. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
  119. )
  120. INSERT INTO ft SELECT document(12) FROM s;
  121. }
  122. do_catchsql_test 3.1 {
  123. INSERT INTO ft(ft, rank) VALUES('deletemerge', 'text');
  124. } {1 {SQL logic error}}
  125. do_catchsql_test 3.2 {
  126. INSERT INTO ft(ft, rank) VALUES('deletemerge', 50);
  127. } {0 {}}
  128. do_execsql_test 3.3 {
  129. SELECT * FROM ft_config WHERE k='deletemerge'
  130. } {deletemerge 50}
  131. do_catchsql_test 3.4 {
  132. INSERT INTO ft(ft, rank) VALUES('deletemerge', 101);
  133. } {0 {}}
  134. do_execsql_test 3.5 {
  135. SELECT * FROM ft_config WHERE k='deletemerge'
  136. } {deletemerge 101}
  137. do_execsql_test 3.6 {
  138. DELETE FROM ft WHERE rowid<95
  139. }
  140. do_execsql_test 3.7 {
  141. SELECT nentrytombstone, nentry FROM fts5_structure((
  142. SELECT block FROM ft_data WHERE id=10
  143. ))
  144. } {94 100}
  145. do_execsql_test 3.8 {
  146. DELETE FROM ft WHERE rowid=95
  147. }
  148. do_execsql_test 3.9 {
  149. SELECT nentrytombstone, nentry FROM fts5_structure((
  150. SELECT block FROM ft_data WHERE id=10
  151. ))
  152. } {95 100}
  153. do_execsql_test 3.10 {
  154. DELETE FROM ft;
  155. WITH s(i) AS (
  156. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
  157. )
  158. INSERT INTO ft SELECT document(12) FROM s;
  159. INSERT INTO ft(ft, rank) VALUES('deletemerge', 50);
  160. }
  161. do_execsql_test 3.11 {
  162. DELETE FROM ft WHERE rowid<95
  163. }
  164. do_execsql_test 3.12 {
  165. SELECT nentrytombstone, nentry FROM fts5_structure((
  166. SELECT block FROM ft_data WHERE id=10
  167. ))
  168. } {0 6}
  169. #-------------------------------------------------------------------------
  170. reset_db
  171. db func document document
  172. do_execsql_test 4.0 {
  173. CREATE VIRTUAL TABLE x1 USING fts5(x, content='', contentless_delete=1);
  174. INSERT INTO x1(x1, rank) VALUES('usermerge', 16);
  175. INSERT INTO x1(x1, rank) VALUES('deletemerge', 40);
  176. INSERT INTO x1 VALUES('one');
  177. INSERT INTO x1 VALUES('two');
  178. INSERT INTO x1 VALUES('three');
  179. INSERT INTO x1 VALUES('four');
  180. INSERT INTO x1 VALUES('five');
  181. INSERT INTO x1 VALUES('six');
  182. INSERT INTO x1 VALUES('seven');
  183. INSERT INTO x1 VALUES('eight');
  184. INSERT INTO x1 VALUES('nine');
  185. INSERT INTO x1 VALUES('ten');
  186. }
  187. do_execsql_test 4.1 {
  188. SELECT level, segment FROM fts5_structure((
  189. SELECT block FROM x1_data WHERE id=10
  190. ))
  191. } {
  192. 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9
  193. }
  194. for {set ii 1} {$ii < 4} {incr ii} {
  195. do_execsql_test 4.2.$ii {
  196. DELETE FROM x1 WHERE rowid = $ii;
  197. INSERT INTO x1(x1, rank) VALUES('merge', 5);
  198. SELECT level, segment FROM fts5_structure((
  199. SELECT block FROM x1_data WHERE id=10
  200. ))
  201. } {
  202. 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9
  203. }
  204. }
  205. do_execsql_test 4.3 {
  206. DELETE FROM x1 WHERE rowid = $ii;
  207. INSERT INTO x1(x1, rank) VALUES('merge', 5);
  208. SELECT level, segment, nentry FROM fts5_structure((
  209. SELECT block FROM x1_data WHERE id=10
  210. ))
  211. } {
  212. 1 0 6
  213. }
  214. finish_test