sl@0
|
1 |
# 2007 Sep 12
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# This file is to test that ticket #2640 has been fixed.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# $Id: tkt2640.test,v 1.3 2008/08/04 03:51:24 danielk1977 Exp $
|
sl@0
|
15 |
#
|
sl@0
|
16 |
|
sl@0
|
17 |
# The problem in ticket #2640 was that the query optimizer was
|
sl@0
|
18 |
# not recognizing all uses of tables within subqueries in the
|
sl@0
|
19 |
# WHERE clause. If the subquery contained a compound SELECT,
|
sl@0
|
20 |
# then tables that were used by terms of the compound other than
|
sl@0
|
21 |
# the last term would not be recognized as dependencies.
|
sl@0
|
22 |
# So if one of the SELECT statements within a compound made
|
sl@0
|
23 |
# use of a table that occurs later in a join, the query
|
sl@0
|
24 |
# optimizer would not recognize this and would try to evaluate
|
sl@0
|
25 |
# the subquery too early, before that tables value had been
|
sl@0
|
26 |
# established.
|
sl@0
|
27 |
|
sl@0
|
28 |
set testdir [file dirname $argv0]
|
sl@0
|
29 |
source $testdir/tester.tcl
|
sl@0
|
30 |
|
sl@0
|
31 |
ifcapable !subquery||!compound {
|
sl@0
|
32 |
finish_test
|
sl@0
|
33 |
return
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
do_test tkt2640-1.1 {
|
sl@0
|
37 |
execsql {
|
sl@0
|
38 |
CREATE TABLE persons(person_id, name);
|
sl@0
|
39 |
INSERT INTO persons VALUES(1,'fred');
|
sl@0
|
40 |
INSERT INTO persons VALUES(2,'barney');
|
sl@0
|
41 |
INSERT INTO persons VALUES(3,'wilma');
|
sl@0
|
42 |
INSERT INTO persons VALUES(4,'pebbles');
|
sl@0
|
43 |
INSERT INTO persons VALUES(5,'bambam');
|
sl@0
|
44 |
CREATE TABLE directors(person_id);
|
sl@0
|
45 |
INSERT INTO directors VALUES(5);
|
sl@0
|
46 |
INSERT INTO directors VALUES(3);
|
sl@0
|
47 |
CREATE TABLE writers(person_id);
|
sl@0
|
48 |
INSERT INTO writers VALUES(2);
|
sl@0
|
49 |
INSERT INTO writers VALUES(3);
|
sl@0
|
50 |
INSERT INTO writers VALUES(4);
|
sl@0
|
51 |
SELECT DISTINCT p.name
|
sl@0
|
52 |
FROM persons p, directors d
|
sl@0
|
53 |
WHERE d.person_id=p.person_id
|
sl@0
|
54 |
AND NOT EXISTS (
|
sl@0
|
55 |
SELECT person_id FROM directors d1 WHERE d1.person_id=p.person_id
|
sl@0
|
56 |
EXCEPT
|
sl@0
|
57 |
SELECT person_id FROM writers w
|
sl@0
|
58 |
);
|
sl@0
|
59 |
}
|
sl@0
|
60 |
} {wilma}
|
sl@0
|
61 |
do_test tkt2640-1.2 {
|
sl@0
|
62 |
execsql {
|
sl@0
|
63 |
SELECT DISTINCT p.name
|
sl@0
|
64 |
FROM persons p CROSS JOIN directors d
|
sl@0
|
65 |
WHERE d.person_id=p.person_id
|
sl@0
|
66 |
AND NOT EXISTS (
|
sl@0
|
67 |
SELECT person_id FROM directors d1 WHERE d1.person_id=p.person_id
|
sl@0
|
68 |
EXCEPT
|
sl@0
|
69 |
SELECT person_id FROM writers w
|
sl@0
|
70 |
);
|
sl@0
|
71 |
}
|
sl@0
|
72 |
} {wilma}
|
sl@0
|
73 |
do_test tkt2640-1.3 {
|
sl@0
|
74 |
execsql {
|
sl@0
|
75 |
SELECT DISTINCT p.name
|
sl@0
|
76 |
FROM directors d CROSS JOIN persons p
|
sl@0
|
77 |
WHERE d.person_id=p.person_id
|
sl@0
|
78 |
AND NOT EXISTS (
|
sl@0
|
79 |
SELECT person_id FROM directors d1 WHERE d1.person_id=p.person_id
|
sl@0
|
80 |
EXCEPT
|
sl@0
|
81 |
SELECT person_id FROM writers w
|
sl@0
|
82 |
);
|
sl@0
|
83 |
}
|
sl@0
|
84 |
} {wilma}
|
sl@0
|
85 |
do_test tkt2640-1.4 {
|
sl@0
|
86 |
execsql {
|
sl@0
|
87 |
SELECT DISTINCT p.name
|
sl@0
|
88 |
FROM persons p, directors d
|
sl@0
|
89 |
WHERE d.person_id=p.person_id
|
sl@0
|
90 |
AND NOT EXISTS (
|
sl@0
|
91 |
SELECT person_id FROM directors d1 WHERE d1.person_id=d.person_id
|
sl@0
|
92 |
EXCEPT
|
sl@0
|
93 |
SELECT person_id FROM writers w
|
sl@0
|
94 |
);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
} {wilma}
|
sl@0
|
97 |
do_test tkt2640-1.5 {
|
sl@0
|
98 |
execsql {
|
sl@0
|
99 |
SELECT DISTINCT p.name
|
sl@0
|
100 |
FROM persons p CROSS JOIN directors d
|
sl@0
|
101 |
WHERE d.person_id=p.person_id
|
sl@0
|
102 |
AND NOT EXISTS (
|
sl@0
|
103 |
SELECT person_id FROM directors d1 WHERE d1.person_id=d.person_id
|
sl@0
|
104 |
EXCEPT
|
sl@0
|
105 |
SELECT person_id FROM writers w
|
sl@0
|
106 |
);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
} {wilma}
|
sl@0
|
109 |
do_test tkt2640-1.6 {
|
sl@0
|
110 |
execsql {
|
sl@0
|
111 |
SELECT DISTINCT p.name
|
sl@0
|
112 |
FROM directors d CROSS JOIN persons p
|
sl@0
|
113 |
WHERE d.person_id=p.person_id
|
sl@0
|
114 |
AND NOT EXISTS (
|
sl@0
|
115 |
SELECT person_id FROM directors d1 WHERE d1.person_id=d.person_id
|
sl@0
|
116 |
EXCEPT
|
sl@0
|
117 |
SELECT person_id FROM writers w
|
sl@0
|
118 |
);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
} {wilma}
|
sl@0
|
121 |
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
finish_test
|