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/existsexpr2.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 / existsexpr2.test` 113 lines ยท 2311 bytes Raw Blame History 1 # 2024 June 14 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 source $testdir/lock_common.tcl 16 set testprefix existsexpr2 17 18 19 do_execsql_test 1.0 { 20 CREATE TABLE x1(a, b, PRIMARY KEY(a)) WITHOUT ROWID; 21 INSERT INTO x1 VALUES(1, 2), (3, 4), (5, 6); 22 CREATE INDEX x1b ON x1(b); 23 24 CREATE TABLE x2(x, y); 25 INSERT INTO x2 VALUES(1, 2), (3, 4), (5, 6); 26 } 27 28 do_execsql_test 1.1 { 29 SELECT * FROM x1 WHERE EXISTS (SELECT 1 FROM x2 WHERE a!=123) 30 } {1 2 3 4 5 6} 31 32 do_execsql_test 1.2 { 33 CREATE TABLE x3(u, v); 34 CREATE INDEX x3u ON x3(u); 35 INSERT INTO x3 VALUES 36 (1, 1), (1, 2), (1, 3), 37 (2, 1), (2, 2), (2, 3); 38 } 39 40 do_execsql_test 1.3 { 41 SELECT * FROM x1 WHERE EXISTS ( 42 SELECT 1 FROM x3 WHERE u IN (1, 2, 3, 4) AND v=b 43 ); 44 } { 45 1 2 46 } 47 48 #------------------------------------------------------------------------- 49 # 50 reset_db 51 do_execsql_test 2.0 { 52 CREATE TABLE t1(a, b, c); 53 CREATE INDEX t1ab ON t1(a,b); 54 55 INSERT INTO t1 VALUES 56 ('abc', 1, 1), 57 ('abc', 2, 2), 58 ('abc', 2, 3), 59 60 ('def', 1, 1), 61 ('def', 2, 2), 62 ('def', 2, 3); 63 64 CREATE TABLE t2(x, y); 65 INSERT INTO t2 VALUES(1, 1), (2, 2), (3, 3); 66 67 ANALYZE; 68 DELETE FROM sqlite_stat1; 69 INSERT INTO sqlite_stat1 VALUES('t1','t1ab','10000 5000 2'); 70 ANALYZE sqlite_master; 71 } 72 73 74 do_execsql_test 2.1 { 75 SELECT a,b,c FROM t1 WHERE b=2 ORDER BY a 76 } { 77 abc 2 2 78 abc 2 3 79 def 2 2 80 def 2 3 81 } 82 83 do_execsql_test 2.2 { 84 SELECT x, y FROM t2 WHERE EXISTS ( 85 SELECT 1 FROM t1 WHERE b=x 86 ) 87 } { 88 1 1 89 2 2 90 } 91 92 #------------------------------------------------------------------------- 93 reset_db 94 do_execsql_test 3.0 { 95 CREATE TABLE t1(a INTEGER PRIMARY KEY, b); 96 CREATE TABLE t2(c INTEGER PRIMARY KEY, d, e); 97 CREATE INDEX t2b ON t2(d); 98 } 99 100 do_execsql_test 3.1 { 101 EXPLAIN SELECT * FROM t1 WHERE EXISTS ( 102 SELECT 1 FROM t2 WHERE b=d 103 ); 104 } [execsql { 105 EXPLAIN SELECT * FROM t1 WHERE EXISTS ( 106 SELECT 1 FROM t2 WHERE b=d ORDER BY e 107 ); 108 }] 109 110 111 finish_test 112 113