OLD | NEW |
1 # 2008 December 23 | 1 # 2008 December 23 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. The focus | 11 # This file implements regression tests for SQLite library. The focus |
12 # is testing of where.c. More specifically, the focus is the optimization | 12 # is testing of where.c. More specifically, the focus is the optimization |
13 # of WHERE clauses that feature the OR operator. | 13 # of WHERE clauses that feature the OR operator. |
14 # | 14 # |
15 # $Id: where8.test,v 1.9 2009/07/31 06:14:52 danielk1977 Exp $ | |
16 | 15 |
17 set testdir [file dirname $argv0] | 16 set testdir [file dirname $argv0] |
18 source $testdir/tester.tcl | 17 source $testdir/tester.tcl |
19 | 18 |
20 # Test organization: | 19 # Test organization: |
21 # | 20 # |
22 # where8-1.*: Tests to demonstrate simple cases work with a single table | 21 # where8-1.*: Tests to demonstrate simple cases work with a single table |
23 # in the FROM clause. | 22 # in the FROM clause. |
24 # | 23 # |
25 # where8-2.*: Tests surrounding virtual tables and the OR optimization. | 24 # where8-2.*: Tests surrounding virtual tables and the OR optimization. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 execsql_status { SELECT c FROM t1 WHERE a = 1 OR b = 'three' ORDER BY a } | 80 execsql_status { SELECT c FROM t1 WHERE a = 1 OR b = 'three' ORDER BY a } |
82 } {I III 0 1} | 81 } {I III 0 1} |
83 | 82 |
84 do_test where8-1.8 { | 83 do_test where8-1.8 { |
85 # 18 searches. 9 on the index cursor and 9 on the table cursor. | 84 # 18 searches. 9 on the index cursor and 9 on the table cursor. |
86 execsql_status2 { SELECT c FROM t1 WHERE a > 1 AND c LIKE 'I%' } | 85 execsql_status2 { SELECT c FROM t1 WHERE a > 1 AND c LIKE 'I%' } |
87 } {II III IV IX 0 0 18} | 86 } {II III IV IX 0 0 18} |
88 | 87 |
89 do_test where8-1.9 { | 88 do_test where8-1.9 { |
90 execsql_status2 { SELECT c FROM t1 WHERE a >= 9 OR b <= 'eight' } | 89 execsql_status2 { SELECT c FROM t1 WHERE a >= 9 OR b <= 'eight' } |
91 } {IX X VIII 0 0 6} | 90 } {IX X VIII 0 0 7} |
92 | 91 |
93 do_test where8-1.10 { | 92 do_test where8-1.10 { |
94 execsql_status2 { | 93 execsql_status2 { |
95 SELECT c FROM t1 WHERE (a >= 9 AND c != 'X') OR b <= 'eight' | 94 SELECT c FROM t1 WHERE (a >= 9 AND c != 'X') OR b <= 'eight' |
96 } | 95 } |
97 } {IX VIII 0 0 6} | 96 } {IX VIII 0 0 7} |
98 | 97 |
99 do_test where8-1.11 { | 98 do_test where8-1.11 { |
100 execsql_status2 { | 99 execsql_status2 { |
101 SELECT c FROM t1 WHERE (a >= 4 AND a <= 6) OR b = 'nine' | 100 SELECT c FROM t1 WHERE (a >= 4 AND a <= 6) OR b = 'nine' |
102 } | 101 } |
103 } {IV V VI IX 0 0 10} | 102 } {IV V VI IX 0 0 10} |
104 | 103 |
105 do_test where8-1.12.1 { | 104 do_test where8-1.12.1 { |
106 execsql_status2 { | 105 execsql_status2 { |
107 SELECT c FROM t1 WHERE a IN(1, 2, 3) OR a = 5 | 106 SELECT c FROM t1 WHERE a IN(1, 2, 3) OR a = 5 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } {2 6 3 6 0 0} | 203 } {2 6 3 6 0 0} |
205 | 204 |
206 do_test where8-3.4 { | 205 do_test where8-3.4 { |
207 execsql_status { | 206 execsql_status { |
208 SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND d = a | 207 SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND d = a |
209 } | 208 } |
210 } {2 2 3 3 0 0} | 209 } {2 2 3 3 0 0} |
211 | 210 |
212 do_test where8-3.5 { | 211 do_test where8-3.5 { |
213 execsql_status { | 212 execsql_status { |
214 SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen') | 213 SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = +a OR e = 'sixteen') |
| 214 ORDER BY +a, +d; |
215 } | 215 } |
216 } {2 2 2 4 3 3 3 4 0 0} | 216 } {2 2 2 4 3 3 3 4 0 1} |
217 | 217 |
218 do_test where8-3.6 { | 218 do_test where8-3.6 { |
219 # The first part of the WHERE clause in this query, (a=2 OR a=3) is | 219 # The first part of the WHERE clause in this query, (a=2 OR a=3) is |
220 # transformed into "a IN (2, 3)". This is why the sort is required. | 220 # transformed into "a IN (2, 3)". This is why the sort is required. |
221 # | 221 # |
222 execsql_status { | 222 execsql_status { |
223 SELECT a, d | 223 SELECT a, d |
224 FROM t1, t2 | 224 FROM t1, t2 |
225 WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen') | 225 WHERE (a = 2 OR a = 3) AND (d = +a OR e = 'sixteen') |
226 ORDER BY t1.rowid | 226 ORDER BY t1.rowid |
227 } | 227 } |
228 } {2 2 2 4 3 3 3 4 0 1} | 228 } {2 2 2 4 3 3 3 4 0 1} |
229 do_test where8-3.7 { | 229 do_test where8-3.7 { |
230 execsql_status { | 230 execsql_status { |
231 SELECT a, d | 231 SELECT a, d |
232 FROM t1, t2 | 232 FROM t1, t2 |
233 WHERE a = 2 AND (d = a OR e = 'sixteen') | 233 WHERE a = 2 AND (d = a OR e = 'sixteen') |
234 ORDER BY t1.rowid | 234 ORDER BY t1.rowid |
235 } | 235 } |
236 } {2 2 2 4 0 0} | 236 } {/2 2 2 4 0 [01]/} |
237 do_test where8-3.8 { | 237 do_test where8-3.8 { |
238 execsql_status { | 238 execsql_status { |
239 SELECT a, d | 239 SELECT a, d |
240 FROM t1, t2 | 240 FROM t1, t2 |
241 WHERE (a = 2 OR b = 'three') AND (d = a OR e = 'sixteen') | 241 WHERE (a = 2 OR b = 'three') AND (d = a OR e = 'sixteen') |
242 ORDER BY t1.rowid | 242 ORDER BY t1.rowid |
243 } | 243 } |
244 } {2 2 2 4 3 3 3 4 0 1} | 244 } {2 2 2 4 3 3 3 4 0 1} |
245 | 245 |
246 do_test where8-3.9 { | 246 do_test where8-3.9 { |
(...skipping 14 matching lines...) Expand all Loading... |
261 | 261 |
262 do_test where8-3.11 { | 262 do_test where8-3.11 { |
263 execsql_status { | 263 execsql_status { |
264 SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND a<5 ORDER BY a | 264 SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND a<5 ORDER BY a |
265 } | 265 } |
266 } {1 1 2 2 3 3 4 2 4 4 0 0} | 266 } {1 1 2 2 3 3 4 2 4 4 0 0} |
267 do_test where8-3.12 { | 267 do_test where8-3.12 { |
268 execsql_status { | 268 execsql_status { |
269 SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 ORDER BY a | 269 SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 ORDER BY a |
270 } | 270 } |
271 } {1 1 2 2 3 3 4 2 4 4 0 0} | 271 } {1 1 2 2 3 3 4 2 4 4 9 0} |
272 do_test where8-3.13 { | 272 do_test where8-3.13 { |
273 execsql_status { | 273 execsql_status { |
274 SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 | 274 SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 |
275 } | 275 } |
276 } {1 1 2 2 3 3 4 2 4 4 9 0} | 276 } {1 1 2 2 3 3 4 2 4 4 9 0} |
277 | 277 |
278 do_test where8-3.14 { | 278 do_test where8-3.14 { |
279 execsql_status { | 279 execsql_status { |
280 SELECT c FROM t1 WHERE a > (SELECT d FROM t2 WHERE e = b) OR a = 5 | 280 SELECT c FROM t1 WHERE a > (SELECT d FROM t2 WHERE e = b) OR a = 5 |
281 } | 281 } |
282 } {IV V 9 0} | 282 } {IV V 9 0} |
283 | 283 |
284 do_test where8-3.15 { | 284 do_test where8-3.15 { |
285 execsql_status { | 285 execsql_status { |
286 SELECT c FROM t1, t2 WHERE a BETWEEN 1 AND 2 OR a = ( | 286 SELECT c FROM t1, t2 WHERE a BETWEEN 1 AND 2 OR a = ( |
287 SELECT sum(e IS NULL) FROM t2 AS inner WHERE t2.d>inner.d | 287 SELECT sum(e IS NULL) FROM t2 AS inner WHERE t2.d>inner.d |
288 ) | 288 ) |
289 ORDER BY c | 289 ORDER BY c |
290 } | 290 } |
291 } {I I I I I I I I I I II II II II II II II II II II III III III III III 9 1} | 291 } {I I I I I I I I I I II II II II II II II II II II III III III III III 9 1} |
292 | 292 |
| 293 |
| 294 do_test where8-3.21 { |
| 295 execsql_status { |
| 296 SELECT a, d FROM t1, (t2) WHERE (a=d OR b=e) AND a<5 ORDER BY a |
| 297 } |
| 298 } {1 1 2 2 3 3 4 2 4 4 0 0} |
| 299 do_test where8-3.21.1 { |
| 300 execsql_status { |
| 301 SELECT a, d FROM t1, ((t2)) AS t3 WHERE (a=d OR b=e) AND a<5 ORDER BY a |
| 302 } |
| 303 } {1 1 2 2 3 3 4 2 4 4 0 0} |
| 304 if {[permutation] != "no_optimization"} { |
| 305 do_test where8-3.21.2 { |
| 306 execsql_status { |
| 307 SELECT a, d FROM t1, ((SELECT * FROM t2)) AS t3 WHERE (a=d OR b=e) AND a<5 O
RDER BY a |
| 308 } |
| 309 } {1 1 2 2 3 3 4 2 4 4 0 0} |
| 310 } |
| 311 do_test where8-3.22 { |
| 312 execsql_status { |
| 313 SELECT a, d FROM ((((((t1))), (((t2)))))) |
| 314 WHERE (a=d OR b=e) AND a<5 ORDER BY a |
| 315 } |
| 316 } {1 1 2 2 3 3 4 2 4 4 0 0} |
| 317 if {[permutation] != "no_optimization"} { |
| 318 do_test where8-3.23 { |
| 319 execsql_status { |
| 320 SELECT * FROM ((SELECT * FROM t2)) AS t3; |
| 321 } |
| 322 } {1 {} I 2 four IV 3 {} IX 4 sixteen XVI 5 {} XXV 6 thirtysix XXXVI 7 fortynine
XLIX 8 sixtyeight LXIV 9 eightyone LXXXIX 10 {} C 9 0} |
| 323 } |
| 324 |
293 #----------------------------------------------------------------------- | 325 #----------------------------------------------------------------------- |
294 # The following tests - where8-4.* - verify that adding or removing | 326 # The following tests - where8-4.* - verify that adding or removing |
295 # indexes does not change the results returned by various queries. | 327 # indexes does not change the results returned by various queries. |
296 # | 328 # |
297 do_test where8-4.1 { | 329 do_test where8-4.1 { |
298 execsql { | 330 execsql { |
299 BEGIN; | 331 BEGIN; |
300 CREATE TABLE t3(a INTEGER, b REAL, c TEXT); | 332 CREATE TABLE t3(a INTEGER, b REAL, c TEXT); |
301 CREATE TABLE t4(f INTEGER, g REAL, h TEXT); | 333 CREATE TABLE t4(f INTEGER, g REAL, h TEXT); |
302 INSERT INTO t3 VALUES('hills', NULL, 1415926535); | 334 INSERT INTO t3 VALUES('hills', NULL, 1415926535); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 741 } |
710 execsql { | 742 execsql { |
711 SELECT a, x FROM tA LEFT JOIN tB ON ( | 743 SELECT a, x FROM tA LEFT JOIN tB ON ( |
712 a=1 AND b=2 AND c=3 AND d=4 AND e=5 AND f=6 AND g=7 AND h=8 AND | 744 a=1 AND b=2 AND c=3 AND d=4 AND e=5 AND f=6 AND g=7 AND h=8 AND |
713 i=1 AND j=2 AND k=3 AND l=4 AND m=5 AND n=6 AND o=7 AND | 745 i=1 AND j=2 AND k=3 AND l=4 AND m=5 AND n=6 AND o=7 AND |
714 (p = 1 OR p = 2 OR p = 3) | 746 (p = 1 OR p = 2 OR p = 3) |
715 ) | 747 ) |
716 } | 748 } |
717 } {1 {}} | 749 } {1 {}} |
718 | 750 |
| 751 # The OR optimization and WITHOUT ROWID |
| 752 # |
| 753 do_execsql_test where8-6.1 { |
| 754 CREATE TABLE t600(a PRIMARY KEY, b) WITHOUT rowid; |
| 755 CREATE INDEX t600b ON t600(b); |
| 756 INSERT INTO t600 VALUES('state','screen'),('exact','dolphin'),('green','mercur
y'); |
| 757 SELECT a, b, '|' FROM t600 WHERE a=='state' OR b='mercury' ORDER BY +a; |
| 758 } {green mercury | state screen |} |
| 759 |
719 finish_test | 760 finish_test |
OLD | NEW |