3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing optimizations associated with "IS NULL"
13 # and "IS NOT NULL" operators on columns with NOT NULL constraints.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix notnull2
21 CREATE TABLE t1(a, b);
22 CREATE TABLE t2(c, d NOT NULL);
25 SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<1000
27 INSERT INTO t1 SELECT i, i FROM x;
28 INSERT INTO t2 SELECT * FROM t1;
31 proc do_vmstep_test {tn sql nstep {res {}}} {
32 uplevel [list do_execsql_test $tn.0 $sql $res]
34 set vmstep [db status vmstep]
35 if {[string range $nstep 0 0]=="+"} {
36 set body "if {$vmstep<$nstep} {
37 error \"got $vmstep, expected more than [string range $nstep 1 end]\"
40 set body "if {$vmstep>$nstep} {
41 error \"got $vmstep, expected less than $nstep\"
45 # set name "$tn.vmstep=$vmstep,expect=$nstep"
47 uplevel [list do_test $name $body {}]
50 do_vmstep_test 1.1.1 {
51 SELECT * FROM t1 LEFT JOIN t2 WHERE a=c AND d IS NULL;
53 do_vmstep_test 1.1.2 {
54 SELECT * FROM t1 LEFT JOIN t2 WHERE a=c AND c IS NULL;
57 do_vmstep_test 1.2.1 {
58 SELECT * FROM ( SELECT * FROM t2 ) WHERE d IS NULL
60 do_vmstep_test 1.2.2 {
61 SELECT * FROM ( SELECT * FROM t2 ) WHERE c IS NULL
64 do_vmstep_test 1.3.1 {
65 SELECT * FROM t2 WHERE d IS NULL
67 do_vmstep_test 1.3.2 {
68 SELECT * FROM t2 WHERE c IS NULL
71 do_vmstep_test 1.4.1 {
72 SELECT (d IS NOT NULL) FROM t2 WHERE 0==( d IS NOT NULL )
74 do_vmstep_test 1.4.2 {
75 SELECT * FROM t2 WHERE 0==( c IS NOT NULL )
78 do_vmstep_test 1.5.1 {
79 SELECT count(*) FROM t2 WHERE EXISTS(
80 SELECT t2.d IS NULL FROM t1 WHERE t1.a=450
83 do_vmstep_test 1.5.2 {
84 SELECT count(*) FROM t2 WHERE EXISTS(
85 SELECT t2.c IS NULL FROM t1 WHERE t1.a=450
89 #-------------------------------------------------------------------------
92 CREATE TABLE T1(a INTEGER PRIMARY KEY, b);
93 CREATE TABLE T3(k, v);
97 SELECT * FROM (SELECT a, b FROM t1) LEFT JOIN t3 ON a IS NULL;
102 #-------------------------------------------------------------------------
104 do_execsql_test 3.0 {
105 CREATE TABLE t0(c0 PRIMARY KEY);
106 INSERT INTO t0(c0) VALUES (0);
108 do_execsql_test 3.1 {
109 SELECT * FROM t0 WHERE ((c0 NOT NULL) AND 1) OR (c0 == NULL);