sl@0
|
1 |
# 2005 September 17
|
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 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file implements tests to verify that ticket #1433 has been
|
sl@0
|
14 |
# fixed.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# The problem in ticket #1433 was that the dependencies on the right-hand
|
sl@0
|
17 |
# side of an IN operator were not being checked correctly. So in an
|
sl@0
|
18 |
# expression of the form:
|
sl@0
|
19 |
#
|
sl@0
|
20 |
# t1.x IN (1,t2.b,3)
|
sl@0
|
21 |
#
|
sl@0
|
22 |
# the optimizer was missing the fact that the right-hand side of the IN
|
sl@0
|
23 |
# depended on table t2. It was checking dependencies based on the
|
sl@0
|
24 |
# Expr.pRight field rather than Expr.pList and Expr.pSelect.
|
sl@0
|
25 |
#
|
sl@0
|
26 |
# Such a bug could be verifed using a less elaborate test case. But
|
sl@0
|
27 |
# this test case (from the original bug poster) exercises so many different
|
sl@0
|
28 |
# parts of the system all at once, that it seemed like a good one to
|
sl@0
|
29 |
# include in the test suite.
|
sl@0
|
30 |
#
|
sl@0
|
31 |
# NOTE: Yes, in spite of the name of this file (tkt1443.test) this
|
sl@0
|
32 |
# test is for ticket #1433 not #1443. I mistyped the name when I was
|
sl@0
|
33 |
# creating the file and I had already checked in the file by the wrong
|
sl@0
|
34 |
# name be the time I noticed the error. With CVS it is a really hassle
|
sl@0
|
35 |
# to change filenames, so I'll just leave it as is. No harm done.
|
sl@0
|
36 |
#
|
sl@0
|
37 |
# $Id: tkt1443.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $
|
sl@0
|
38 |
|
sl@0
|
39 |
set testdir [file dirname $argv0]
|
sl@0
|
40 |
source $testdir/tester.tcl
|
sl@0
|
41 |
|
sl@0
|
42 |
ifcapable !subquery||!memorydb {
|
sl@0
|
43 |
finish_test
|
sl@0
|
44 |
return
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
# Construct the sample database.
|
sl@0
|
48 |
#
|
sl@0
|
49 |
do_test tkt1443-1.0 {
|
sl@0
|
50 |
sqlite3 db :memory:
|
sl@0
|
51 |
execsql {
|
sl@0
|
52 |
CREATE TABLE Items(
|
sl@0
|
53 |
itemId integer primary key,
|
sl@0
|
54 |
item str unique
|
sl@0
|
55 |
);
|
sl@0
|
56 |
INSERT INTO "Items" VALUES(0, 'ALL');
|
sl@0
|
57 |
INSERT INTO "Items" VALUES(1, 'double:source');
|
sl@0
|
58 |
INSERT INTO "Items" VALUES(2, 'double');
|
sl@0
|
59 |
INSERT INTO "Items" VALUES(3, 'double:runtime');
|
sl@0
|
60 |
INSERT INTO "Items" VALUES(4, '.*:runtime');
|
sl@0
|
61 |
|
sl@0
|
62 |
CREATE TABLE Labels(
|
sl@0
|
63 |
labelId INTEGER PRIMARY KEY,
|
sl@0
|
64 |
label STR UNIQUE
|
sl@0
|
65 |
);
|
sl@0
|
66 |
INSERT INTO "Labels" VALUES(0, 'ALL');
|
sl@0
|
67 |
INSERT INTO "Labels" VALUES(1, 'localhost@rpl:linux');
|
sl@0
|
68 |
INSERT INTO "Labels" VALUES(2, 'localhost@rpl:branch');
|
sl@0
|
69 |
|
sl@0
|
70 |
CREATE TABLE LabelMap(
|
sl@0
|
71 |
itemId INTEGER,
|
sl@0
|
72 |
labelId INTEGER,
|
sl@0
|
73 |
branchId integer
|
sl@0
|
74 |
);
|
sl@0
|
75 |
INSERT INTO "LabelMap" VALUES(1, 1, 1);
|
sl@0
|
76 |
INSERT INTO "LabelMap" VALUES(2, 1, 1);
|
sl@0
|
77 |
INSERT INTO "LabelMap" VALUES(3, 1, 1);
|
sl@0
|
78 |
INSERT INTO "LabelMap" VALUES(1, 2, 2);
|
sl@0
|
79 |
INSERT INTO "LabelMap" VALUES(2, 2, 3);
|
sl@0
|
80 |
INSERT INTO "LabelMap" VALUES(3, 2, 3);
|
sl@0
|
81 |
|
sl@0
|
82 |
CREATE TABLE Users (
|
sl@0
|
83 |
userId INTEGER PRIMARY KEY,
|
sl@0
|
84 |
user STRING UNIQUE,
|
sl@0
|
85 |
salt BINARY,
|
sl@0
|
86 |
password STRING
|
sl@0
|
87 |
);
|
sl@0
|
88 |
INSERT INTO "Users" VALUES(1, 'test', 'æ$d',
|
sl@0
|
89 |
'43ba0f45014306bd6df529551ffdb3df');
|
sl@0
|
90 |
INSERT INTO "Users" VALUES(2, 'limited', 'ª>S',
|
sl@0
|
91 |
'cf07c8348fdf675cc1f7696b7d45191b');
|
sl@0
|
92 |
CREATE TABLE UserGroups (
|
sl@0
|
93 |
userGroupId INTEGER PRIMARY KEY,
|
sl@0
|
94 |
userGroup STRING UNIQUE
|
sl@0
|
95 |
);
|
sl@0
|
96 |
INSERT INTO "UserGroups" VALUES(1, 'test');
|
sl@0
|
97 |
INSERT INTO "UserGroups" VALUES(2, 'limited');
|
sl@0
|
98 |
|
sl@0
|
99 |
CREATE TABLE UserGroupMembers (
|
sl@0
|
100 |
userGroupId INTEGER,
|
sl@0
|
101 |
userId INTEGER
|
sl@0
|
102 |
);
|
sl@0
|
103 |
INSERT INTO "UserGroupMembers" VALUES(1, 1);
|
sl@0
|
104 |
INSERT INTO "UserGroupMembers" VALUES(2, 2);
|
sl@0
|
105 |
|
sl@0
|
106 |
CREATE TABLE Permissions (
|
sl@0
|
107 |
userGroupId INTEGER,
|
sl@0
|
108 |
labelId INTEGER NOT NULL,
|
sl@0
|
109 |
itemId INTEGER NOT NULL,
|
sl@0
|
110 |
write INTEGER,
|
sl@0
|
111 |
capped INTEGER,
|
sl@0
|
112 |
admin INTEGER
|
sl@0
|
113 |
);
|
sl@0
|
114 |
INSERT INTO "Permissions" VALUES(1, 0, 0, 1, 0, 1);
|
sl@0
|
115 |
INSERT INTO "Permissions" VALUES(2, 2, 4, 0, 0, 0);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
} {}
|
sl@0
|
118 |
|
sl@0
|
119 |
# Run the query with an index
|
sl@0
|
120 |
#
|
sl@0
|
121 |
do_test tkt1443-1.1 {
|
sl@0
|
122 |
execsql {
|
sl@0
|
123 |
select distinct
|
sl@0
|
124 |
Items.Item as trove, UP.pattern as pattern
|
sl@0
|
125 |
from
|
sl@0
|
126 |
( select
|
sl@0
|
127 |
Permissions.labelId as labelId,
|
sl@0
|
128 |
PerItems.item as pattern
|
sl@0
|
129 |
from
|
sl@0
|
130 |
Users, UserGroupMembers, Permissions
|
sl@0
|
131 |
left outer join Items as PerItems
|
sl@0
|
132 |
on Permissions.itemId = PerItems.itemId
|
sl@0
|
133 |
where
|
sl@0
|
134 |
Users.user = 'limited'
|
sl@0
|
135 |
and Users.userId = UserGroupMembers.userId
|
sl@0
|
136 |
and UserGroupMembers.userGroupId = Permissions.userGroupId
|
sl@0
|
137 |
) as UP join LabelMap on ( UP.labelId = 0 or
|
sl@0
|
138 |
UP.labelId = LabelMap.labelId ),
|
sl@0
|
139 |
Labels, Items
|
sl@0
|
140 |
where
|
sl@0
|
141 |
Labels.label = 'localhost@rpl:branch'
|
sl@0
|
142 |
and Labels.labelId = LabelMap.labelId
|
sl@0
|
143 |
and LabelMap.itemId = Items.itemId
|
sl@0
|
144 |
ORDER BY +trove, +pattern
|
sl@0
|
145 |
}
|
sl@0
|
146 |
} {double .*:runtime double:runtime .*:runtime double:source .*:runtime}
|
sl@0
|
147 |
|
sl@0
|
148 |
# Create an index and rerun the query.
|
sl@0
|
149 |
# Verify that the results are the same
|
sl@0
|
150 |
#
|
sl@0
|
151 |
do_test tkt1443-1.2 {
|
sl@0
|
152 |
execsql {
|
sl@0
|
153 |
CREATE UNIQUE INDEX PermissionsIdx
|
sl@0
|
154 |
ON Permissions(userGroupId, labelId, itemId);
|
sl@0
|
155 |
select distinct
|
sl@0
|
156 |
Items.Item as trove, UP.pattern as pattern
|
sl@0
|
157 |
from
|
sl@0
|
158 |
( select
|
sl@0
|
159 |
Permissions.labelId as labelId,
|
sl@0
|
160 |
PerItems.item as pattern
|
sl@0
|
161 |
from
|
sl@0
|
162 |
Users, UserGroupMembers, Permissions
|
sl@0
|
163 |
left outer join Items as PerItems
|
sl@0
|
164 |
on Permissions.itemId = PerItems.itemId
|
sl@0
|
165 |
where
|
sl@0
|
166 |
Users.user = 'limited'
|
sl@0
|
167 |
and Users.userId = UserGroupMembers.userId
|
sl@0
|
168 |
and UserGroupMembers.userGroupId = Permissions.userGroupId
|
sl@0
|
169 |
) as UP join LabelMap on ( UP.labelId = 0 or
|
sl@0
|
170 |
UP.labelId = LabelMap.labelId ),
|
sl@0
|
171 |
Labels, Items
|
sl@0
|
172 |
where
|
sl@0
|
173 |
Labels.label = 'localhost@rpl:branch'
|
sl@0
|
174 |
and Labels.labelId = LabelMap.labelId
|
sl@0
|
175 |
and LabelMap.itemId = Items.itemId
|
sl@0
|
176 |
ORDER BY +trove, +pattern
|
sl@0
|
177 |
}
|
sl@0
|
178 |
} {double .*:runtime double:runtime .*:runtime double:source .*:runtime}
|
sl@0
|
179 |
|
sl@0
|
180 |
finish_test
|