interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / tkt-80ba201079.test

173 lines · 5461 bytes Raw Blame History
1# 2010 December 6
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. Specifically,
12# it tests that ticket [80ba201079ea608071d22a57856b940ea3ac53ce] is
13# resolved. That ticket is about an incorrect result that appears when
14# an index is added. The root cause is that a constant is being used
15# without initialization when the OR optimization applies in the WHERE clause.
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20set ::testprefix tkt-80ba201079
21
22do_test tkt-80ba2-100 {
23 db eval {
24 CREATE TABLE t1(a);
25 INSERT INTO t1 VALUES('A');
26 CREATE TABLE t2(b);
27 INSERT INTO t2 VALUES('B');
28 CREATE TABLE t3(c);
29 INSERT INTO t3 VALUES('C');
30 SELECT * FROM t1, t2
31 WHERE (a='A' AND b='X')
32 OR (a='A' AND EXISTS (SELECT * FROM t3 WHERE c='C'));
33 }
34} {A B}
35do_test tkt-80ba2-101 {
36 db eval {
37 CREATE INDEX i1 ON t1(a);
38 SELECT * FROM t1, t2
39 WHERE (a='A' AND b='X')
40 OR (a='A' AND EXISTS (SELECT * FROM t3 WHERE c='C'));
41 }
42} {A B}
43do_test tkt-80ba2-102 {
44 db cache flush
45 db eval {
46 SELECT * FROM t1, t2
47 WHERE (a='A' AND b='X')
48 OR (a='A' AND EXISTS (SELECT * FROM t3 WHERE c='C'));
49 }
50} {A B}
51
52do_test tkt-80ba2-200 {
53 db eval {
54 CREATE TABLE entry_types (
55 id integer primary key,
56 name text
57 );
58 INSERT INTO "entry_types" VALUES(100,'cli_command');
59 INSERT INTO "entry_types" VALUES(300,'object_change');
60 CREATE TABLE object_changes (
61 change_id integer primary key,
62 system_id int,
63 obj_id int,
64 obj_context text,
65 change_type int,
66 command_id int
67 );
68 INSERT INTO "object_changes" VALUES(1551,1,114608,'exported_pools',1,2114);
69 INSERT INTO "object_changes" VALUES(2048,1,114608,'exported_pools',2,2319);
70 CREATE TABLE timeline (
71 rowid integer primary key,
72 timestamp text,
73 system_id int,
74 entry_type int,
75 entry_id int
76 );
77 INSERT INTO "timeline" VALUES(6735,'2010-11-21 17:08:27.000',1,300,2048);
78 INSERT INTO "timeline" VALUES(6825,'2010-11-21 17:09:21.000',1,300,2114);
79 SELECT entry_type,
80 entry_types.name,
81 entry_id
82 FROM timeline JOIN entry_types ON entry_type = entry_types.id
83 WHERE (entry_types.name = 'cli_command' AND entry_id=2114)
84 OR (entry_types.name = 'object_change'
85 AND entry_id IN (SELECT change_id
86 FROM object_changes
87 WHERE obj_context = 'exported_pools'));
88 }
89} {300 object_change 2048}
90do_test tkt-80ba2-201 {
91 db eval {
92 CREATE INDEX timeline_entry_id_idx on timeline(entry_id);
93 SELECT entry_type,
94 entry_types.name,
95 entry_id
96 FROM timeline JOIN entry_types ON entry_type = entry_types.id
97 WHERE (entry_types.name = 'cli_command' AND entry_id=2114)
98 OR (entry_types.name = 'object_change'
99 AND entry_id IN (SELECT change_id
100 FROM object_changes
101 WHERE obj_context = 'exported_pools'));
102 }
103} {300 object_change 2048}
104do_test tkt-80ba2-202 {
105 db cache flush
106 db eval {
107 SELECT entry_type,
108 entry_types.name,
109 entry_id
110 FROM timeline JOIN entry_types ON entry_type = entry_types.id
111 WHERE (entry_types.name = 'cli_command' AND entry_id=2114)
112 OR (entry_types.name = 'object_change'
113 AND entry_id IN (SELECT change_id
114 FROM object_changes
115 WHERE obj_context = 'exported_pools'));
116 }
117} {300 object_change 2048}
118
119#-------------------------------------------------------------------------
120#
121
122drop_all_tables
123do_execsql_test 301 {
124 CREATE TABLE t1(a, b, c);
125 CREATE INDEX i1 ON t1(a);
126 CREATE INDEX i2 ON t1(b);
127 CREATE TABLE t2(d, e);
128
129 INSERT INTO t1 VALUES('A', 'B', 'C');
130 INSERT INTO t2 VALUES('D', 'E');
131}
132
133do_execsql_test 302 {
134 SELECT * FROM t1, t2 WHERE
135 (a='A' AND d='E') OR
136 (b='B' AND c IN ('C', 'D', 'E'))
137} {A B C D E}
138
139do_execsql_test 303 {
140 SELECT * FROM t1, t2 WHERE
141 (a='A' AND d='E') OR
142 (b='B' AND c IN (SELECT c FROM t1))
143} {A B C D E}
144
145ifcapable compound {
146 do_execsql_test 304 {
147 SELECT * FROM t1, t2 WHERE
148 (a='A' AND d='E') OR
149 (b='B' AND c IN (SELECT 'B' UNION SELECT 'C' UNION SELECT 'D'))
150 } {A B C D E}
151}
152
153do_execsql_test 305 {
154 SELECT * FROM t1, t2 WHERE
155 (b='B' AND c IN ('C', 'D', 'E')) OR
156 (a='A' AND d='E')
157} {A B C D E}
158
159do_execsql_test 306 {
160 SELECT * FROM t1, t2 WHERE
161 (b='B' AND c IN (SELECT c FROM t1)) OR
162 (a='A' AND d='E')
163} {A B C D E}
164
165ifcapable compound {
166 do_execsql_test 307 {
167 SELECT * FROM t1, t2 WHERE
168 (b='B' AND c IN (SELECT 'B' UNION SELECT 'C' UNION SELECT 'D')) OR
169 (a='A' AND d='E')
170 } {A B C D E}
171}
172
173finish_test