| OLD | NEW |
| 1 # 2005 July 22 | 1 # 2005 July 22 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 CREATE INDEX stat1idx ON sqlite_stat1(idx); | 66 CREATE INDEX stat1idx ON sqlite_stat1(idx); |
| 67 } | 67 } |
| 68 } {1 {table sqlite_stat1 may not be indexed}} | 68 } {1 {table sqlite_stat1 may not be indexed}} |
| 69 do_test analyze-1.6.3 { | 69 do_test analyze-1.6.3 { |
| 70 catchsql { | 70 catchsql { |
| 71 CREATE INDEX main.stat1idx ON SQLite_stat1(idx); | 71 CREATE INDEX main.stat1idx ON SQLite_stat1(idx); |
| 72 } | 72 } |
| 73 } {1 {table sqlite_stat1 may not be indexed}} | 73 } {1 {table sqlite_stat1 may not be indexed}} |
| 74 do_test analyze-1.7 { | 74 do_test analyze-1.7 { |
| 75 execsql { | 75 execsql { |
| 76 SELECT * FROM sqlite_stat1 | 76 SELECT * FROM sqlite_stat1 WHERE idx NOT NULL |
| 77 } | 77 } |
| 78 } {} | 78 } {} |
| 79 do_test analyze-1.8 { | 79 do_test analyze-1.8 { |
| 80 catchsql { | 80 catchsql { |
| 81 ANALYZE main | 81 ANALYZE main |
| 82 } | 82 } |
| 83 } {0 {}} | 83 } {0 {}} |
| 84 do_test analyze-1.9 { | 84 do_test analyze-1.9 { |
| 85 execsql { | 85 execsql { |
| 86 SELECT * FROM sqlite_stat1 | 86 SELECT * FROM sqlite_stat1 WHERE idx NOT NULL |
| 87 } | 87 } |
| 88 } {} | 88 } {} |
| 89 do_test analyze-1.10 { | 89 do_test analyze-1.10 { |
| 90 catchsql { | 90 catchsql { |
| 91 CREATE TABLE t1(a,b); | 91 CREATE TABLE t1(a,b); |
| 92 ANALYZE main.t1; | 92 ANALYZE main.t1; |
| 93 } | 93 } |
| 94 } {0 {}} | 94 } {0 {}} |
| 95 do_test analyze-1.11 { | 95 do_test analyze-1.11 { |
| 96 execsql { | 96 execsql { |
| 97 SELECT * FROM sqlite_stat1 | 97 SELECT * FROM sqlite_stat1 |
| 98 } | 98 } |
| 99 } {} | 99 } {t1 {} 0} |
| 100 do_test analyze-1.12 { | 100 do_test analyze-1.12 { |
| 101 catchsql { | 101 catchsql { |
| 102 ANALYZE t1; | 102 ANALYZE t1; |
| 103 } | 103 } |
| 104 } {0 {}} | 104 } {0 {}} |
| 105 do_test analyze-1.13 { | 105 do_test analyze-1.13 { |
| 106 execsql { | 106 execsql { |
| 107 SELECT * FROM sqlite_stat1 | 107 SELECT * FROM sqlite_stat1 |
| 108 } | 108 } |
| 109 } {} | 109 } {t1 {} 0} |
| 110 | 110 |
| 111 # Create some indices that can be analyzed. But do not yet add | 111 # Create some indices that can be analyzed. But do not yet add |
| 112 # data. Without data in the tables, no analysis is done. | 112 # data. Without data in the tables, no analysis is done. |
| 113 # | 113 # |
| 114 do_test analyze-2.1 { | 114 do_test analyze-2.1 { |
| 115 execsql { | 115 execsql { |
| 116 CREATE INDEX t1i1 ON t1(a); | 116 CREATE INDEX t1i1 ON t1(a); |
| 117 ANALYZE main.t1; | 117 ANALYZE main.t1; |
| 118 SELECT * FROM sqlite_stat1 ORDER BY idx; | 118 SELECT * FROM sqlite_stat1 ORDER BY idx; |
| 119 } | 119 } |
| 120 } {} | 120 } {t1 {} 0} |
| 121 do_test analyze-2.2 { | 121 do_test analyze-2.2 { |
| 122 execsql { | 122 execsql { |
| 123 CREATE INDEX t1i2 ON t1(b); | 123 CREATE INDEX t1i2 ON t1(b); |
| 124 ANALYZE t1; | 124 ANALYZE t1; |
| 125 SELECT * FROM sqlite_stat1 ORDER BY idx; | 125 SELECT * FROM sqlite_stat1 ORDER BY idx; |
| 126 } | 126 } |
| 127 } {} | 127 } {t1 {} 0} |
| 128 do_test analyze-2.3 { | 128 do_test analyze-2.3 { |
| 129 execsql { | 129 execsql { |
| 130 CREATE INDEX t1i3 ON t1(a,b); | 130 CREATE INDEX t1i3 ON t1(a,b); |
| 131 ANALYZE main; | 131 ANALYZE main; |
| 132 SELECT * FROM sqlite_stat1 ORDER BY idx; | 132 SELECT * FROM sqlite_stat1 ORDER BY idx; |
| 133 } | 133 } |
| 134 } {} | 134 } {t1 {} 0} |
| 135 | 135 |
| 136 # Start adding data to the table. Verify that the analysis | 136 # Start adding data to the table. Verify that the analysis |
| 137 # is done correctly. | 137 # is done correctly. |
| 138 # | 138 # |
| 139 do_test analyze-3.1 { | 139 do_test analyze-3.1 { |
| 140 execsql { | 140 execsql { |
| 141 INSERT INTO t1 VALUES(1,2); | 141 INSERT INTO t1 VALUES(1,2); |
| 142 INSERT INTO t1 VALUES(1,3); | 142 INSERT INTO t1 VALUES(1,3); |
| 143 ANALYZE main.t1; | 143 ANALYZE main.t1; |
| 144 SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; | 144 SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 # This test corrupts the database file so it must be the last test | 290 # This test corrupts the database file so it must be the last test |
| 291 # in the series. | 291 # in the series. |
| 292 # | 292 # |
| 293 do_test analyze-99.1 { | 293 do_test analyze-99.1 { |
| 294 execsql { | 294 execsql { |
| 295 PRAGMA writable_schema=on; | 295 PRAGMA writable_schema=on; |
| 296 UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1'; | 296 UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1'; |
| 297 } | 297 } |
| 298 db close | 298 db close |
| 299 sqlite3 db test.db | 299 catch { sqlite3 db test.db } |
| 300 catchsql { | 300 catchsql { |
| 301 ANALYZE | 301 ANALYZE |
| 302 } | 302 } |
| 303 } {1 {malformed database schema (sqlite_stat1) - near "nonsense": syntax error}} | 303 } {1 {malformed database schema (sqlite_stat1) - near "nonsense": syntax error}} |
| 304 | 304 |
| 305 | 305 |
| 306 finish_test | 306 finish_test |
| OLD | NEW |