fts5restart.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # 2015 April 28
  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 focuses on testing the planner (xBestIndex function).
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5restart
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. do_execsql_test 1.0 {
  22. CREATE VIRTUAL TABLE f1 USING fts5(ff);
  23. }
  24. #-------------------------------------------------------------------------
  25. # Run the 'optimize' command. Check that it does not disturb ongoing
  26. # full-text queries.
  27. #
  28. unset -nocomplain lRowid
  29. do_test 1.1 {
  30. for {set i 1} {$i < 1000} {incr i} {
  31. execsql { INSERT INTO f1 VALUES('a b c d e') }
  32. lappend lRowid $i
  33. }
  34. } {}
  35. do_execsql_test 1.2 {
  36. SELECT rowid FROM f1 WHERE f1 MATCH 'c';
  37. } $lRowid
  38. do_test 1.3 {
  39. set res [list]
  40. db eval { SELECT rowid FROM f1 WHERE f1 MATCH 'c' } {
  41. if {$rowid == 100} {
  42. execsql { INSERT INTO f1(f1) VALUES('optimize') }
  43. }
  44. lappend res $rowid
  45. }
  46. set res
  47. } $lRowid
  48. do_test 1.4.1 {
  49. sqlite3 db2 test.db
  50. set res [list]
  51. db2 eval { SELECT rowid FROM f1 WHERE f1 MATCH 'c' } {
  52. if {$rowid == 100} {
  53. set cres [catchsql { INSERT INTO f1(f1) VALUES('optimize') }]
  54. }
  55. lappend res $rowid
  56. }
  57. set res
  58. } $lRowid
  59. do_test 1.4.2 {
  60. db2 close
  61. set cres
  62. } {1 {database is locked}}
  63. #-------------------------------------------------------------------------
  64. # Open a couple of cursors. Then close them in the same order.
  65. #
  66. do_test 2.1 {
  67. set ::s1 [sqlite3_prepare db "SELECT rowid FROM f1 WHERE f1 MATCH 'b'" -1 X]
  68. set ::s2 [sqlite3_prepare db "SELECT rowid FROM f1 WHERE f1 MATCH 'c'" -1 X]
  69. sqlite3_step $::s1
  70. } {SQLITE_ROW}
  71. do_test 2.2 {
  72. sqlite3_step $::s2
  73. } {SQLITE_ROW}
  74. do_test 2.1 {
  75. sqlite3_finalize $::s1
  76. sqlite3_finalize $::s2
  77. } {SQLITE_OK}
  78. #-------------------------------------------------------------------------
  79. # Copy data between two FTS5 tables.
  80. #
  81. do_execsql_test 3.1 {
  82. CREATE VIRTUAL TABLE f2 USING fts5(gg);
  83. INSERT INTO f2 SELECT ff FROM f1 WHERE f1 MATCH 'b+c+d';
  84. }
  85. do_execsql_test 3.2 {
  86. SELECT rowid FROM f2 WHERE f2 MATCH 'a+b+c+d+e'
  87. } $lRowid
  88. #-------------------------------------------------------------------------
  89. # Remove the row that an FTS5 cursor is currently pointing to. And
  90. # various other similar things. Check that this does not disturb
  91. # ongoing scans.
  92. #
  93. do_execsql_test 4.0 {
  94. CREATE VIRTUAL TABLE n4 USING fts5(n);
  95. INSERT INTO n4(rowid, n) VALUES(100, '1 2 3 4 5');
  96. INSERT INTO n4(rowid, n) VALUES(200, '1 2 3 4');
  97. INSERT INTO n4(rowid, n) VALUES(300, '2 3 4');
  98. INSERT INTO n4(rowid, n) VALUES(400, '2 3');
  99. INSERT INTO n4(rowid, n) VALUES(500, '3');
  100. }
  101. do_test 4.1 {
  102. set res [list]
  103. db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' } {
  104. if {$rowid==300} {
  105. execsql { DELETE FROM n4 WHERE rowid=300 }
  106. }
  107. lappend res $rowid
  108. }
  109. set res
  110. } {100 200 300 400 500}
  111. do_test 4.2 {
  112. execsql { INSERT INTO n4(rowid, n) VALUES(300, '2 3 4') }
  113. set res [list]
  114. db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' ORDER BY rowid DESC} {
  115. if {$rowid==300} {
  116. execsql { DELETE FROM n4 WHERE rowid=300 }
  117. }
  118. lappend res $rowid
  119. }
  120. set res
  121. } {500 400 300 200 100}
  122. do_test 4.3 {
  123. execsql { INSERT INTO n4(rowid, n) VALUES(300, '2 3 4') }
  124. set res [list]
  125. db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' ORDER BY rowid DESC} {
  126. if {$rowid==300} {
  127. execsql { DELETE FROM n4 }
  128. }
  129. lappend res $rowid
  130. }
  131. set res
  132. } {500 400 300}
  133. finish_test