summaryrefslogtreecommitdiff
path: root/test/subquery2.test
blob: 04200046f9b2d68d5f714fa63043440c72e7b0e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 2011 September 16
#
# 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 script is testing correlated subqueries
#
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery {
  finish_test
  return
}

do_test subquery2-1.1 {
  execsql {
    BEGIN;
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    INSERT INTO t1 VALUES(3,4);
    INSERT INTO t1 VALUES(5,6);
    INSERT INTO t1 VALUES(7,8);
    CREATE TABLE t2(c,d);
    INSERT INTO t2 VALUES(1,1);
    INSERT INTO t2 VALUES(3,9);
    INSERT INTO t2 VALUES(5,25);
    INSERT INTO t2 VALUES(7,49);
    CREATE TABLE t3(e,f);
    INSERT INTO t3 VALUES(1,1);
    INSERT INTO t3 VALUES(3,27);
    INSERT INTO t3 VALUES(5,125);
    INSERT INTO t3 VALUES(7,343);
    COMMIT;
  }
  execsql {
    SELECT a FROM t1
     WHERE b IN (SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
  }
} {1 3 5 7}
do_test subquery2-1.2 {
  execsql {
    CREATE INDEX t1b ON t1(b);
    SELECT a FROM t1
     WHERE b IN (SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
  }
} {1 3 5 7}

do_test subquery2-1.11 {
  execsql {
    SELECT a FROM t1
     WHERE +b=(SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
  }
} {1}
do_test subquery2-1.12 {
  execsql {
    SELECT a FROM t1
     WHERE b=(SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
  }
} {1}

do_test subquery2-1.21 {
  execsql {
    SELECT a FROM t1
     WHERE +b=(SELECT x+1 FROM 
                 (SELECT DISTINCT f/d AS x FROM t2 JOIN t3 ON d*a=f))
  }
} {1 3 5 7}
do_test subquery2-1.22 {
  execsql {
    SELECT a FROM t1
     WHERE b=(SELECT x+1 FROM 
                 (SELECT DISTINCT f/d AS x FROM t2 JOIN t3 ON d*a=f))
  }
} {1 3 5 7}


finish_test