OLD | NEW |
1 # 2001 September 15 | 1 # 2001 September 15 |
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 #*********************************************************************** |
(...skipping 24 matching lines...) Expand all Loading... |
35 INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1; | 35 INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1; |
36 } | 36 } |
37 } else { | 37 } else { |
38 set maxy [execsql {select max(y) from t1}] | 38 set maxy [execsql {select max(y) from t1}] |
39 execsql " | 39 execsql " |
40 INSERT INTO t2 SELECT 101-w, x, $maxy+1-y, y FROM t1; | 40 INSERT INTO t2 SELECT 101-w, x, $maxy+1-y, y FROM t1; |
41 " | 41 " |
42 } | 42 } |
43 | 43 |
44 execsql { | 44 execsql { |
45 CREATE INDEX i1w ON t1(w); | 45 CREATE INDEX i1w ON t1("w"); -- Verify quoted identifier names |
46 CREATE INDEX i1xy ON t1(x,y); | 46 CREATE INDEX i1xy ON t1(`x`,'y' ASC); -- Old MySQL compatibility |
47 CREATE INDEX i2p ON t2(p); | 47 CREATE INDEX i2p ON t2(p); |
48 CREATE INDEX i2r ON t2(r); | 48 CREATE INDEX i2r ON t2(r); |
49 CREATE INDEX i2qs ON t2(q, s); | 49 CREATE INDEX i2qs ON t2(q, s); |
50 } | 50 } |
51 } {} | 51 } {} |
52 | 52 |
53 # Do an SQL statement. Append the search count to the end of the result. | 53 # Do an SQL statement. Append the search count to the end of the result. |
54 # | 54 # |
55 proc count sql { | 55 proc count sql { |
56 set ::sqlite_search_count 0 | 56 set ::sqlite_search_count 0 |
57 return [concat [execsql $sql] $::sqlite_search_count] | 57 return [concat [execsql $sql] $::sqlite_search_count] |
58 } | 58 } |
59 | 59 |
60 # Verify that queries use an index. We are using the special variable | 60 # Verify that queries use an index. We are using the special variable |
61 # "sqlite_search_count" which tallys the number of executions of MoveTo | 61 # "sqlite_search_count" which tallys the number of executions of MoveTo |
62 # and Next operators in the VDBE. By verifing that the search count is | 62 # and Next operators in the VDBE. By verifing that the search count is |
63 # small we can be assured that indices are being used properly. | 63 # small we can be assured that indices are being used properly. |
64 # | 64 # |
65 do_test where-1.1.1 { | 65 do_test where-1.1.1 { |
66 count {SELECT x, y, w FROM t1 WHERE w=10} | 66 count {SELECT x, y, w FROM t1 WHERE w=10} |
67 } {3 121 10 3} | 67 } {3 121 10 3} |
| 68 do_test where-1.1.1b { |
| 69 count {SELECT x, y, w FROM t1 WHERE w IS 10} |
| 70 } {3 121 10 3} |
68 do_eqp_test where-1.1.2 { | 71 do_eqp_test where-1.1.2 { |
69 SELECT x, y, w FROM t1 WHERE w=10 | 72 SELECT x, y, w FROM t1 WHERE w=10 |
70 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} | 73 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} |
| 74 do_eqp_test where-1.1.2b { |
| 75 SELECT x, y, w FROM t1 WHERE w IS 10 |
| 76 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} |
71 do_test where-1.1.3 { | 77 do_test where-1.1.3 { |
72 db status step | 78 db status step |
73 } {0} | 79 } {0} |
74 do_test where-1.1.4 { | 80 do_test where-1.1.4 { |
75 db eval {SELECT x, y, w FROM t1 WHERE +w=10} | 81 db eval {SELECT x, y, w FROM t1 WHERE +w=10} |
76 } {3 121 10} | 82 } {3 121 10} |
77 do_test where-1.1.5 { | 83 do_test where-1.1.5 { |
78 db status step | 84 db status step |
79 } {99} | 85 } {99} |
80 do_eqp_test where-1.1.6 { | 86 do_eqp_test where-1.1.6 { |
(...skipping 13 matching lines...) Expand all Loading... |
94 } {3 144 11 3} | 100 } {3 144 11 3} |
95 do_test where-1.2.2 { | 101 do_test where-1.2.2 { |
96 count {SELECT x, y, w AS abc FROM t1 WHERE abc=11} | 102 count {SELECT x, y, w AS abc FROM t1 WHERE abc=11} |
97 } {3 144 11 3} | 103 } {3 144 11 3} |
98 do_test where-1.3.1 { | 104 do_test where-1.3.1 { |
99 count {SELECT x, y, w AS abc FROM t1 WHERE 11=w} | 105 count {SELECT x, y, w AS abc FROM t1 WHERE 11=w} |
100 } {3 144 11 3} | 106 } {3 144 11 3} |
101 do_test where-1.3.2 { | 107 do_test where-1.3.2 { |
102 count {SELECT x, y, w AS abc FROM t1 WHERE 11=abc} | 108 count {SELECT x, y, w AS abc FROM t1 WHERE 11=abc} |
103 } {3 144 11 3} | 109 } {3 144 11 3} |
| 110 do_test where-1.3.3 { |
| 111 count {SELECT x, y, w AS abc FROM t1 WHERE 11 IS abc} |
| 112 } {3 144 11 3} |
104 do_test where-1.4.1 { | 113 do_test where-1.4.1 { |
105 count {SELECT w, x, y FROM t1 WHERE 11=w AND x>2} | 114 count {SELECT w, x, y FROM t1 WHERE 11=w AND x>2} |
106 } {11 3 144 3} | 115 } {11 3 144 3} |
| 116 do_test where-1.4.1b { |
| 117 count {SELECT w, x, y FROM t1 WHERE 11 IS w AND x>2} |
| 118 } {11 3 144 3} |
107 do_eqp_test where-1.4.2 { | 119 do_eqp_test where-1.4.2 { |
108 SELECT w, x, y FROM t1 WHERE 11=w AND x>2 | 120 SELECT w, x, y FROM t1 WHERE 11=w AND x>2 |
109 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} | 121 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} |
| 122 do_eqp_test where-1.4.2b { |
| 123 SELECT w, x, y FROM t1 WHERE 11 IS w AND x>2 |
| 124 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} |
110 do_test where-1.4.3 { | 125 do_test where-1.4.3 { |
111 count {SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2} | 126 count {SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2} |
112 } {11 3 144 3} | 127 } {11 3 144 3} |
113 do_eqp_test where-1.4.4 { | 128 do_eqp_test where-1.4.4 { |
114 SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2 | 129 SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2 |
115 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} | 130 } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*} |
116 do_test where-1.5 { | 131 do_test where-1.5 { |
117 count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2} | 132 count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2} |
118 } {3 144 3} | 133 } {3 144 3} |
119 do_eqp_test where-1.5.2 { | 134 do_eqp_test where-1.5.2 { |
(...skipping 16 matching lines...) Expand all Loading... |
136 } {*SEARCH TABLE t1 USING COVERING INDEX i1xy (x=? AND y=?)*} | 151 } {*SEARCH TABLE t1 USING COVERING INDEX i1xy (x=? AND y=?)*} |
137 do_test where-1.9 { | 152 do_test where-1.9 { |
138 count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3} | 153 count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3} |
139 } {3 144 3} | 154 } {3 144 3} |
140 do_test where-1.10 { | 155 do_test where-1.10 { |
141 count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121} | 156 count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121} |
142 } {3 121 3} | 157 } {3 121 3} |
143 do_test where-1.11 { | 158 do_test where-1.11 { |
144 count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10} | 159 count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10} |
145 } {3 100 3} | 160 } {3 100 3} |
| 161 do_test where-1.11b { |
| 162 count {SELECT x, y FROM t1 WHERE x IS 3 AND y IS 100 AND w<10} |
| 163 } {3 100 3} |
146 | 164 |
147 # New for SQLite version 2.1: Verify that that inequality constraints | 165 # New for SQLite version 2.1: Verify that that inequality constraints |
148 # are used correctly. | 166 # are used correctly. |
149 # | 167 # |
150 do_test where-1.12 { | 168 do_test where-1.12 { |
151 count {SELECT w FROM t1 WHERE x=3 AND y<100} | 169 count {SELECT w FROM t1 WHERE x=3 AND y<100} |
152 } {8 3} | 170 } {8 3} |
| 171 do_test where-1.12b { |
| 172 count {SELECT w FROM t1 WHERE x IS 3 AND y<100} |
| 173 } {8 3} |
153 do_test where-1.13 { | 174 do_test where-1.13 { |
154 count {SELECT w FROM t1 WHERE x=3 AND 100>y} | 175 count {SELECT w FROM t1 WHERE x=3 AND 100>y} |
155 } {8 3} | 176 } {8 3} |
156 do_test where-1.14 { | 177 do_test where-1.14 { |
157 count {SELECT w FROM t1 WHERE 3=x AND y<100} | 178 count {SELECT w FROM t1 WHERE 3=x AND y<100} |
158 } {8 3} | 179 } {8 3} |
| 180 do_test where-1.14b { |
| 181 count {SELECT w FROM t1 WHERE 3 IS x AND y<100} |
| 182 } {8 3} |
159 do_test where-1.15 { | 183 do_test where-1.15 { |
160 count {SELECT w FROM t1 WHERE 3=x AND 100>y} | 184 count {SELECT w FROM t1 WHERE 3=x AND 100>y} |
161 } {8 3} | 185 } {8 3} |
162 do_test where-1.16 { | 186 do_test where-1.16 { |
163 count {SELECT w FROM t1 WHERE x=3 AND y<=100} | 187 count {SELECT w FROM t1 WHERE x=3 AND y<=100} |
164 } {8 9 5} | 188 } {8 9 5} |
165 do_test where-1.17 { | 189 do_test where-1.17 { |
166 count {SELECT w FROM t1 WHERE x=3 AND 100>=y} | 190 count {SELECT w FROM t1 WHERE x=3 AND 100>=y} |
167 } {8 9 5} | 191 } {8 9 5} |
168 do_test where-1.18 { | 192 do_test where-1.18 { |
169 count {SELECT w FROM t1 WHERE x=3 AND y>225} | 193 count {SELECT w FROM t1 WHERE x=3 AND y>225} |
170 } {15 3} | 194 } {15 3} |
| 195 do_test where-1.18b { |
| 196 count {SELECT w FROM t1 WHERE x IS 3 AND y>225} |
| 197 } {15 3} |
171 do_test where-1.19 { | 198 do_test where-1.19 { |
172 count {SELECT w FROM t1 WHERE x=3 AND 225<y} | 199 count {SELECT w FROM t1 WHERE x=3 AND 225<y} |
173 } {15 3} | 200 } {15 3} |
174 do_test where-1.20 { | 201 do_test where-1.20 { |
175 count {SELECT w FROM t1 WHERE x=3 AND y>=225} | 202 count {SELECT w FROM t1 WHERE x=3 AND y>=225} |
176 } {14 15 5} | 203 } {14 15 5} |
177 do_test where-1.21 { | 204 do_test where-1.21 { |
178 count {SELECT w FROM t1 WHERE x=3 AND 225<=y} | 205 count {SELECT w FROM t1 WHERE x=3 AND 225<=y} |
179 } {14 15 5} | 206 } {14 15 5} |
180 do_test where-1.22 { | 207 do_test where-1.22 { |
181 count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196} | 208 count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196} |
182 } {11 12 5} | 209 } {11 12 5} |
| 210 do_test where-1.22b { |
| 211 count {SELECT w FROM t1 WHERE x IS 3 AND y>121 AND y<196} |
| 212 } {11 12 5} |
183 do_test where-1.23 { | 213 do_test where-1.23 { |
184 count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196} | 214 count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196} |
185 } {10 11 12 13 9} | 215 } {10 11 12 13 9} |
186 do_test where-1.24 { | 216 do_test where-1.24 { |
187 count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y} | 217 count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y} |
188 } {11 12 5} | 218 } {11 12 5} |
189 do_test where-1.25 { | 219 do_test where-1.25 { |
190 count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y} | 220 count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y} |
191 } {10 11 12 13 9} | 221 } {10 11 12 13 9} |
192 | 222 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } {1 0 4 2 1 9 3 1 16 4} | 405 } {1 0 4 2 1 9 3 1 16 4} |
376 do_test where-5.2 { | 406 do_test where-5.2 { |
377 count { | 407 count { |
378 SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1; | 408 SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1; |
379 } | 409 } |
380 } {1 0 4 2 1 9 3 1 16 102} | 410 } {1 0 4 2 1 9 3 1 16 102} |
381 do_test where-5.3a { | 411 do_test where-5.3a { |
382 count { | 412 count { |
383 SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1; | 413 SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1; |
384 } | 414 } |
385 } {1 0 4 2 1 9 3 1 16 13} | 415 } {1 0 4 2 1 9 3 1 16 12} |
386 do_test where-5.3b { | 416 do_test where-5.3b { |
387 count { | 417 count { |
388 SELECT * FROM t1 WHERE w IN (3,-1,1,2) order by 1; | 418 SELECT * FROM t1 WHERE w IN (3,-1,1,2) order by 1; |
389 } | 419 } |
390 } {1 0 4 2 1 9 3 1 16 13} | 420 } {1 0 4 2 1 9 3 1 16 12} |
391 do_test where-5.3c { | 421 do_test where-5.3c { |
392 count { | 422 count { |
393 SELECT * FROM t1 WHERE w IN (3,2,-1,1,2) order by 1; | 423 SELECT * FROM t1 WHERE w IN (3,2,-1,1,2) order by 1; |
394 } | 424 } |
395 } {1 0 4 2 1 9 3 1 16 13} | 425 } {1 0 4 2 1 9 3 1 16 12} |
396 do_test where-5.3d { | 426 do_test where-5.3d { |
397 count { | 427 count { |
398 SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1 DESC; | 428 SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1 DESC; |
399 } | 429 } |
400 } {3 1 16 2 1 9 1 0 4 12} | 430 } {3 1 16 2 1 9 1 0 4 11} |
401 do_test where-5.4 { | 431 do_test where-5.4 { |
402 count { | 432 count { |
403 SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1; | 433 SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1; |
404 } | 434 } |
405 } {1 0 4 2 1 9 3 1 16 102} | 435 } {1 0 4 2 1 9 3 1 16 102} |
406 do_test where-5.5 { | 436 do_test where-5.5 { |
407 count { | 437 count { |
408 SELECT * FROM t1 WHERE rowid IN | 438 SELECT * FROM t1 WHERE rowid IN |
409 (select rowid from t1 where rowid IN (-1,2,4)) | 439 (select rowid from t1 where rowid IN (-1,2,4)) |
410 ORDER BY 1; | 440 ORDER BY 1; |
(...skipping 17 matching lines...) Expand all Loading... |
428 count { | 458 count { |
429 SELECT * FROM t1 WHERE w+0 IN | 459 SELECT * FROM t1 WHERE w+0 IN |
430 (select rowid from t1 where rowid IN (-1,2,4)) | 460 (select rowid from t1 where rowid IN (-1,2,4)) |
431 ORDER BY 1; | 461 ORDER BY 1; |
432 } | 462 } |
433 } {2 1 9 4 2 25 103} | 463 } {2 1 9 4 2 25 103} |
434 do_test where-5.9 { | 464 do_test where-5.9 { |
435 count { | 465 count { |
436 SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1; | 466 SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1; |
437 } | 467 } |
438 } {2 1 9 3 1 16 7} | 468 } {2 1 9 3 1 16 6} |
439 do_test where-5.10 { | 469 do_test where-5.10 { |
440 count { | 470 count { |
441 SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1; | 471 SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1; |
442 } | 472 } |
443 } {2 1 9 3 1 16 199} | 473 } {2 1 9 3 1 16 199} |
444 do_test where-5.11 { | 474 do_test where-5.11 { |
445 count { | 475 count { |
446 SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1; | 476 SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1; |
447 } | 477 } |
448 } {79 6 6400 89 6 8100 199} | 478 } {79 6 6400 89 6 8100 199} |
449 do_test where-5.12 { | 479 do_test where-5.12 { |
450 count { | 480 count { |
451 SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1; | 481 SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1; |
452 } | 482 } |
453 } {79 6 6400 89 6 8100 7} | 483 } {79 6 6400 89 6 8100 7} |
454 do_test where-5.13 { | 484 do_test where-5.13 { |
455 count { | 485 count { |
456 SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1; | 486 SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1; |
457 } | 487 } |
458 } {2 1 9 3 1 16 7} | 488 } {2 1 9 3 1 16 6} |
459 do_test where-5.14 { | 489 do_test where-5.14 { |
460 count { | 490 count { |
461 SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1; | 491 SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1; |
462 } | 492 } |
463 } {2 1 9 8} | 493 } {2 1 9 5} |
464 do_test where-5.15 { | 494 do_test where-5.15 { |
465 count { | 495 count { |
466 SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,16) ORDER BY 1; | 496 SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,16) ORDER BY 1; |
467 } | 497 } |
468 } {2 1 9 3 1 16 11} | 498 } {2 1 9 3 1 16 9} |
469 do_test where-5.100 { | 499 do_test where-5.100 { |
470 db eval { | 500 db eval { |
471 SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969) | 501 SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969) |
472 ORDER BY x, y | 502 ORDER BY x, y |
473 } | 503 } |
474 } {2 1 9 54 5 3025 62 5 3969} | 504 } {2 1 9 54 5 3025 62 5 3969} |
475 do_test where-5.101 { | 505 do_test where-5.101 { |
476 db eval { | 506 db eval { |
477 SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969) | 507 SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969) |
478 ORDER BY x DESC, y DESC | 508 ORDER BY x DESC, y DESC |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 INSERT INTO t181 VALUES(2); | 1357 INSERT INTO t181 VALUES(2); |
1328 SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL, +a; | 1358 SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL, +a; |
1329 } {1 2} | 1359 } {1 2} |
1330 do_execsql_test where-18.6 { | 1360 do_execsql_test where-18.6 { |
1331 INSERT INTO t181 VALUES(2); | 1361 INSERT INTO t181 VALUES(2); |
1332 SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +a, +c IS NULL; | 1362 SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +a, +c IS NULL; |
1333 } {1 2} | 1363 } {1 2} |
1334 | 1364 |
1335 | 1365 |
1336 finish_test | 1366 finish_test |
OLD | NEW |