fts5fault2.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # 2014 June 17
  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 is focused on OOM errors.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. source $testdir/malloc_common.tcl
  16. set testprefix fts5fault2
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. set doc [string trim [string repeat "x y z " 200]]
  23. do_execsql_test 1.0 {
  24. CREATE TABLE t1(a INTEGER PRIMARY KEY, x);
  25. CREATE VIRTUAL TABLE x1 USING fts5(x, content='t1', content_rowid='a');
  26. INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
  27. WITH input(a,b) AS (
  28. SELECT 1, $doc UNION ALL
  29. SELECT a+1, ($doc || CASE WHEN (a+1)%100 THEN '' ELSE ' xyz' END)
  30. FROM input WHERE a < 1000
  31. )
  32. INSERT INTO t1 SELECT * FROM input;
  33. INSERT INTO x1(x1) VALUES('rebuild');
  34. }
  35. do_faultsim_test 1.1 -faults oom-* -prep {
  36. } -body {
  37. execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z AND xyz' }
  38. } -test {
  39. faultsim_test_result {0 {100 200 300 400 500 600 700 800 900 1000}}
  40. }
  41. do_faultsim_test 1.2 -faults oom-* -prep {
  42. } -body {
  43. execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z + xyz' ORDER BY 1 DESC}
  44. } -test {
  45. faultsim_test_result {0 {1000 900 800 700 600 500 400 300 200 100}}
  46. }
  47. #-------------------------------------------------------------------------
  48. # OOM within a query that accesses the in-memory hash table.
  49. #
  50. reset_db
  51. do_execsql_test 2.0 {
  52. CREATE VIRTUAL TABLE "a b c" USING fts5(a, b, c);
  53. INSERT INTO "a b c" VALUES('one two', 'x x x', 'three four');
  54. INSERT INTO "a b c" VALUES('nine ten', 'y y y', 'two two');
  55. }
  56. do_faultsim_test 2.1 -faults oom-trans* -prep {
  57. execsql {
  58. BEGIN;
  59. INSERT INTO "a b c" VALUES('one one', 'z z z', 'nine ten');
  60. }
  61. } -body {
  62. execsql { SELECT rowid FROM "a b c" WHERE "a b c" MATCH 'one' }
  63. } -test {
  64. faultsim_test_result {0 {1 3}}
  65. catchsql { ROLLBACK }
  66. }
  67. #-------------------------------------------------------------------------
  68. # OOM within an 'optimize' operation that writes multiple pages to disk.
  69. #
  70. reset_db
  71. do_execsql_test 3.0 {
  72. CREATE VIRTUAL TABLE zzz USING fts5(z);
  73. INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
  74. INSERT INTO zzz VALUES('a b c d');
  75. INSERT INTO zzz SELECT 'c d e f' FROM zzz;
  76. INSERT INTO zzz SELECT 'e f g h' FROM zzz;
  77. INSERT INTO zzz SELECT 'i j k l' FROM zzz;
  78. INSERT INTO zzz SELECT 'l k m n' FROM zzz;
  79. INSERT INTO zzz SELECT 'o p q r' FROM zzz;
  80. }
  81. faultsim_save_and_close
  82. do_faultsim_test 3.1 -faults oom-trans* -prep {
  83. faultsim_restore_and_reopen
  84. execsql { SELECT rowid FROM zzz }
  85. } -body {
  86. execsql { INSERT INTO zzz(zzz) VALUES('optimize') }
  87. } -test {
  88. faultsim_test_result {0 {}}
  89. }
  90. #-------------------------------------------------------------------------
  91. # OOM within an 'integrity-check' operation.
  92. #
  93. reset_db
  94. db func rnddoc fts5_rnddoc
  95. do_execsql_test 4.0 {
  96. CREATE VIRTUAL TABLE zzz USING fts5(z);
  97. INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
  98. WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<10)
  99. INSERT INTO zzz SELECT rnddoc(10) || ' xccc' FROM ii;
  100. }
  101. do_faultsim_test 4.1 -faults oom-trans* -prep {
  102. } -body {
  103. execsql { INSERT INTO zzz(zzz) VALUES('integrity-check') }
  104. } -test {
  105. faultsim_test_result {0 {}}
  106. }
  107. #-------------------------------------------------------------------------
  108. # OOM while parsing a tokenize=option
  109. #
  110. reset_db
  111. faultsim_save_and_close
  112. do_faultsim_test 5.0 -faults oom-* -prep {
  113. faultsim_restore_and_reopen
  114. } -body {
  115. execsql {
  116. CREATE VIRTUAL TABLE uio USING fts5(a, b,
  117. tokenize="porter 'ascii'",
  118. content="another table",
  119. content_rowid="somecolumn"
  120. );
  121. }
  122. } -test {
  123. faultsim_test_result {0 {}}
  124. }
  125. finish_test