3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
12 # This file is focused on OOM errors.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 source $testdir/malloc_common.tcl
17 set testprefix fts5fault2
19 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
25 set doc [string trim [string repeat "x y z " 200]]
27 CREATE TABLE t1(a INTEGER PRIMARY KEY, x);
28 CREATE VIRTUAL TABLE x1 USING fts5(x, content='t1', content_rowid='a');
29 INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
31 SELECT 1, $doc UNION ALL
32 SELECT a+1, ($doc || CASE WHEN (a+1)%100 THEN '' ELSE ' xyz' END)
33 FROM input WHERE a < 1000
35 INSERT INTO t1 SELECT * FROM input;
37 INSERT INTO x1(x1) VALUES('rebuild');
40 do_faultsim_test 1.1 -faults oom-* -prep {
42 execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z AND xyz' }
44 faultsim_test_result {0 {100 200 300 400 500 600 700 800 900 1000}}
47 do_faultsim_test 1.2 -faults oom-* -prep {
49 execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z + xyz' ORDER BY 1 DESC}
51 faultsim_test_result {0 {1000 900 800 700 600 500 400 300 200 100}}
54 #-------------------------------------------------------------------------
55 # OOM within a query that accesses the in-memory hash table.
59 CREATE VIRTUAL TABLE "a b c" USING fts5(a, b, c);
60 INSERT INTO "a b c" VALUES('one two', 'x x x', 'three four');
61 INSERT INTO "a b c" VALUES('nine ten', 'y y y', 'two two');
64 do_faultsim_test 2.1 -faults oom-trans* -prep {
67 INSERT INTO "a b c" VALUES('one one', 'z z z', 'nine ten');
70 execsql { SELECT rowid FROM "a b c" WHERE "a b c" MATCH 'one' }
72 faultsim_test_result {0 {1 3}}
76 #-------------------------------------------------------------------------
77 # OOM within an 'optimize' operation that writes multiple pages to disk.
81 CREATE VIRTUAL TABLE zzz USING fts5(z);
82 INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
83 INSERT INTO zzz VALUES('a b c d');
84 INSERT INTO zzz SELECT 'c d e f' FROM zzz;
85 INSERT INTO zzz SELECT 'e f g h' FROM zzz;
86 INSERT INTO zzz SELECT 'i j k l' FROM zzz;
87 INSERT INTO zzz SELECT 'l k m n' FROM zzz;
88 INSERT INTO zzz SELECT 'o p q r' FROM zzz;
90 faultsim_save_and_close
92 do_faultsim_test 3.1 -faults oom-trans* -prep {
93 faultsim_restore_and_reopen
94 execsql { SELECT rowid FROM zzz }
96 execsql { INSERT INTO zzz(zzz) VALUES('optimize') }
98 faultsim_test_result {0 {}}
101 #-------------------------------------------------------------------------
102 # OOM within an 'integrity-check' operation.
105 db func rnddoc fts5_rnddoc
106 do_execsql_test 4.0 {
107 CREATE VIRTUAL TABLE zzz USING fts5(z);
108 INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
109 WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<10)
110 INSERT INTO zzz SELECT rnddoc(10) || ' xccc' FROM ii;
113 do_faultsim_test 4.1 -faults oom-trans* -prep {
115 execsql { INSERT INTO zzz(zzz) VALUES('integrity-check') }
117 faultsim_test_result {0 {}}
120 #-------------------------------------------------------------------------
121 # OOM while parsing a tokenize=option
124 faultsim_save_and_close
125 do_faultsim_test 5.0 -faults oom-* -prep {
126 faultsim_restore_and_reopen
129 CREATE VIRTUAL TABLE uio USING fts5(a, b,
130 tokenize="porter 'ascii'",
131 content="another table",
132 content_rowid="somecolumn"
136 faultsim_test_result {0 {}}