sl@0: # 2001 September 15 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is testing the use of indices in WHERE clases. sl@0: # sl@0: # $Id: where.test,v 1.47 2008/09/01 15:52:11 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # Build some test data sl@0: # sl@0: do_test where-1.0 { sl@0: execsql { sl@0: CREATE TABLE t1(w int, x int, y int); sl@0: CREATE TABLE t2(p int, q int, r int, s int); sl@0: } sl@0: for {set i 1} {$i<=100} {incr i} { sl@0: set w $i sl@0: set x [expr {int(log($i)/log(2))}] sl@0: set y [expr {$i*$i + 2*$i + 1}] sl@0: execsql "INSERT INTO t1 VALUES($w,$x,$y)" sl@0: } sl@0: sl@0: ifcapable subquery { sl@0: execsql { sl@0: INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1; sl@0: } sl@0: } else { sl@0: set maxy [execsql {select max(y) from t1}] sl@0: execsql " sl@0: INSERT INTO t2 SELECT 101-w, x, $maxy+1-y, y FROM t1; sl@0: " sl@0: } sl@0: sl@0: execsql { sl@0: CREATE INDEX i1w ON t1(w); sl@0: CREATE INDEX i1xy ON t1(x,y); sl@0: CREATE INDEX i2p ON t2(p); sl@0: CREATE INDEX i2r ON t2(r); sl@0: CREATE INDEX i2qs ON t2(q, s); sl@0: } sl@0: } {} sl@0: sl@0: # Do an SQL statement. Append the search count to the end of the result. sl@0: # sl@0: proc count sql { sl@0: set ::sqlite_search_count 0 sl@0: return [concat [execsql $sql] $::sqlite_search_count] sl@0: } sl@0: sl@0: # Verify that queries use an index. We are using the special variable sl@0: # "sqlite_search_count" which tallys the number of executions of MoveTo sl@0: # and Next operators in the VDBE. By verifing that the search count is sl@0: # small we can be assured that indices are being used properly. sl@0: # sl@0: do_test where-1.1.1 { sl@0: count {SELECT x, y, w FROM t1 WHERE w=10} sl@0: } {3 121 10 3} sl@0: do_test where-1.1.2 { sl@0: set sqlite_query_plan sl@0: } {t1 i1w} sl@0: do_test where-1.1.3 { sl@0: count {SELECT x, y, w AS abc FROM t1 WHERE abc=10} sl@0: } {3 121 10 3} sl@0: do_test where-1.1.4 { sl@0: set sqlite_query_plan sl@0: } {t1 i1w} sl@0: do_test where-1.2.1 { sl@0: count {SELECT x, y, w FROM t1 WHERE w=11} sl@0: } {3 144 11 3} sl@0: do_test where-1.2.2 { sl@0: count {SELECT x, y, w AS abc FROM t1 WHERE abc=11} sl@0: } {3 144 11 3} sl@0: do_test where-1.3.1 { sl@0: count {SELECT x, y, w AS abc FROM t1 WHERE 11=w} sl@0: } {3 144 11 3} sl@0: do_test where-1.3.2 { sl@0: count {SELECT x, y, w AS abc FROM t1 WHERE 11=abc} sl@0: } {3 144 11 3} sl@0: do_test where-1.4.1 { sl@0: count {SELECT w, x, y FROM t1 WHERE 11=w AND x>2} sl@0: } {11 3 144 3} sl@0: do_test where-1.4.2 { sl@0: set sqlite_query_plan sl@0: } {t1 i1w} sl@0: do_test where-1.4.3 { sl@0: count {SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2} sl@0: } {11 3 144 3} sl@0: do_test where-1.4.4 { sl@0: set sqlite_query_plan sl@0: } {t1 i1w} sl@0: do_test where-1.5 { sl@0: count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2} sl@0: } {3 144 3} sl@0: do_test where-1.5.2 { sl@0: set sqlite_query_plan sl@0: } {t1 i1w} sl@0: do_test where-1.6 { sl@0: count {SELECT x, y FROM t1 WHERE y<200 AND x>2 AND w=11} sl@0: } {3 144 3} sl@0: do_test where-1.7 { sl@0: count {SELECT x, y FROM t1 WHERE w=11 AND y<200 AND x>2} sl@0: } {3 144 3} sl@0: do_test where-1.8 { sl@0: count {SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3} sl@0: } {3 144 3} sl@0: do_test where-1.8.2 { sl@0: set sqlite_query_plan sl@0: } {t1 i1xy} sl@0: do_test where-1.8.3 { sl@0: count {SELECT x, y FROM t1 WHERE y=144 AND x=3} sl@0: set sqlite_query_plan sl@0: } {{} i1xy} sl@0: do_test where-1.9 { sl@0: count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3} sl@0: } {3 144 3} sl@0: do_test where-1.10 { sl@0: count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121} sl@0: } {3 121 3} sl@0: do_test where-1.11 { sl@0: count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10} sl@0: } {3 100 3} sl@0: sl@0: # New for SQLite version 2.1: Verify that that inequality constraints sl@0: # are used correctly. sl@0: # sl@0: do_test where-1.12 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND y<100} sl@0: } {8 3} sl@0: do_test where-1.13 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND 100>y} sl@0: } {8 3} sl@0: do_test where-1.14 { sl@0: count {SELECT w FROM t1 WHERE 3=x AND y<100} sl@0: } {8 3} sl@0: do_test where-1.15 { sl@0: count {SELECT w FROM t1 WHERE 3=x AND 100>y} sl@0: } {8 3} sl@0: do_test where-1.16 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND y<=100} sl@0: } {8 9 5} sl@0: do_test where-1.17 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND 100>=y} sl@0: } {8 9 5} sl@0: do_test where-1.18 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND y>225} sl@0: } {15 3} sl@0: do_test where-1.19 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND 225=225} sl@0: } {14 15 5} sl@0: do_test where-1.21 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND 225<=y} sl@0: } {14 15 5} sl@0: do_test where-1.22 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196} sl@0: } {11 12 5} sl@0: do_test where-1.23 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196} sl@0: } {10 11 12 13 9} sl@0: do_test where-1.24 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND 121y} sl@0: } {11 12 5} sl@0: do_test where-1.25 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y} sl@0: } {10 11 12 13 9} sl@0: sl@0: # Need to work on optimizing the BETWEEN operator. sl@0: # sl@0: # do_test where-1.26 { sl@0: # count {SELECT w FROM t1 WHERE x=3 AND y BETWEEN 121 AND 196} sl@0: # } {10 11 12 13 9} sl@0: sl@0: do_test where-1.27 { sl@0: count {SELECT w FROM t1 WHERE x=3 AND y+1==122} sl@0: } {10 10} sl@0: sl@0: do_test where-1.28 { sl@0: count {SELECT w FROM t1 WHERE x+1=4 AND y+1==122} sl@0: } {10 99} sl@0: do_test where-1.29 { sl@0: count {SELECT w FROM t1 WHERE y==121} sl@0: } {10 99} sl@0: sl@0: sl@0: do_test where-1.30 { sl@0: count {SELECT w FROM t1 WHERE w>97} sl@0: } {98 99 100 3} sl@0: do_test where-1.31 { sl@0: count {SELECT w FROM t1 WHERE w>=97} sl@0: } {97 98 99 100 4} sl@0: do_test where-1.33 { sl@0: count {SELECT w FROM t1 WHERE w==97} sl@0: } {97 2} sl@0: do_test where-1.33.1 { sl@0: count {SELECT w FROM t1 WHERE w<=97 AND w==97} sl@0: } {97 2} sl@0: do_test where-1.33.2 { sl@0: count {SELECT w FROM t1 WHERE w<98 AND w==97} sl@0: } {97 2} sl@0: do_test where-1.33.3 { sl@0: count {SELECT w FROM t1 WHERE w>=97 AND w==97} sl@0: } {97 2} sl@0: do_test where-1.33.4 { sl@0: count {SELECT w FROM t1 WHERE w>96 AND w==97} sl@0: } {97 2} sl@0: do_test where-1.33.5 { sl@0: count {SELECT w FROM t1 WHERE w==97 AND w==97} sl@0: } {97 2} sl@0: do_test where-1.34 { sl@0: count {SELECT w FROM t1 WHERE w+1==98} sl@0: } {97 99} sl@0: do_test where-1.35 { sl@0: count {SELECT w FROM t1 WHERE w<3} sl@0: } {1 2 2} sl@0: do_test where-1.36 { sl@0: count {SELECT w FROM t1 WHERE w<=3} sl@0: } {1 2 3 3} sl@0: do_test where-1.37 { sl@0: count {SELECT w FROM t1 WHERE w+1<=4 ORDER BY w} sl@0: } {1 2 3 99} sl@0: sl@0: do_test where-1.38 { sl@0: count {SELECT (w) FROM t1 WHERE (w)>(97)} sl@0: } {98 99 100 3} sl@0: do_test where-1.39 { sl@0: count {SELECT (w) FROM t1 WHERE (w)>=(97)} sl@0: } {97 98 99 100 4} sl@0: do_test where-1.40 { sl@0: count {SELECT (w) FROM t1 WHERE (w)==(97)} sl@0: } {97 2} sl@0: do_test where-1.41 { sl@0: count {SELECT (w) FROM t1 WHERE ((w)+(1))==(98)} sl@0: } {97 99} sl@0: sl@0: sl@0: # Do the same kind of thing except use a join as the data source. sl@0: # sl@0: do_test where-2.1 { sl@0: count { sl@0: SELECT w, p FROM t2, t1 sl@0: WHERE x=q AND y=s AND r=8977 sl@0: } sl@0: } {34 67 6} sl@0: do_test where-2.2 { sl@0: count { sl@0: SELECT w, p FROM t2, t1 sl@0: WHERE x=q AND s=y AND r=8977 sl@0: } sl@0: } {34 67 6} sl@0: do_test where-2.3 { sl@0: count { sl@0: SELECT w, p FROM t2, t1 sl@0: WHERE x=q AND s=y AND r=8977 AND w>10 sl@0: } sl@0: } {34 67 6} sl@0: do_test where-2.4 { sl@0: count { sl@0: SELECT w, p FROM t2, t1 sl@0: WHERE p<80 AND x=q AND s=y AND r=8977 AND w>10 sl@0: } sl@0: } {34 67 6} sl@0: do_test where-2.5 { sl@0: count { sl@0: SELECT w, p FROM t2, t1 sl@0: WHERE p<80 AND x=q AND 8977=r AND s=y AND w>10 sl@0: } sl@0: } {34 67 6} sl@0: do_test where-2.6 { sl@0: count { sl@0: SELECT w, p FROM t2, t1 sl@0: WHERE x=q AND p=77 AND s=y AND w>5 sl@0: } sl@0: } {24 77 6} sl@0: do_test where-2.7 { sl@0: count { sl@0: SELECT w, p FROM t1, t2 sl@0: WHERE x=q AND p>77 AND s=y AND w=5 sl@0: } sl@0: } {5 96 6} sl@0: sl@0: # Lets do a 3-way join. sl@0: # sl@0: do_test where-3.1 { sl@0: count { sl@0: SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C sl@0: WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=11 sl@0: } sl@0: } {11 90 11 8} sl@0: do_test where-3.2 { sl@0: count { sl@0: SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C sl@0: WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=12 sl@0: } sl@0: } {12 89 12 8} sl@0: do_test where-3.3 { sl@0: count { sl@0: SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C sl@0: WHERE A.w=15 AND B.p=C.w AND B.r=10202-A.y sl@0: } sl@0: } {15 86 86 8} sl@0: sl@0: # Test to see that the special case of a constant WHERE clause is sl@0: # handled. sl@0: # sl@0: do_test where-4.1 { sl@0: count { sl@0: SELECT * FROM t1 WHERE 0 sl@0: } sl@0: } {0} sl@0: do_test where-4.2 { sl@0: count { sl@0: SELECT * FROM t1 WHERE 1 LIMIT 1 sl@0: } sl@0: } {1 0 4 0} sl@0: do_test where-4.3 { sl@0: execsql { sl@0: SELECT 99 WHERE 0 sl@0: } sl@0: } {} sl@0: do_test where-4.4 { sl@0: execsql { sl@0: SELECT 99 WHERE 1 sl@0: } sl@0: } {99} sl@0: do_test where-4.5 { sl@0: execsql { sl@0: SELECT 99 WHERE 0.1 sl@0: } sl@0: } {99} sl@0: do_test where-4.6 { sl@0: execsql { sl@0: SELECT 99 WHERE 0.0 sl@0: } sl@0: } {} sl@0: do_test where-4.7 { sl@0: execsql { sl@0: SELECT count(*) FROM t1 WHERE t1.w sl@0: } sl@0: } {100} sl@0: sl@0: # Verify that IN operators in a WHERE clause are handled correctly. sl@0: # Omit these tests if the build is not capable of sub-queries. sl@0: # sl@0: ifcapable subquery { sl@0: do_test where-5.1 { sl@0: count { sl@0: SELECT * FROM t1 WHERE rowid IN (1,2,3,1234) order by 1; sl@0: } sl@0: } {1 0 4 2 1 9 3 1 16 4} sl@0: do_test where-5.2 { sl@0: count { sl@0: SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1; sl@0: } sl@0: } {1 0 4 2 1 9 3 1 16 102} sl@0: do_test where-5.3 { sl@0: count { sl@0: SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1; sl@0: } sl@0: } {1 0 4 2 1 9 3 1 16 14} sl@0: do_test where-5.4 { sl@0: count { sl@0: SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1; sl@0: } sl@0: } {1 0 4 2 1 9 3 1 16 102} sl@0: do_test where-5.5 { sl@0: count { sl@0: SELECT * FROM t1 WHERE rowid IN sl@0: (select rowid from t1 where rowid IN (-1,2,4)) sl@0: ORDER BY 1; sl@0: } sl@0: } {2 1 9 4 2 25 3} sl@0: do_test where-5.6 { sl@0: count { sl@0: SELECT * FROM t1 WHERE rowid+0 IN sl@0: (select rowid from t1 where rowid IN (-1,2,4)) sl@0: ORDER BY 1; sl@0: } sl@0: } {2 1 9 4 2 25 103} sl@0: do_test where-5.7 { sl@0: count { sl@0: SELECT * FROM t1 WHERE w IN sl@0: (select rowid from t1 where rowid IN (-1,2,4)) sl@0: ORDER BY 1; sl@0: } sl@0: } {2 1 9 4 2 25 9} sl@0: do_test where-5.8 { sl@0: count { sl@0: SELECT * FROM t1 WHERE w+0 IN sl@0: (select rowid from t1 where rowid IN (-1,2,4)) sl@0: ORDER BY 1; sl@0: } sl@0: } {2 1 9 4 2 25 103} sl@0: do_test where-5.9 { sl@0: count { sl@0: SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1; sl@0: } sl@0: } {2 1 9 3 1 16 7} sl@0: do_test where-5.10 { sl@0: count { sl@0: SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1; sl@0: } sl@0: } {2 1 9 3 1 16 199} sl@0: do_test where-5.11 { sl@0: count { sl@0: SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1; sl@0: } sl@0: } {79 6 6400 89 6 8100 199} sl@0: do_test where-5.12 { sl@0: count { sl@0: SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1; sl@0: } sl@0: } {79 6 6400 89 6 8100 7} sl@0: do_test where-5.13 { sl@0: count { sl@0: SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1; sl@0: } sl@0: } {2 1 9 3 1 16 7} sl@0: do_test where-5.14 { sl@0: count { sl@0: SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1; sl@0: } sl@0: } {2 1 9 8} sl@0: do_test where-5.15 { sl@0: count { sl@0: SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,16) ORDER BY 1; sl@0: } sl@0: } {2 1 9 3 1 16 11} sl@0: } sl@0: sl@0: # This procedure executes the SQL. Then it checks to see if the OP_Sort sl@0: # opcode was executed. If an OP_Sort did occur, then "sort" is appended sl@0: # to the result. If no OP_Sort happened, then "nosort" is appended. sl@0: # sl@0: # This procedure is used to check to make sure sorting is or is not sl@0: # occurring as expected. sl@0: # sl@0: proc cksort {sql} { sl@0: set ::sqlite_sort_count 0 sl@0: set data [execsql $sql] sl@0: if {$::sqlite_sort_count} {set x sort} {set x nosort} sl@0: lappend data $x sl@0: return $data sl@0: } sl@0: # Check out the logic that attempts to implement the ORDER BY clause sl@0: # using an index rather than by sorting. sl@0: # sl@0: do_test where-6.1 { sl@0: execsql { sl@0: CREATE TABLE t3(a,b,c); sl@0: CREATE INDEX t3a ON t3(a); sl@0: CREATE INDEX t3bc ON t3(b,c); sl@0: CREATE INDEX t3acb ON t3(a,c,b); sl@0: INSERT INTO t3 SELECT w, 101-w, y FROM t1; sl@0: SELECT count(*), sum(a), sum(b), sum(c) FROM t3; sl@0: } sl@0: } {100 5050 5050 348550} sl@0: do_test where-6.2 { sl@0: cksort { sl@0: SELECT * FROM t3 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 nosort} sl@0: do_test where-6.3 { sl@0: cksort { sl@0: SELECT * FROM t3 ORDER BY a+1 LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 sort} sl@0: do_test where-6.4 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a<10 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 nosort} sl@0: do_test where-6.5 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a>0 AND a<10 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 nosort} sl@0: do_test where-6.6 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a>0 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 nosort} sl@0: do_test where-6.7 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE b>0 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 nosort} sl@0: ifcapable subquery { sl@0: do_test where-6.8 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 2 99 9 3 98 16 sort} sl@0: } sl@0: do_test where-6.9.1 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.1.1 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a>=1 AND a=1 AND c>0 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.1.2 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a<2 AND a=1 AND c>0 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.2 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.3 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY c LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.4 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a DESC LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.5 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a DESC, c DESC LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.6 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY c DESC LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.7 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY c,a LIMIT 3 sl@0: } sl@0: } {1 100 4 sort} sl@0: do_test where-6.9.8 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a DESC, c ASC LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.9.9 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a ASC, c DESC LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.10 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.11 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.12 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c,b LIMIT 3 sl@0: } sl@0: } {1 100 4 nosort} sl@0: do_test where-6.13 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a>0 ORDER BY a DESC LIMIT 3 sl@0: } sl@0: } {100 1 10201 99 2 10000 98 3 9801 nosort} sl@0: do_test where-6.13.1 { sl@0: cksort { sl@0: SELECT * FROM t3 WHERE a>0 ORDER BY -a LIMIT 3 sl@0: } sl@0: } {100 1 10201 99 2 10000 98 3 9801 sort} sl@0: do_test where-6.14 { sl@0: cksort { sl@0: SELECT * FROM t3 ORDER BY b LIMIT 3 sl@0: } sl@0: } {100 1 10201 99 2 10000 98 3 9801 nosort} sl@0: do_test where-6.15 { sl@0: cksort { sl@0: SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t3.a LIMIT 3 sl@0: } sl@0: } {1 0 2 1 3 1 nosort} sl@0: do_test where-6.16 { sl@0: cksort { sl@0: SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t1.x, t3.a LIMIT 3 sl@0: } sl@0: } {1 0 2 1 3 1 sort} sl@0: do_test where-6.19 { sl@0: cksort { sl@0: SELECT y FROM t1 ORDER BY w LIMIT 3; sl@0: } sl@0: } {4 9 16 nosort} sl@0: do_test where-6.20 { sl@0: cksort { sl@0: SELECT y FROM t1 ORDER BY rowid LIMIT 3; sl@0: } sl@0: } {4 9 16 nosort} sl@0: do_test where-6.21 { sl@0: cksort { sl@0: SELECT y FROM t1 ORDER BY rowid, y LIMIT 3; sl@0: } sl@0: } {4 9 16 nosort} sl@0: do_test where-6.22 { sl@0: cksort { sl@0: SELECT y FROM t1 ORDER BY rowid, y DESC LIMIT 3; sl@0: } sl@0: } {4 9 16 nosort} sl@0: do_test where-6.23 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y>4 ORDER BY rowid, w, x LIMIT 3; sl@0: } sl@0: } {9 16 25 nosort} sl@0: do_test where-6.24 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y>=9 ORDER BY rowid, x DESC, w LIMIT 3; sl@0: } sl@0: } {9 16 25 nosort} sl@0: do_test where-6.25 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y>4 AND y<25 ORDER BY rowid; sl@0: } sl@0: } {9 16 nosort} sl@0: do_test where-6.26 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y>=4 AND y<=25 ORDER BY oid; sl@0: } sl@0: } {4 9 16 25 nosort} sl@0: do_test where-6.27 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y<=25 ORDER BY _rowid_, w+y; sl@0: } sl@0: } {4 9 16 25 nosort} sl@0: sl@0: sl@0: # Tests for reverse-order sorting. sl@0: # sl@0: do_test where-7.1 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 ORDER BY y; sl@0: } sl@0: } {8 9 10 11 12 13 14 15 nosort} sl@0: do_test where-7.2 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 ORDER BY y DESC; sl@0: } sl@0: } {15 14 13 12 11 10 9 8 nosort} sl@0: do_test where-7.3 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>100 ORDER BY y LIMIT 3; sl@0: } sl@0: } {10 11 12 nosort} sl@0: do_test where-7.4 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>100 ORDER BY y DESC LIMIT 3; sl@0: } sl@0: } {15 14 13 nosort} sl@0: do_test where-7.5 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>121 ORDER BY y DESC; sl@0: } sl@0: } {15 14 13 12 11 nosort} sl@0: do_test where-7.6 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=121 ORDER BY y DESC; sl@0: } sl@0: } {15 14 13 12 11 10 nosort} sl@0: do_test where-7.7 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<196 ORDER BY y DESC; sl@0: } sl@0: } {12 11 10 nosort} sl@0: do_test where-7.8 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196 ORDER BY y DESC; sl@0: } sl@0: } {13 12 11 10 nosort} sl@0: do_test where-7.9 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>121 AND y<=196 ORDER BY y DESC; sl@0: } sl@0: } {13 12 11 nosort} sl@0: do_test where-7.10 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>100 AND y<196 ORDER BY y DESC; sl@0: } sl@0: } {12 11 10 nosort} sl@0: do_test where-7.11 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<196 ORDER BY y; sl@0: } sl@0: } {10 11 12 nosort} sl@0: do_test where-7.12 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196 ORDER BY y; sl@0: } sl@0: } {10 11 12 13 nosort} sl@0: do_test where-7.13 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>121 AND y<=196 ORDER BY y; sl@0: } sl@0: } {11 12 13 nosort} sl@0: do_test where-7.14 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>100 AND y<196 ORDER BY y; sl@0: } sl@0: } {10 11 12 nosort} sl@0: do_test where-7.15 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y<81 ORDER BY y; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.16 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y<=81 ORDER BY y; sl@0: } sl@0: } {8 nosort} sl@0: do_test where-7.17 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>256 ORDER BY y; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.18 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=256 ORDER BY y; sl@0: } sl@0: } {15 nosort} sl@0: do_test where-7.19 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y<81 ORDER BY y DESC; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.20 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y<=81 ORDER BY y DESC; sl@0: } sl@0: } {8 nosort} sl@0: do_test where-7.21 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>256 ORDER BY y DESC; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.22 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=3 AND y>=256 ORDER BY y DESC; sl@0: } sl@0: } {15 nosort} sl@0: do_test where-7.23 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=0 AND y<4 ORDER BY y; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.24 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=0 AND y<=4 ORDER BY y; sl@0: } sl@0: } {1 nosort} sl@0: do_test where-7.25 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=6 AND y>10201 ORDER BY y; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.26 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=6 AND y>=10201 ORDER BY y; sl@0: } sl@0: } {100 nosort} sl@0: do_test where-7.27 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=0 AND y<4 ORDER BY y DESC; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.28 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=0 AND y<=4 ORDER BY y DESC; sl@0: } sl@0: } {1 nosort} sl@0: do_test where-7.29 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=6 AND y>10201 ORDER BY y DESC; sl@0: } sl@0: } {nosort} sl@0: do_test where-7.30 { sl@0: cksort { sl@0: SELECT w FROM t1 WHERE x=6 AND y>=10201 ORDER BY y DESC; sl@0: } sl@0: } {100 nosort} sl@0: do_test where-7.31 { sl@0: cksort { sl@0: SELECT y FROM t1 ORDER BY rowid DESC LIMIT 3 sl@0: } sl@0: } {10201 10000 9801 nosort} sl@0: do_test where-7.32 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y<25 ORDER BY rowid DESC sl@0: } sl@0: } {16 9 4 nosort} sl@0: do_test where-7.33 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y<=25 ORDER BY rowid DESC sl@0: } sl@0: } {25 16 9 4 nosort} sl@0: do_test where-7.34 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y<25 AND y>4 ORDER BY rowid DESC, y DESC sl@0: } sl@0: } {16 9 nosort} sl@0: do_test where-7.35 { sl@0: cksort { sl@0: SELECT y FROM t1 WHERE y<25 AND y>=4 ORDER BY rowid DESC sl@0: } sl@0: } {16 9 4 nosort} sl@0: sl@0: do_test where-8.1 { sl@0: execsql { sl@0: CREATE TABLE t4 AS SELECT * FROM t1; sl@0: CREATE INDEX i4xy ON t4(x,y); sl@0: } sl@0: cksort { sl@0: SELECT w FROM t4 WHERE x=4 and y<1000 ORDER BY y DESC limit 3; sl@0: } sl@0: } {30 29 28 nosort} sl@0: do_test where-8.2 { sl@0: execsql { sl@0: DELETE FROM t4; sl@0: } sl@0: cksort { sl@0: SELECT w FROM t4 WHERE x=4 and y<1000 ORDER BY y DESC limit 3; sl@0: } sl@0: } {nosort} sl@0: sl@0: # Make sure searches with an index work with an empty table. sl@0: # sl@0: do_test where-9.1 { sl@0: execsql { sl@0: CREATE TABLE t5(x PRIMARY KEY); sl@0: SELECT * FROM t5 WHERE x<10; sl@0: } sl@0: } {} sl@0: do_test where-9.2 { sl@0: execsql { sl@0: SELECT * FROM t5 WHERE x<10 ORDER BY x DESC; sl@0: } sl@0: } {} sl@0: do_test where-9.3 { sl@0: execsql { sl@0: SELECT * FROM t5 WHERE x=10; sl@0: } sl@0: } {} sl@0: sl@0: do_test where-10.1 { sl@0: execsql { sl@0: SELECT 1 WHERE abs(random())<0 sl@0: } sl@0: } {} sl@0: do_test where-10.2 { sl@0: proc tclvar_func {vname} {return [set ::$vname]} sl@0: db function tclvar tclvar_func sl@0: set ::v1 0 sl@0: execsql { sl@0: SELECT count(*) FROM t1 WHERE tclvar('v1'); sl@0: } sl@0: } {0} sl@0: do_test where-10.3 { sl@0: set ::v1 1 sl@0: execsql { sl@0: SELECT count(*) FROM t1 WHERE tclvar('v1'); sl@0: } sl@0: } {100} sl@0: do_test where-10.4 { sl@0: set ::v1 1 sl@0: proc tclvar_func {vname} { sl@0: upvar #0 $vname v sl@0: set v [expr {!$v}] sl@0: return $v sl@0: } sl@0: execsql { sl@0: SELECT count(*) FROM t1 WHERE tclvar('v1'); sl@0: } sl@0: } {50} sl@0: sl@0: # Ticket #1376. The query below was causing a segfault. sl@0: # The problem was the age-old error of calling realloc() on an sl@0: # array while there are still pointers to individual elements of sl@0: # that array. sl@0: # sl@0: do_test where-11.1 { sl@0: execsql { sl@0: CREATE TABLE t99(Dte INT, X INT); sl@0: DELETE FROM t99 WHERE (Dte = 2451337) OR (Dte = 2451339) OR sl@0: (Dte BETWEEN 2451345 AND 2451347) OR (Dte = 2451351) OR sl@0: (Dte BETWEEN 2451355 AND 2451356) OR (Dte = 2451358) OR sl@0: (Dte = 2451362) OR (Dte = 2451365) OR (Dte = 2451367) OR sl@0: (Dte BETWEEN 2451372 AND 2451376) OR (Dte BETWEEN 2451382 AND 2451384) OR sl@0: (Dte = 2451387) OR (Dte BETWEEN 2451389 AND 2451391) OR sl@0: (Dte BETWEEN 2451393 AND 2451395) OR (Dte = 2451400) OR sl@0: (Dte = 2451402) OR (Dte = 2451404) OR (Dte BETWEEN 2451416 AND 2451418) OR sl@0: (Dte = 2451422) OR (Dte = 2451426) OR (Dte BETWEEN 2451445 AND 2451446) OR sl@0: (Dte = 2451456) OR (Dte = 2451458) OR (Dte BETWEEN 2451465 AND 2451467) OR sl@0: (Dte BETWEEN 2451469 AND 2451471) OR (Dte = 2451474) OR sl@0: (Dte BETWEEN 2451477 AND 2451501) OR (Dte BETWEEN 2451503 AND 2451509) OR sl@0: (Dte BETWEEN 2451511 AND 2451514) OR (Dte BETWEEN 2451518 AND 2451521) OR sl@0: (Dte BETWEEN 2451523 AND 2451531) OR (Dte BETWEEN 2451533 AND 2451537) OR sl@0: (Dte BETWEEN 2451539 AND 2451544) OR (Dte BETWEEN 2451546 AND 2451551) OR sl@0: (Dte BETWEEN 2451553 AND 2451555) OR (Dte = 2451557) OR sl@0: (Dte BETWEEN 2451559 AND 2451561) OR (Dte = 2451563) OR sl@0: (Dte BETWEEN 2451565 AND 2451566) OR (Dte BETWEEN 2451569 AND 2451571) OR sl@0: (Dte = 2451573) OR (Dte = 2451575) OR (Dte = 2451577) OR (Dte = 2451581) OR sl@0: (Dte BETWEEN 2451583 AND 2451586) OR (Dte BETWEEN 2451588 AND 2451592) OR sl@0: (Dte BETWEEN 2451596 AND 2451598) OR (Dte = 2451600) OR sl@0: (Dte BETWEEN 2451602 AND 2451603) OR (Dte = 2451606) OR (Dte = 2451611); sl@0: } sl@0: } {} sl@0: sl@0: # Ticket #2116: Make sure sorting by index works well with nn INTEGER PRIMARY sl@0: # KEY. sl@0: # sl@0: do_test where-12.1 { sl@0: execsql { sl@0: CREATE TABLE t6(a INTEGER PRIMARY KEY, b TEXT); sl@0: INSERT INTO t6 VALUES(1,'one'); sl@0: INSERT INTO t6 VALUES(4,'four'); sl@0: CREATE INDEX t6i1 ON t6(b); sl@0: } sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY b; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-12.2 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY b, a; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-12.3 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY a; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-12.4 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY a, b; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-12.5 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY b DESC; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-12.6 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY b DESC, a DESC; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-12.7 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY b DESC, a ASC; sl@0: } sl@0: } {1 one 4 four sort} sl@0: do_test where-12.8 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY b ASC, a DESC; sl@0: } sl@0: } {4 four 1 one sort} sl@0: do_test where-12.9 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY a DESC; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-12.10 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY a DESC, b DESC; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-12.11 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY a DESC, b ASC; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-12.12 { sl@0: cksort { sl@0: SELECT * FROM t6 ORDER BY a ASC, b DESC; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-13.1 { sl@0: execsql { sl@0: CREATE TABLE t7(a INTEGER PRIMARY KEY, b TEXT); sl@0: INSERT INTO t7 VALUES(1,'one'); sl@0: INSERT INTO t7 VALUES(4,'four'); sl@0: CREATE INDEX t7i1 ON t7(b); sl@0: } sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY b; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-13.2 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY b, a; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-13.3 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY a; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-13.4 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY a, b; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-13.5 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY b DESC; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-13.6 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY b DESC, a DESC; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: do_test where-13.7 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY b DESC, a ASC; sl@0: } sl@0: } {1 one 4 four sort} sl@0: do_test where-13.8 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY b ASC, a DESC; sl@0: } sl@0: } {4 four 1 one sort} sl@0: do_test where-13.9 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY a DESC; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-13.10 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY a DESC, b DESC; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-13.11 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY a DESC, b ASC; sl@0: } sl@0: } {4 four 1 one nosort} sl@0: do_test where-13.12 { sl@0: cksort { sl@0: SELECT * FROM t7 ORDER BY a ASC, b DESC; sl@0: } sl@0: } {1 one 4 four nosort} sl@0: sl@0: # Ticket #2211. sl@0: # sl@0: # When optimizing out ORDER BY clauses, make sure that trailing terms sl@0: # of the ORDER BY clause do not reference other tables in a join. sl@0: # sl@0: do_test where-14.1 { sl@0: execsql { sl@0: CREATE TABLE t8(a INTEGER PRIMARY KEY, b TEXT UNIQUE); sl@0: INSERT INTO t8 VALUES(1,'one'); sl@0: INSERT INTO t8 VALUES(4,'four'); sl@0: } sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b sl@0: } sl@0: } {1/4 1/1 4/4 4/1 sort} sl@0: do_test where-14.2 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b DESC sl@0: } sl@0: } {1/1 1/4 4/1 4/4 sort} sl@0: do_test where-14.3 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, x.b sl@0: } sl@0: } {1/1 1/4 4/1 4/4 nosort} sl@0: do_test where-14.4 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, x.b DESC sl@0: } sl@0: } {1/1 1/4 4/1 4/4 nosort} sl@0: do_test where-14.5 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||x.b sl@0: } sl@0: } {4/1 4/4 1/1 1/4 nosort} sl@0: do_test where-14.6 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||x.b DESC sl@0: } sl@0: } {4/1 4/4 1/1 1/4 nosort} sl@0: do_test where-14.7 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||y.b sl@0: } sl@0: } {4/1 4/4 1/1 1/4 sort} sl@0: do_test where-14.7.1 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a, y.a||y.b sl@0: } sl@0: } {4/1 4/4 1/1 1/4 sort} sl@0: do_test where-14.7.2 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a, x.a||x.b sl@0: } sl@0: } {4/1 4/4 1/1 1/4 nosort} sl@0: do_test where-14.8 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||y.b DESC sl@0: } sl@0: } {4/4 4/1 1/4 1/1 sort} sl@0: do_test where-14.9 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||y.b sl@0: } sl@0: } {4/4 4/1 1/4 1/1 sort} sl@0: do_test where-14.10 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||y.b DESC sl@0: } sl@0: } {4/1 4/4 1/1 1/4 sort} sl@0: do_test where-14.11 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||x.b sl@0: } sl@0: } {4/1 4/4 1/1 1/4 sort} sl@0: do_test where-14.12 { sl@0: cksort { sl@0: SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||x.b DESC sl@0: } sl@0: } {4/4 4/1 1/4 1/1 sort} sl@0: sl@0: # Ticket #2445. sl@0: # sl@0: # There was a crash that could occur when a where clause contains an sl@0: # alias for an expression in the result set, and that expression retrieves sl@0: # a column of the second or subsequent table in a join. sl@0: # sl@0: do_test where-15.1 { sl@0: execsql { sl@0: CREATE TEMP TABLE t1 (a, b, c, d, e); sl@0: CREATE TEMP TABLE t2 (f); sl@0: SELECT t1.e AS alias FROM t2, t1 WHERE alias = 1 ; sl@0: } sl@0: } {} sl@0: sl@0: integrity_check {where-99.0} sl@0: sl@0: finish_test