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/cost.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 / cost.test` 289 lines ยท 6886 bytes Raw Blame History 1 # 2014-04-26 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 cost 16 17 18 do_execsql_test 1.1 { 19 CREATE TABLE t3(id INTEGER PRIMARY KEY, b NOT NULL); 20 CREATE TABLE t4(c, d, e); 21 CREATE UNIQUE INDEX i3 ON t3(b); 22 CREATE UNIQUE INDEX i4 ON t4(c, d); 23 } 24 do_eqp_test 1.2 { 25 SELECT e FROM t3, t4 WHERE b=c ORDER BY b, d; 26 } { 27 QUERY PLAN 28 |--SCAN t3 USING COVERING INDEX i3 29 `--SEARCH t4 USING INDEX i4 (c=?) 30 } 31 32 33 do_execsql_test 2.1 { 34 CREATE TABLE t1(a, b); 35 CREATE INDEX i1 ON t1(a); 36 } 37 38 # It is better to use an index for ORDER BY than sort externally, even 39 # if the index is a non-covering index. 40 do_eqp_test 2.2 { 41 SELECT * FROM t1 ORDER BY a; 42 } {SCAN t1 USING INDEX i1} 43 44 do_execsql_test 3.1 { 45 CREATE TABLE t5(a INTEGER PRIMARY KEY,b,c,d,e,f,g); 46 CREATE INDEX t5b ON t5(b); 47 CREATE INDEX t5c ON t5(c); 48 CREATE INDEX t5d ON t5(d); 49 CREATE INDEX t5e ON t5(e); 50 CREATE INDEX t5f ON t5(f); 51 CREATE INDEX t5g ON t5(g); 52 } 53 54 do_eqp_test 3.2 { 55 SELECT a FROM t5 56 WHERE b IS NULL OR c IS NULL OR d IS NULL 57 ORDER BY a; 58 } { 59 QUERY PLAN 60 |--MULTI-INDEX OR 61 | |--INDEX 1 62 | | `--SEARCH t5 USING INDEX t5b (b=?) 63 | |--INDEX 2 64 | | `--SEARCH t5 USING INDEX t5c (c=?) 65 | `--INDEX 3 66 | `--SEARCH t5 USING INDEX t5d (d=?) 67 `--USE TEMP B-TREE FOR ORDER BY 68 } 69 70 #------------------------------------------------------------------------- 71 # If there is no likelihood() or stat3 data, SQLite assumes that a closed 72 # range scan (e.g. one constrained by "col BETWEEN ? AND ?" constraint) 73 # visits 1/64 of the rows in a table. 74 # 75 # Note: 1/63 =~ 0.016 76 # Note: 1/65 =~ 0.015 77 # 78 reset_db 79 do_execsql_test 4.1 { 80 CREATE TABLE t1(a, b); 81 CREATE INDEX i1 ON t1(a); 82 CREATE INDEX i2 ON t1(b); 83 } 84 do_eqp_test 4.2 { 85 SELECT * FROM t1 WHERE likelihood(a=?, 0.014) AND b BETWEEN ? AND ?; 86 } {SEARCH t1 USING INDEX i1 (a=?)} 87 88 do_eqp_test 4.3 { 89 SELECT * FROM t1 WHERE likelihood(a=?, 0.016) AND b BETWEEN ? AND ?; 90 } {SEARCH t1 USING INDEX i2 (b>? AND b? AND x? AND b=950 AND b<=1010) OR (b IS NULL AND c NOT NULL) 153 ORDER BY a 154 } { 155 QUERY PLAN 156 |--MULTI-INDEX OR 157 | |--INDEX 1 158 | | `--SEARCH t1 USING INDEX t1b (b>? AND b