Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/sqlite/src/test/fts3aux1.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2011 January 27 1 # 2011 January 27
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 20 matching lines...) Expand all
31 } 31 }
32 32
33 do_execsql_test 1.2 { 33 do_execsql_test 1.2 {
34 INSERT INTO t1 VALUES('one one one three three three'); 34 INSERT INTO t1 VALUES('one one one three three three');
35 SELECT term, documents, occurrences FROM terms WHERE col = '*'; 35 SELECT term, documents, occurrences FROM terms WHERE col = '*';
36 } { 36 } {
37 five 2 2 four 2 2 one 3 5 seven 1 1 37 five 2 2 four 2 2 one 3 5 seven 1 1
38 six 1 1 three 4 6 two 1 1 38 six 1 1 three 4 6 two 1 1
39 } 39 }
40 40
41 do_execsql_test 1.3 { 41 do_execsql_test 1.3.1 { DELETE FROM t1; }
42 DELETE FROM t1; 42 do_execsql_test 1.3.2 {
43 SELECT term, documents, occurrences FROM terms WHERE col = '*'; 43 SELECT term, documents, occurrences FROM terms WHERE col = '*';
44 } {} 44 }
45 45
46 do_execsql_test 1.4 { 46 do_execsql_test 1.4 {
47 INSERT INTO t1 VALUES('a b a b a b a'); 47 INSERT INTO t1 VALUES('a b a b a b a');
48 INSERT INTO t1 SELECT * FROM t1; 48 INSERT INTO t1 SELECT * FROM t1;
49 INSERT INTO t1 SELECT * FROM t1; 49 INSERT INTO t1 SELECT * FROM t1;
50 INSERT INTO t1 SELECT * FROM t1; 50 INSERT INTO t1 SELECT * FROM t1;
51 INSERT INTO t1 SELECT * FROM t1; 51 INSERT INTO t1 SELECT * FROM t1;
52 INSERT INTO t1 SELECT * FROM t1; 52 INSERT INTO t1 SELECT * FROM t1;
53 INSERT INTO t1 SELECT * FROM t1; 53 INSERT INTO t1 SELECT * FROM t1;
54 INSERT INTO t1 SELECT * FROM t1; 54 INSERT INTO t1 SELECT * FROM t1;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 incr $varname 98 incr $varname
99 return 1 99 return 1
100 } 100 }
101 db func rec rec 101 db func rec rec
102 102
103 # Use EQP to show that the WHERE expression "term='braid'" uses a different 103 # Use EQP to show that the WHERE expression "term='braid'" uses a different
104 # index number (1) than "+term='braid'" (0). 104 # index number (1) than "+term='braid'" (0).
105 # 105 #
106 do_execsql_test 2.1.1.1 { 106 do_execsql_test 2.1.1.1 {
107 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term='braid' 107 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term='braid'
108 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1: (~0 rows)} } 108 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1:} }
109 do_execsql_test 2.1.1.2 { 109 do_execsql_test 2.1.1.2 {
110 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term='braid' 110 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term='braid'
111 } {0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)}} 111 } {0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}}
112 112
113 # Now show that using "term='braid'" means the virtual table returns 113 # Now show that using "term='braid'" means the virtual table returns
114 # only 1 row to SQLite, but "+term='braid'" means all 19 are returned. 114 # only 1 row to SQLite, but "+term='braid'" means all 19 are returned.
115 # 115 #
116 do_test 2.1.2.1 { 116 do_test 2.1.2.1 {
117 set cnt 0 117 set cnt 0
118 execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND term='braid' } 118 execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND term='braid' }
119 set cnt 119 set cnt
120 } {2} 120 } {2}
121 do_test 2.1.2.2 { 121 do_test 2.1.2.2 {
(...skipping 25 matching lines...) Expand all
147 do_execsql_test 2.1.4.6 { SELECT * FROM terms_v WHERE +term='cba' } {} 147 do_execsql_test 2.1.4.6 { SELECT * FROM terms_v WHERE +term='cba' } {}
148 do_execsql_test 2.1.4.7 { SELECT * FROM terms_v WHERE term='abc' } {} 148 do_execsql_test 2.1.4.7 { SELECT * FROM terms_v WHERE term='abc' } {}
149 do_execsql_test 2.1.4.8 { SELECT * FROM terms_v WHERE +term='abc' } {} 149 do_execsql_test 2.1.4.8 { SELECT * FROM terms_v WHERE +term='abc' } {}
150 150
151 # Special case: term=NULL 151 # Special case: term=NULL
152 # 152 #
153 do_execsql_test 2.1.5 { SELECT * FROM terms WHERE term=NULL } {} 153 do_execsql_test 2.1.5 { SELECT * FROM terms WHERE term=NULL } {}
154 154
155 do_execsql_test 2.2.1.1 { 155 do_execsql_test 2.2.1.1 {
156 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term>'brain' 156 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term>'brain'
157 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 2: (~0 rows)} } 157 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 2:} }
158 do_execsql_test 2.2.1.2 { 158 do_execsql_test 2.2.1.2 {
159 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term>'brain' 159 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term>'brain'
160 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} } 160 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:} }
161 161
162 do_execsql_test 2.2.1.3 { 162 do_execsql_test 2.2.1.3 {
163 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term<'brain' 163 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term<'brain'
164 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 4: (~0 rows)} } 164 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 4:} }
165 do_execsql_test 2.2.1.4 { 165 do_execsql_test 2.2.1.4 {
166 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term<'brain' 166 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term<'brain'
167 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} } 167 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:} }
168 168
169 do_execsql_test 2.2.1.5 { 169 do_execsql_test 2.2.1.5 {
170 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term BETWEEN 'brags' AND 'brain' 170 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term BETWEEN 'brags' AND 'brain'
171 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 6: (~0 rows)} } 171 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 6:} }
172 do_execsql_test 2.2.1.6 { 172 do_execsql_test 2.2.1.6 {
173 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term BETWEEN 'brags' AND 'brain' 173 EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term BETWEEN 'brags' AND 'brain'
174 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} } 174 } { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:} }
175 175
176 do_test 2.2.2.1 { 176 do_test 2.2.2.1 {
177 set cnt 0 177 set cnt 0
178 execsql { SELECT * FROM terms WHERE rec('cnt', term) AND term>'brain' } 178 execsql { SELECT * FROM terms WHERE rec('cnt', term) AND term>'brain' }
179 set cnt 179 set cnt
180 } {18} 180 } {18}
181 do_test 2.2.2.2 { 181 do_test 2.2.2.2 {
182 set cnt 0 182 set cnt 0
183 execsql { SELECT * FROM terms WHERE rec('cnt', term) AND +term>'brain' } 183 execsql { SELECT * FROM terms WHERE rec('cnt', term) AND +term>'brain' }
184 set cnt 184 set cnt
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 2 0 "ORDER BY term" 328 2 0 "ORDER BY term"
329 3 1 "ORDER BY term DESC" 329 3 1 "ORDER BY term DESC"
330 4 1 "ORDER BY documents ASC" 330 4 1 "ORDER BY documents ASC"
331 5 1 "ORDER BY documents" 331 5 1 "ORDER BY documents"
332 6 1 "ORDER BY documents DESC" 332 6 1 "ORDER BY documents DESC"
333 7 1 "ORDER BY occurrences ASC" 333 7 1 "ORDER BY occurrences ASC"
334 8 1 "ORDER BY occurrences" 334 8 1 "ORDER BY occurrences"
335 9 1 "ORDER BY occurrences DESC" 335 9 1 "ORDER BY occurrences DESC"
336 } { 336 } {
337 337
338 set res [list 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)}] 338 set res [list 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}]
339 if {$sort} { lappend res 0 0 0 {USE TEMP B-TREE FOR ORDER BY} } 339 if {$sort} { lappend res 0 0 0 {USE TEMP B-TREE FOR ORDER BY} }
340 340
341 set sql "SELECT * FROM terms $orderby" 341 set sql "SELECT * FROM terms $orderby"
342 do_execsql_test 2.3.1.$tn "EXPLAIN QUERY PLAN $sql" $res 342 do_execsql_test 2.3.1.$tn "EXPLAIN QUERY PLAN $sql" $res
343 } 343 }
344 344
345 #------------------------------------------------------------------------- 345 #-------------------------------------------------------------------------
346 # The next set of tests, fts3aux1-3.*, test error conditions in the 346 # The next set of tests, fts3aux1-3.*, test error conditions in the
347 # fts4aux module. Except, fault injection testing (OOM, IO error etc.) is 347 # fts4aux module. Except, fault injection testing (OOM, IO error etc.) is
348 # done in fts3fault2.test 348 # done in fts3fault2.test
349 # 349 #
350 350
351 do_execsql_test 3.1.1 { 351 do_execsql_test 3.1.1 {
352 CREATE VIRTUAL TABLE t2 USING fts4; 352 CREATE VIRTUAL TABLE t2 USING fts4;
353 } 353 }
354 354
355 do_catchsql_test 3.1.2 { 355 do_catchsql_test 3.1.2 {
356 CREATE VIRTUAL TABLE terms2 USING fts4aux; 356 CREATE VIRTUAL TABLE terms2 USING fts4aux;
357 } {1 {wrong number of arguments to fts4aux constructor}} 357 } {1 {invalid arguments to fts4aux constructor}}
358 do_catchsql_test 3.1.3 { 358 do_catchsql_test 3.1.3 {
359 CREATE VIRTUAL TABLE terms2 USING fts4aux(t2, t2); 359 CREATE VIRTUAL TABLE terms2 USING fts4aux(t2, t2);
360 } {1 {wrong number of arguments to fts4aux constructor}} 360 } {1 {invalid arguments to fts4aux constructor}}
361 361
362 do_execsql_test 3.2.1 { 362 do_execsql_test 3.2.1 {
363 CREATE VIRTUAL TABLE terms3 USING fts4aux(does_not_exist) 363 CREATE VIRTUAL TABLE terms3 USING fts4aux(does_not_exist)
364 } 364 }
365 do_catchsql_test 3.2.2 { 365 do_catchsql_test 3.2.2 {
366 SELECT * FROM terms3 366 SELECT * FROM terms3
367 } {1 {SQL logic error or missing database}} 367 } {1 {SQL logic error or missing database}}
368 do_catchsql_test 3.2.3 { 368 do_catchsql_test 3.2.3 {
369 SELECT * FROM terms3 WHERE term = 'abc' 369 SELECT * FROM terms3 WHERE term = 'abc'
370 } {1 {SQL logic error or missing database}} 370 } {1 {SQL logic error or missing database}}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 INSERT INTO x3 SELECT term FROM terms WHERE col = '*'; 403 INSERT INTO x3 SELECT term FROM terms WHERE col = '*';
404 } 404 }
405 405
406 proc do_plansql_test {tn sql r} { 406 proc do_plansql_test {tn sql r} {
407 uplevel do_execsql_test $tn [list "EXPLAIN QUERY PLAN $sql ; $sql"] [list $r] 407 uplevel do_execsql_test $tn [list "EXPLAIN QUERY PLAN $sql ; $sql"] [list $r]
408 } 408 }
409 409
410 do_plansql_test 4.2 { 410 do_plansql_test 4.2 {
411 SELECT y FROM x2, terms WHERE y = term AND col = '*' 411 SELECT y FROM x2, terms WHERE y = term AND col = '*'
412 } { 412 } {
413 0 0 0 {SCAN TABLE x2 (~1000000 rows)} 413 0 0 0 {SCAN TABLE x2}
414 0 1 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 1: (~0 rows)} 414 0 1 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 1:}
415 a b c d e f g h i j k l 415 a b c d e f g h i j k l
416 } 416 }
417 417
418 do_plansql_test 4.3 { 418 do_plansql_test 4.3 {
419 SELECT y FROM terms, x2 WHERE y = term AND col = '*' 419 SELECT y FROM terms, x2 WHERE y = term AND col = '*'
420 } { 420 } {
421 0 0 1 {SCAN TABLE x2 (~1000000 rows)} 421 0 0 1 {SCAN TABLE x2}
422 0 1 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1: (~0 rows)} 422 0 1 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1:}
423 a b c d e f g h i j k l 423 a b c d e f g h i j k l
424 } 424 }
425 425
426 do_plansql_test 4.4 { 426 do_plansql_test 4.4 {
427 SELECT y FROM x3, terms WHERE y = term AND col = '*' 427 SELECT y FROM x3, terms WHERE y = term AND col = '*'
428 } { 428 } {
429 0 0 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} 429 0 0 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}
430 0 1 0 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?) (~10 rows)} 430 0 1 0 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?)}
431 a b c d e f g h i j k l 431 a b c d e f g h i j k l
432 } 432 }
433 433
434 do_plansql_test 4.5 { 434 do_plansql_test 4.5 {
435 SELECT y FROM terms, x3 WHERE y = term AND occurrences>1 AND col = '*' 435 SELECT y FROM terms, x3 WHERE y = term AND occurrences>1 AND col = '*'
436 } { 436 } {
437 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} 437 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}
438 0 1 1 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?) (~10 rows)} 438 0 1 1 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?)}
439 a k l 439 a k l
440 } 440 }
441 441
442 #------------------------------------------------------------------------- 442 #-------------------------------------------------------------------------
443 # The following tests check that fts4aux can handle an fts table with an 443 # The following tests check that fts4aux can handle an fts table with an
444 # odd name (one that requires quoting for use in SQL statements). And that 444 # odd name (one that requires quoting for use in SQL statements). And that
445 # the argument to the fts4aux constructor is properly dequoted before use. 445 # the argument to the fts4aux constructor is properly dequoted before use.
446 # 446 #
447 #
448 do_execsql_test 5.1 { 447 do_execsql_test 5.1 {
449 CREATE VIRTUAL TABLE "abc '!' def" USING fts4(x, y); 448 CREATE VIRTUAL TABLE "abc '!' def" USING fts4(x, y);
450 INSERT INTO "abc '!' def" VALUES('XX', 'YY'); 449 INSERT INTO "abc '!' def" VALUES('XX', 'YY');
451 450
452 CREATE VIRTUAL TABLE terms3 USING fts4aux("abc '!' def"); 451 CREATE VIRTUAL TABLE terms3 USING fts4aux("abc '!' def");
453 SELECT * FROM terms3; 452 SELECT * FROM terms3;
454 } {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1} 453 } {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1}
455 454
456 do_execsql_test 5.2 { 455 do_execsql_test 5.2 {
457 CREATE VIRTUAL TABLE "%%^^%%" USING fts4aux('abc ''!'' def'); 456 CREATE VIRTUAL TABLE "%%^^%%" USING fts4aux('abc ''!'' def');
458 SELECT * FROM "%%^^%%"; 457 SELECT * FROM "%%^^%%";
459 } {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1} 458 } {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1}
460 459
460 #-------------------------------------------------------------------------
461 # Test that we can create an fts4aux table in the temp database.
462 #
463 forcedelete test.db2
464 do_execsql_test 6.1 {
465 CREATE VIRTUAL TABLE ft1 USING fts4(x, y);
466 INSERT INTO ft1 VALUES('a b', 'c d');
467 INSERT INTO ft1 VALUES('e e', 'c d');
468 INSERT INTO ft1 VALUES('a a', 'b b');
469 CREATE VIRTUAL TABLE temp.aux1 USING fts4aux(main, ft1);
470 SELECT * FROM aux1;
471 } {
472 a * 2 3 a 0 2 3
473 b * 2 3 b 0 1 1 b 1 1 2
474 c * 2 2 c 1 2 2
475 d * 2 2 d 1 2 2
476 e * 1 2 e 0 1 2
477 }
478
479 do_execsql_test 6.2 {
480 ATTACH 'test.db2' AS att;
481 CREATE VIRTUAL TABLE att.ft1 USING fts4(x, y);
482 INSERT INTO att.ft1 VALUES('v w', 'x y');
483 INSERT INTO att.ft1 VALUES('z z', 'x y');
484 INSERT INTO att.ft1 VALUES('v v', 'w w');
485 CREATE VIRTUAL TABLE temp.aux2 USING fts4aux(att, ft1);
486 SELECT * FROM aux2;
487 } {
488 v * 2 3 v 0 2 3
489 w * 2 3 w 0 1 1 w 1 1 2
490 x * 2 2 x 1 2 2
491 y * 2 2 y 1 2 2
492 z * 1 2 z 0 1 2
493 }
494
495 foreach {tn q res1 res2} {
496 1 { SELECT * FROM %%% WHERE term = 'a' } {a * 2 3 a 0 2 3} {}
497 2 { SELECT * FROM %%% WHERE term = 'x' } {} {x * 2 2 x 1 2 2}
498
499 3 { SELECT * FROM %%% WHERE term >= 'y' }
500 {} {y * 2 2 y 1 2 2 z * 1 2 z 0 1 2}
501
502 4 { SELECT * FROM %%% WHERE term <= 'c' }
503 {a * 2 3 a 0 2 3 b * 2 3 b 0 1 1 b 1 1 2 c * 2 2 c 1 2 2} {}
504 } {
505 set sql1 [string map {%%% aux1} $q]
506 set sql2 [string map {%%% aux2} $q]
507
508 do_execsql_test 7.$tn.1 $sql1 $res1
509 do_execsql_test 7.$tn.2 $sql2 $res2
510 }
511
512 do_test 8.1 {
513 catchsql { CREATE VIRTUAL TABLE att.aux3 USING fts4aux(main, ft1) }
514 } {1 {invalid arguments to fts4aux constructor}}
515
516 do_test 8.2 {
517 execsql {DETACH att}
518 catchsql { SELECT * FROM aux2 }
519 } {1 {SQL logic error or missing database}}
461 520
462 finish_test 521 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698