sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5limits.test
| 1 | # 2023 May 16 |
| 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 | |
| 13 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 14 | set testprefix fts5limits |
| 15 | return_if_no_fts5 |
| 16 | |
| 17 | |
| 18 | do_execsql_test 1.0 { |
| 19 | CREATE VIRTUAL TABLE ft USING fts5(x); |
| 20 | } |
| 21 | |
| 22 | # Default limit for expression depth is 256 |
| 23 | # |
| 24 | foreach {tn nRepeat op bErr} { |
| 25 | 1 200 AND 0 |
| 26 | 2 200 NOT 0 |
| 27 | 3 200 OR 0 |
| 28 | |
| 29 | 4 260 AND 0 |
| 30 | 5 260 NOT 1 |
| 31 | 6 260 OR 0 |
| 32 | } { |
| 33 | set L [string repeat "abc " $nRepeat] |
| 34 | set Q [join $L " $op "] |
| 35 | |
| 36 | set res {0 {}} |
| 37 | if {$bErr} { |
| 38 | set res "1 {fts5 expression tree is too large (maximum depth 256)}" |
| 39 | } |
| 40 | |
| 41 | do_catchsql_test 1.$tn { |
| 42 | SELECT * FROM ft($Q) |
| 43 | } $res |
| 44 | } |
| 45 | |
| 46 | #------------------------------------------------------------------------- |
| 47 | # Test that if a record written to the %_data or %_docsize tables is larger |
| 48 | # than SQLITE_LIMIT_LENGTH, the write fails with SQLITE_TOOBIG. It should not |
| 49 | # succeed and store a NULL in place of the record, corrupting the index. |
| 50 | # |
| 51 | # Report: https://sqlite.org/bugs/forumpost/f712b4e116 |
| 52 | # |
| 53 | set toobig {1 {string or blob too big}} |
| 54 | |
| 55 | # A %_data leaf record that is too large. |
| 56 | # |
| 57 | reset_db |
| 58 | set nLimit [sqlite3_limit db SQLITE_LIMIT_LENGTH -1] |
| 59 | do_execsql_test 2.1.0 { |
| 60 | CREATE VIRTUAL TABLE ft USING fts5(a); |
| 61 | } |
| 62 | sqlite3_limit db SQLITE_LIMIT_LENGTH 100 |
| 63 | do_catchsql_test 2.1.1 { |
| 64 | INSERT INTO ft VALUES('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'); |
| 65 | } $toobig |
| 66 | sqlite3_limit db SQLITE_LIMIT_LENGTH $nLimit |
| 67 | do_execsql_test 2.1.2 { |
| 68 | SELECT count(*) FROM ft_data WHERE block IS NULL; |
| 69 | } {0} |
| 70 | do_execsql_test 2.1.3 { |
| 71 | INSERT INTO ft(ft) VALUES('integrity-check'); |
| 72 | SELECT rowid FROM ft('a'); |
| 73 | } {} |
| 74 | |
| 75 | # The tables used by the following tests have 31 columns, so that both the |
| 76 | # averages record and the %_docsize record are larger than the minimum |
| 77 | # possible value of SQLITE_LIMIT_LENGTH (30). They are contentless, as |
| 78 | # otherwise writing to the %_content table fails. And all values inserted |
| 79 | # are empty, so that no leaf records are written. |
| 80 | # |
| 81 | set cols [list] |
| 82 | set vals [list] |
| 83 | for {set i 0} {$i < 31} {incr i} { |
| 84 | lappend cols c$i |
| 85 | lappend vals "''" |
| 86 | } |
| 87 | set cols [join $cols ,] |
| 88 | set vals [join $vals ,] |
| 89 | |
| 90 | # An averages record that is too large. The columnsize=0 option means that |
| 91 | # there is no %_docsize record to write. |
| 92 | # |
| 93 | reset_db |
| 94 | do_execsql_test 2.2.0 " |
| 95 | CREATE VIRTUAL TABLE ft USING fts5($cols, content='', columnsize=0); |
| 96 | " |
| 97 | sqlite3_limit db SQLITE_LIMIT_LENGTH 30 |
| 98 | do_catchsql_test 2.2.1 " |
| 99 | INSERT INTO ft(rowid, $cols) VALUES(1, $vals); |
| 100 | " $toobig |
| 101 | sqlite3_limit db SQLITE_LIMIT_LENGTH $nLimit |
| 102 | do_execsql_test 2.2.2 { |
| 103 | SELECT count(*) FROM ft_data WHERE block IS NULL; |
| 104 | } {0} |
| 105 | do_execsql_test 2.2.3 { |
| 106 | INSERT INTO ft(ft) VALUES('integrity-check'); |
| 107 | } |
| 108 | |
| 109 | # A %_docsize record that is too large. The %_docsize record is written as |
| 110 | # part of the INSERT statement, but the slightly larger averages record is |
| 111 | # not written until the transaction is committed. So raising the limit before |
| 112 | # the COMMIT means that this tests the %_docsize write only. |
| 113 | # |
| 114 | reset_db |
| 115 | do_execsql_test 2.3.0 " |
| 116 | CREATE VIRTUAL TABLE ft USING fts5($cols, content=''); |
| 117 | BEGIN; |
| 118 | " |
| 119 | sqlite3_limit db SQLITE_LIMIT_LENGTH 30 |
| 120 | do_catchsql_test 2.3.1 " |
| 121 | INSERT INTO ft(rowid, $cols) VALUES(1, $vals); |
| 122 | " $toobig |
| 123 | sqlite3_limit db SQLITE_LIMIT_LENGTH $nLimit |
| 124 | do_execsql_test 2.3.2 { |
| 125 | COMMIT; |
| 126 | SELECT count(*) FROM ft_docsize WHERE sz IS NULL; |
| 127 | } {0} |
| 128 | do_execsql_test 2.3.3 { |
| 129 | INSERT INTO ft(ft) VALUES('integrity-check'); |
| 130 | } |
| 131 | |
| 132 | finish_test |
| 133 |