1# 2018 January 12 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 13if {![info exists testdir]} { 14 set testdir [file join [file dirname [info script]] .. .. test] 15} 16source [file join [file dirname [info script]] session_common.tcl] 17source $testdir/tester.tcl 18ifcapable !session {finish_test; return} 19 20set testprefix sessionstat1 21 22do_execsql_test 1.0 { 23 CREATE TABLE t1(a PRIMARY KEY, b, c); 24 CREATE INDEX t1b ON t1(b); 25 CREATE INDEX t1c ON t1(c); 26 27 WITH s(i) AS ( 28 SELECT 0 UNION ALL SELECT i+1 FROM s WHERE (i+1)<32 29 ) 30 INSERT INTO t1 SELECT i, i%8, i%2 FROM s; 31} 32 33do_iterator_test 1.1 {} { 34 ANALYZE 35} { 36 {INSERT sqlite_stat1 0 XX. {} {t t1 t sqlite_autoindex_t1_1 t {32 1}}} 37 {INSERT sqlite_stat1 0 XX. {} {t t1 t t1b t {32 4}}} 38 {INSERT sqlite_stat1 0 XX. {} {t t1 t t1c t {32 16}}} 39} 40 41do_execsql_test 1.2 { 42 WITH s(i) AS ( 43 SELECT 32 UNION ALL SELECT i+1 FROM s WHERE (i+1)<64 44 ) 45 INSERT INTO t1 SELECT i, i%8, i%2 FROM s; 46} 47 48do_iterator_test 1.3 {} { 49 ANALYZE 50} { 51 {UPDATE sqlite_stat1 0 XX. {t t1 t sqlite_autoindex_t1_1 t {32 1}} {{} {} {} {} t {64 1}}} 52 {UPDATE sqlite_stat1 0 XX. {t t1 t t1b t {32 4}} {{} {} {} {} t {64 8}}} 53 {UPDATE sqlite_stat1 0 XX. {t t1 t t1c t {32 16}} {{} {} {} {} t {64 32}}} 54} 55 56do_iterator_test 1.5 {} { 57 DROP INDEX t1b; 58} { 59 {DELETE sqlite_stat1 0 XX. {t t1 t t1b t {64 8}} {}} 60} 61 62do_iterator_test 1.6 {} { 63 DROP TABLE t1; 64} { 65 {DELETE sqlite_stat1 0 XX. {t t1 t sqlite_autoindex_t1_1 t {64 1}} {}} 66 {DELETE sqlite_stat1 0 XX. {t t1 t t1c t {64 32}} {}} 67} 68 69#------------------------------------------------------------------------- 70# 71catch { db2 close } 72forcedelete test.db2 73sqlite3 db2 test.db2 74 75do_test 2.0 { 76 do_common_sql { 77 CREATE TABLE t1(a PRIMARY KEY, b, c); 78 CREATE INDEX t1b ON t1(b); 79 CREATE INDEX t1c ON t1(c); 80 ANALYZE; 81 } 82} {} 83 84do_test 2.1 { 85 do_then_apply_sql { 86 WITH s(i) AS ( 87 SELECT 0 UNION ALL SELECT i+1 FROM s WHERE (i+1)<32 88 ) 89 INSERT INTO t1 SELECT i, i%8, i%2 FROM s; 90 ANALYZE; 91 } 92} {} 93 94do_execsql_test -db db2 2.2 { 95 SELECT * FROM sqlite_stat1 96} { 97 t1 sqlite_autoindex_t1_1 {32 1} 98 t1 t1b {32 4} 99 t1 t1c {32 16} 100} 101 102do_test 2.3 { 103 do_then_apply_sql { DROP INDEX t1c } 104} {} 105 106do_execsql_test -db db2 2.4 { 107 SELECT * FROM sqlite_stat1 108} { 109 t1 sqlite_autoindex_t1_1 {32 1} 110 t1 t1b {32 4} 111} 112 113do_test 2.3 { 114 do_then_apply_sql { DROP TABLE t1 } 115} {} 116 117do_execsql_test -db db2 2.4 { 118 SELECT * FROM sqlite_stat1 119} { 120} 121 122do_execsql_test -db db2 2.4 { SELECT count(*) FROM t1 } 32 123 124finish_test 125 126