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 #***********************************************************************
14 # When you use an "IS NULL" constraint on a UNIQUE index, the result
15 # is not necessarily UNIQUE. Make sure the optimizer does not assume
18 # $Id: tkt3824.test,v 1.2 2009/04/24 20:32:31 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 proc execsql_status {sql {db db}} {
24 set result [uplevel $db eval [list $sql]]
25 if {[db status sort]} {
35 INSERT INTO t1 VALUES(1,NULL);
36 INSERT INTO t1 VALUES(9,NULL);
37 INSERT INTO t1 VALUES(5,NULL);
38 INSERT INTO t1 VALUES(123,NULL);
39 INSERT INTO t1 VALUES(-10,NULL);
40 CREATE UNIQUE INDEX t1b ON t1(b);
43 SELECT a FROM t1 WHERE b IS NULL ORDER BY a;
45 } {-10 1 5 9 123 sort}
48 SELECT a FROM t1 WHERE b IS NULL ORDER BY b, a;
50 } {-10 1 5 9 123 sort}
54 CREATE TABLE t2(a,b,c);
55 INSERT INTO t2 VALUES(1,1,NULL);
56 INSERT INTO t2 VALUES(9,2,NULL);
57 INSERT INTO t2 VALUES(5,2,NULL);
58 INSERT INTO t2 VALUES(123,3,NULL);
59 INSERT INTO t2 VALUES(-10,3,NULL);
60 CREATE UNIQUE INDEX t2bc ON t2(b,c);
63 SELECT a FROM t2 WHERE b=2 AND c IS NULL ORDER BY a;
68 SELECT a FROM t2 WHERE b=2 AND c IS NULL ORDER BY b, a;
72 lsort [execsql_status {
73 SELECT a FROM t2 WHERE b=2 AND c IS NULL ORDER BY b;
80 INSERT INTO t3 SELECT a, b FROM t1;
81 INSERT INTO t3 VALUES(234,567);
82 CREATE UNIQUE INDEX t3y ON t3(y);
83 DELETE FROM t3 WHERE y IS NULL;
91 INSERT INTO t4 SELECT a, b FROM t1;
92 INSERT INTO t4 VALUES(234,567);
93 CREATE UNIQUE INDEX t4y ON t4(y);
94 UPDATE t4 SET rowid=rowid+100 WHERE y IS NULL;
95 SELECT rowid, x FROM t4 ORDER BY rowid;
97 } {6 234 101 1 102 9 103 5 104 123 105 -10}