mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add simple tests (and a fix) for the change on this branch.
FossilOrigin-Name: 897f3f40267dc922f0fda287484435e1fd8709bade3e87c3829e2f945bb5e4aa
This commit is contained in:
87
test/exists2.test
Normal file
87
test/exists2.test
Normal file
@ -0,0 +1,87 @@
|
||||
# 2021 January 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing cases where EXISTS expressions are
|
||||
# transformed to IN() expressions by where.c
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix exists2
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
||||
INSERT INTO t1 VALUES(1, 'one');
|
||||
INSERT INTO t1 VALUES(2, 'two');
|
||||
INSERT INTO t1 VALUES(3, 'three');
|
||||
INSERT INTO t1 VALUES(4, 'four');
|
||||
INSERT INTO t1 VALUES(5, 'five');
|
||||
INSERT INTO t1 VALUES(6, 'six');
|
||||
INSERT INTO t1 VALUES(7, 'seven');
|
||||
|
||||
CREATE TABLE t2(c INTEGER, d INTEGER);
|
||||
INSERT INTO t2 VALUES(1, 1);
|
||||
INSERT INTO t2 VALUES(3, 2);
|
||||
INSERT INTO t2 VALUES(5, 3);
|
||||
INSERT INTO t2 VALUES(7, 4);
|
||||
}
|
||||
|
||||
proc do_execsql_eqp_test {tn sql eqp res} {
|
||||
uplevel [list do_eqp_test $tn.1 $sql [string trim $eqp]]
|
||||
uplevel [list do_execsql_test $tn.2 $sql $res]
|
||||
}
|
||||
|
||||
do_execsql_eqp_test 1.1 {
|
||||
SELECT t1.* FROM t1 WHERE EXISTS(SELECT * FROM t2 WHERE t1.a=t2.c);
|
||||
} {
|
||||
USING INTEGER PRIMARY KEY
|
||||
} {
|
||||
1 one 3 three 5 five 7 seven
|
||||
}
|
||||
|
||||
do_execsql_eqp_test 1.2 {
|
||||
SELECT t1.* FROM t1 WHERE EXISTS(SELECT * FROM t2 WHERE t2.c=t1.a);
|
||||
} {
|
||||
SEARCH TABLE t1 USING INTEGER PRIMARY KEY
|
||||
} {
|
||||
1 one 3 three 5 five 7 seven
|
||||
}
|
||||
|
||||
do_execsql_eqp_test 1.3 {
|
||||
SELECT t1.* FROM t1 WHERE EXISTS(SELECT * FROM t2 WHERE t2.c+1=t1.a);
|
||||
} {
|
||||
SEARCH TABLE t1 USING INTEGER PRIMARY KEY
|
||||
} {
|
||||
2 two 4 four 6 six
|
||||
}
|
||||
|
||||
do_execsql_eqp_test 1.4 {
|
||||
SELECT t1.* FROM t1 WHERE EXISTS(SELECT * FROM t2 WHERE t2.c+1=t1.a+1);
|
||||
} {
|
||||
SCAN TABLE t1
|
||||
} {
|
||||
1 one 3 three 5 five 7 seven
|
||||
}
|
||||
|
||||
breakpoint
|
||||
do_execsql_eqp_test 1.5 {
|
||||
SELECT t1.* FROM t1 WHERE EXISTS(
|
||||
SELECT * FROM t2 WHERE t1.a=t2.c AND d IN (1, 2, 3)
|
||||
);
|
||||
} {
|
||||
SEARCH TABLE t1 USING INTEGER PRIMARY KEY
|
||||
} {
|
||||
1 one 3 three 5 five
|
||||
}
|
||||
|
||||
|
||||
|
||||
finish_test
|
Reference in New Issue
Block a user