Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/scanstatus.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / scanstatus.test` 417 lines ยท 11641 bytes Raw Blame History 1 # 2014 November 1 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 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 set testprefix scanstatus 16 17 ifcapable !scanstatus { 18 finish_test 19 return 20 } 21 22 do_execsql_test 1.0 { 23 CREATE TABLE t1(a, b); 24 CREATE TABLE t2(x, y); 25 INSERT INTO t1 VALUES(1, 2); 26 INSERT INTO t1 VALUES(3, 4); 27 INSERT INTO t2 VALUES('a', 'b'); 28 INSERT INTO t2 VALUES('c', 'd'); 29 INSERT INTO t2 VALUES('e', 'f'); 30 } 31 32 proc do_scanstatus_test {tn res} { 33 set stmt [db version -last-stmt-ptr] 34 set idx 0 35 set ret [list] 36 while {1} { 37 set r [sqlite3_stmt_scanstatus $stmt $idx] 38 if {[llength $r]==0} break 39 foreach v {nLoop nVisit nEst zName zExplain} { 40 lappend ret $v [dict get $r $v] 41 } 42 incr idx 43 } 44 45 uplevel [list do_test $tn [list set {} $ret] [list {*}$res]] 46 } 47 48 do_execsql_test 1.1a { SELECT count(*) FROM t1, t2; } 6 49 do_scanstatus_test 1.1b { 50 nLoop 1 nVisit 2 nEst `1048576`.0 zName t1 zExplain {SCAN t1} 51 nLoop 2 nVisit 6 nEst `1048576`.0 zName t2 zExplain {SCAN t2} 52 } 53 54 sqlite3_db_config db STMT_SCANSTATUS 0 55 56 do_execsql_test 1.2a { SELECT count(*) FROM t1, t2; } 6 57 do_scanstatus_test 1.2b { 58 } 59 60 sqlite3_db_config db STMT_SCANSTATUS 1 61 62 do_execsql_test 1.3 { 63 ANALYZE; 64 SELECT count(*) FROM t1, t2; 65 } 6 66 do_scanstatus_test 1.4 { 67 nLoop 1 nVisit 2 nEst 2.0 zName t1 zExplain {SCAN t1} 68 nLoop 2 nVisit 6 nEst 3.0 zName t2 zExplain {SCAN t2} 69 } 70 71 do_execsql_test 1.5 { ANALYZE } 72 do_execsql_test 1.6 { 73 SELECT count(*) FROM t1, t2 WHERE t2.rowid>1; 74 } 4 75 do_scanstatus_test 1.7 { 76 nLoop 1 nVisit 2 nEst 2.0 zName t2 zExplain 77 {SEARCH t2 USING INTEGER PRIMARY KEY (rowid>?)} 78 nLoop 2 nVisit 4 nEst 2.0 zName t1 zExplain {SCAN t1} 79 } 80 81 do_execsql_test 1.8 { 82 SELECT count(*) FROM t1, t2 WHERE t2.rowid>1; 83 } 4 84 85 do_scanstatus_test 1.9 { 86 nLoop 2 nVisit 4 nEst 2.0 zName t2 zExplain 87 {SEARCH t2 USING INTEGER PRIMARY KEY (rowid>?)} 88 nLoop 4 nVisit 8 nEst 2.0 zName t1 zExplain {SCAN t1} 89 } 90 91 do_test 1.9 { 92 sqlite3_stmt_scanstatus_reset [db version -last-stmt-ptr] 93 } {} 94 95 do_scanstatus_test 1.10 { 96 nLoop 0 nVisit 0 nEst 2.0 zName t2 zExplain 97 {SEARCH t2 USING INTEGER PRIMARY KEY (rowid>?)} 98 nLoop 0 nVisit 0 nEst 2.0 zName t1 zExplain {SCAN t1} 99 } 100 101 #------------------------------------------------------------------------- 102 # Try a few different types of scans. 103 # 104 reset_db 105 sqlite3_db_config db STMT_SCANSTATUS 1 106 do_execsql_test 2.1 { 107 CREATE TABLE x1(i INTEGER PRIMARY KEY, j); 108 INSERT INTO x1 VALUES(1, 'one'); 109 INSERT INTO x1 VALUES(2, 'two'); 110 INSERT INTO x1 VALUES(3, 'three'); 111 INSERT INTO x1 VALUES(4, 'four'); 112 CREATE INDEX x1j ON x1(j); 113 114 SELECT * FROM x1 WHERE i=2; 115 } {2 two} 116 117 do_scanstatus_test 2.2 { 118 nLoop 1 nVisit 1 nEst 1.0 zName x1 119 zExplain {SEARCH x1 USING INTEGER PRIMARY KEY (rowid=?)} 120 } 121 122 do_execsql_test 2.3.1 { 123 SELECT * FROM x1 WHERE j='two' 124 } {2 two} 125 do_scanstatus_test 2.3.2 { 126 nLoop 1 nVisit 1 nEst 10.0 zName x1j 127 zExplain {SEARCH x1 USING COVERING INDEX x1j (j=?)} 128 } 129 130 do_execsql_test 2.4.1 { 131 SELECT * FROM x1 WHERE j<'two' 132 } {4 four 1 one 3 three} 133 do_scanstatus_test 2.4.2 { 134 nLoop 1 nVisit 3 nEst 262144.0 zName x1j 135 zExplain {SEARCH x1 USING COVERING INDEX x1j (j='two' 140 } {2 two} 141 do_scanstatus_test 2.5.2 { 142 nLoop 1 nVisit 1 nEst 262144.0 zName x1j 143 zExplain {SEARCH x1 USING COVERING INDEX x1j (j>?)} 144 } 145 146 do_execsql_test 2.6.1 { 147 SELECT * FROM x1 WHERE j BETWEEN 'three' AND 'two' 148 } {3 three 2 two} 149 do_scanstatus_test 2.6.2 { 150 nLoop 1 nVisit 2 nEst 16384.0 zName x1j 151 zExplain {SEARCH x1 USING COVERING INDEX x1j (j>? AND j? AND j? AND a? AND b? AND b? AND a