OLD | NEW |
1 # 2009 August 06 | 1 # 2009 August 06 |
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 #*********************************************************************** |
11 # | 11 # |
12 # This file implements regression tests for SQLite library. This file | 12 # This file implements regression tests for SQLite library. This file |
13 # implements tests for the extra functionality provided by the ANALYZE | 13 # implements tests for the extra functionality provided by the ANALYZE |
14 # command when the library is compiled with SQLITE_ENABLE_STAT2 defined. | 14 # command when the library is compiled with SQLITE_ENABLE_STAT2 defined. |
15 # | 15 # |
16 | 16 |
17 set testdir [file dirname $argv0] | 17 set testdir [file dirname $argv0] |
18 source $testdir/tester.tcl | 18 source $testdir/tester.tcl |
19 | 19 |
20 ifcapable !stat2 { | 20 ifcapable !stat2 { |
21 finish_test | 21 finish_test |
22 return | 22 return |
23 } | 23 } |
24 | 24 |
| 25 # Do not use a codec for tests in this file, as the database file is |
| 26 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 27 # |
| 28 do_not_use_codec |
| 29 |
25 #-------------------------------------------------------------------- | 30 #-------------------------------------------------------------------- |
26 # Test organization: | 31 # Test organization: |
27 # | 32 # |
28 # analyze2-1.*: Tests to verify that ANALYZE creates and populates the | 33 # analyze2-1.*: Tests to verify that ANALYZE creates and populates the |
29 # sqlite_stat2 table as expected. | 34 # sqlite_stat2 table as expected. |
30 # | 35 # |
31 # analyze2-2.*: Test that when a table has two indexes on it and either | 36 # analyze2-2.*: Test that when a table has two indexes on it and either |
32 # index may be used for the scan, the index suggested by | 37 # index may be used for the scan, the index suggested by |
33 # the contents of sqlite_stat2 table is prefered. | 38 # the contents of sqlite_stat2 table is prefered. |
34 # | 39 # |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 225 } |
221 } {t3 t3b {AbA CIj EIj GIj IIj bIj dIj fIj hIj jIj}} | 226 } {t3 t3b {AbA CIj EIj GIj IIj bIj dIj fIj hIj jIj}} |
222 | 227 |
223 do_test analyze2-4.4 { | 228 do_test analyze2-4.4 { |
224 eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'C' AND b > 'A' AND b < 'C'" | 229 eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'C' AND b > 'A' AND b < 'C'" |
225 } {0 0 {TABLE t3 WITH INDEX t3b}} | 230 } {0 0 {TABLE t3 WITH INDEX t3b}} |
226 do_test analyze2-4.5 { | 231 do_test analyze2-4.5 { |
227 eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'c' AND b > 'A' AND b < 'c'" | 232 eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'c' AND b > 'A' AND b < 'c'" |
228 } {0 0 {TABLE t3 WITH INDEX t3a}} | 233 } {0 0 {TABLE t3 WITH INDEX t3a}} |
229 | 234 |
230 proc test_collate {enc lhs rhs} { | 235 ifcapable utf16 { |
231 # puts $enc | 236 proc test_collate {enc lhs rhs} { |
232 return [string compare $lhs $rhs] | 237 # puts $enc |
| 238 return [string compare $lhs $rhs] |
| 239 } |
| 240 do_test analyze2-5.1 { |
| 241 add_test_collate db 0 0 1 |
| 242 execsql { CREATE TABLE t4(x COLLATE test_collate) } |
| 243 execsql { CREATE INDEX t4x ON t4(x) } |
| 244 set alphabet [list a b c d e f g h i j] |
| 245 execsql BEGIN |
| 246 for {set i 0} {$i < 1000} {incr i} { |
| 247 set str [lindex $alphabet [expr ($i/100)%10]] |
| 248 append str [lindex $alphabet [expr ($i/ 10)%10]] |
| 249 append str [lindex $alphabet [expr ($i/ 1)%10]] |
| 250 execsql { INSERT INTO t4 VALUES($str) } |
| 251 } |
| 252 execsql COMMIT |
| 253 execsql ANALYZE |
| 254 } {} |
| 255 do_test analyze2-5.2 { |
| 256 execsql { |
| 257 SELECT tbl,idx,group_concat(sample,' ') |
| 258 FROM sqlite_stat2 |
| 259 WHERE tbl = 't4' |
| 260 GROUP BY tbl,idx |
| 261 } |
| 262 } {t4 t4x {afa bej cej dej eej fej gej hej iej jej}} |
| 263 do_test analyze2-5.3 { |
| 264 eqp "SELECT * FROM t4 WHERE x>'ccc'" |
| 265 } {0 0 {TABLE t4 WITH INDEX t4x}} |
| 266 do_test analyze2-5.4 { |
| 267 eqp "SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ccc' AND t42.x>'ggg'" |
| 268 } {0 1 {TABLE t4 AS t42 WITH INDEX t4x} 1 0 {TABLE t4 AS t41 WITH INDEX t4x}} |
| 269 do_test analyze2-5.5 { |
| 270 eqp "SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ddd' AND t42.x>'ccc'" |
| 271 } {0 0 {TABLE t4 AS t41 WITH INDEX t4x} 1 1 {TABLE t4 AS t42 WITH INDEX t4x}} |
233 } | 272 } |
234 do_test analyze2-5.1 { | |
235 add_test_collate db 0 0 1 | |
236 execsql { CREATE TABLE t4(x COLLATE test_collate) } | |
237 execsql { CREATE INDEX t4x ON t4(x) } | |
238 set alphabet [list a b c d e f g h i j] | |
239 execsql BEGIN | |
240 for {set i 0} {$i < 1000} {incr i} { | |
241 set str [lindex $alphabet [expr ($i/100)%10]] | |
242 append str [lindex $alphabet [expr ($i/ 10)%10]] | |
243 append str [lindex $alphabet [expr ($i/ 1)%10]] | |
244 execsql { INSERT INTO t4 VALUES($str) } | |
245 } | |
246 execsql COMMIT | |
247 execsql ANALYZE | |
248 } {} | |
249 do_test analyze2-5.2 { | |
250 execsql { | |
251 SELECT tbl,idx,group_concat(sample,' ') | |
252 FROM sqlite_stat2 | |
253 WHERE tbl = 't4' | |
254 GROUP BY tbl,idx | |
255 } | |
256 } {t4 t4x {afa bej cej dej eej fej gej hej iej jej}} | |
257 do_test analyze2-5.3 { | |
258 eqp "SELECT * FROM t4 WHERE x>'ccc'" | |
259 } {0 0 {TABLE t4 WITH INDEX t4x}} | |
260 do_test analyze2-5.4 { | |
261 eqp "SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ccc' AND t42.x>'ggg'" | |
262 } {0 1 {TABLE t4 AS t42 WITH INDEX t4x} 1 0 {TABLE t4 AS t41 WITH INDEX t4x}} | |
263 do_test analyze2-5.5 { | |
264 eqp "SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ddd' AND t42.x>'ccc'" | |
265 } {0 0 {TABLE t4 AS t41 WITH INDEX t4x} 1 1 {TABLE t4 AS t42 WITH INDEX t4x}} | |
266 | 273 |
267 #-------------------------------------------------------------------- | 274 #-------------------------------------------------------------------- |
268 # These tests, analyze2-6.*, verify that the library behaves correctly | 275 # These tests, analyze2-6.*, verify that the library behaves correctly |
269 # when one of the sqlite_stat1 and sqlite_stat2 tables is missing. | 276 # when one of the sqlite_stat1 and sqlite_stat2 tables is missing. |
270 # | 277 # |
271 # If the sqlite_stat1 table is not present, then the sqlite_stat2 | 278 # If the sqlite_stat1 table is not present, then the sqlite_stat2 |
272 # table is not read. However, if it is the sqlite_stat2 table that | 279 # table is not read. However, if it is the sqlite_stat2 table that |
273 # is missing, the data in the sqlite_stat1 table is still used. | 280 # is missing, the data in the sqlite_stat1 table is still used. |
274 # | 281 # |
275 # Tests analyze2-6.1.* test the libary when the sqlite_stat2 table | 282 # Tests analyze2-6.1.* test the libary when the sqlite_stat2 table |
276 # is missing. Tests analyze2-6.2.* test the library when sqlite_stat1 | 283 # is missing. Tests analyze2-6.2.* test the library when sqlite_stat1 |
277 # is not present. | 284 # is not present. |
278 # | 285 # |
279 do_test analyze2-6.0 { | 286 do_test analyze2-6.0 { |
280 execsql { | 287 execsql { |
281 DROP TABLE t4; | 288 DROP TABLE IF EXISTS t4; |
282 CREATE TABLE t5(a, b); CREATE INDEX t5i ON t5(a, b); | 289 CREATE TABLE t5(a, b); CREATE INDEX t5i ON t5(a, b); |
283 CREATE TABLE t6(a, b); CREATE INDEX t6i ON t6(a, b); | 290 CREATE TABLE t6(a, b); CREATE INDEX t6i ON t6(a, b); |
284 } | 291 } |
285 for {set ii 0} {$ii < 20} {incr ii} { | 292 for {set ii 0} {$ii < 20} {incr ii} { |
286 execsql { | 293 execsql { |
287 INSERT INTO t5 VALUES($ii, $ii); | 294 INSERT INTO t5 VALUES($ii, $ii); |
288 INSERT INTO t6 VALUES($ii/10, $ii/10); | 295 INSERT INTO t6 VALUES($ii/10, $ii/10); |
289 } | 296 } |
290 } | 297 } |
291 execsql { | 298 execsql { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 t6.a>1 | 501 t6.a>1 |
495 } db1 | 502 } db1 |
496 } {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}} | 503 } {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}} |
497 | 504 |
498 db1 close | 505 db1 close |
499 db2 close | 506 db2 close |
500 sqlite3_enable_shared_cache $::enable_shared_cache | 507 sqlite3_enable_shared_cache $::enable_shared_cache |
501 } | 508 } |
502 | 509 |
503 finish_test | 510 finish_test |
OLD | NEW |