| OLD | NEW |
| 1 # 2005 August 13 | 1 # 2005 August 13 |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 execsql { | 63 execsql { |
| 64 SELECT x FROM t1 WHERE x LIKE 'ABC' ORDER BY 1; | 64 SELECT x FROM t1 WHERE x LIKE 'ABC' ORDER BY 1; |
| 65 } | 65 } |
| 66 } {ABC abc} | 66 } {ABC abc} |
| 67 do_test like-1.4 { | 67 do_test like-1.4 { |
| 68 execsql { | 68 execsql { |
| 69 SELECT x FROM t1 WHERE x LIKE 'aBc' ORDER BY 1; | 69 SELECT x FROM t1 WHERE x LIKE 'aBc' ORDER BY 1; |
| 70 } | 70 } |
| 71 } {ABC abc} | 71 } {ABC abc} |
| 72 do_test like-1.5.1 { | 72 do_test like-1.5.1 { |
| 73 # Use sqlite3_exec() to verify fix for ticket [25ee81271091] 2011-06-26 |
| 74 sqlite3_exec db {PRAGMA case_sensitive_like=on} |
| 75 } {0 {}} |
| 76 do_test like-1.5.2 { |
| 73 execsql { | 77 execsql { |
| 74 PRAGMA case_sensitive_like=on; | |
| 75 SELECT x FROM t1 WHERE x LIKE 'abc' ORDER BY 1; | 78 SELECT x FROM t1 WHERE x LIKE 'abc' ORDER BY 1; |
| 76 } | 79 } |
| 77 } {abc} | 80 } {abc} |
| 78 do_test like-1.5.2 { | 81 do_test like-1.5.3 { |
| 79 execsql { | 82 execsql { |
| 80 PRAGMA case_sensitive_like; -- no argument; does not change setting | 83 PRAGMA case_sensitive_like; -- no argument; does not change setting |
| 81 SELECT x FROM t1 WHERE x LIKE 'abc' ORDER BY 1; | 84 SELECT x FROM t1 WHERE x LIKE 'abc' ORDER BY 1; |
| 82 } | 85 } |
| 83 } {abc} | 86 } {abc} |
| 84 do_test like-1.6 { | 87 do_test like-1.6 { |
| 85 execsql { | 88 execsql { |
| 86 SELECT x FROM t1 WHERE x GLOB 'abc' ORDER BY 1; | 89 SELECT x FROM t1 WHERE x GLOB 'abc' ORDER BY 1; |
| 87 } | 90 } |
| 88 } {abc} | 91 } {abc} |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 # For the remaining tests, we need to have the like optimizations | 149 # For the remaining tests, we need to have the like optimizations |
| 147 # enabled. | 150 # enabled. |
| 148 # | 151 # |
| 149 ifcapable !like_opt { | 152 ifcapable !like_opt { |
| 150 finish_test | 153 finish_test |
| 151 return | 154 return |
| 152 } | 155 } |
| 153 | 156 |
| 154 # This procedure executes the SQL. Then it appends to the result the | 157 # This procedure executes the SQL. Then it appends to the result the |
| 155 # "sort" or "nosort" keyword (as in the cksort procedure above) then | 158 # "sort" or "nosort" keyword (as in the cksort procedure above) then |
| 156 # it appends the ::sqlite_query_plan variable. | 159 # it appends the names of the table and index used. |
| 157 # | 160 # |
| 158 proc queryplan {sql} { | 161 proc queryplan {sql} { |
| 159 set ::sqlite_sort_count 0 | 162 set ::sqlite_sort_count 0 |
| 160 set data [execsql $sql] | 163 set data [execsql $sql] |
| 161 if {$::sqlite_sort_count} {set x sort} {set x nosort} | 164 if {$::sqlite_sort_count} {set x sort} {set x nosort} |
| 162 lappend data $x | 165 lappend data $x |
| 163 return [concat $data $::sqlite_query_plan] | 166 set eqp [execsql "EXPLAIN QUERY PLAN $sql"] |
| 167 # puts eqp=$eqp |
| 168 foreach {a b c x} $eqp { |
| 169 if {[regexp { TABLE (\w+ AS )?(\w+) USING COVERING INDEX (\w+)\y} \ |
| 170 $x all as tab idx]} { |
| 171 lappend data {} $idx |
| 172 } elseif {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \ |
| 173 $x all as tab idx]} { |
| 174 lappend data $tab $idx |
| 175 } elseif {[regexp { TABLE (\w+ AS )?(\w+)\y} $x all as tab]} { |
| 176 lappend data $tab * |
| 177 } |
| 178 } |
| 179 return $data |
| 164 } | 180 } |
| 165 | 181 |
| 166 # Perform tests on the like optimization. | 182 # Perform tests on the like optimization. |
| 167 # | 183 # |
| 168 # With no index on t1.x and with case sensitivity turned off, no optimization | 184 # With no index on t1.x and with case sensitivity turned off, no optimization |
| 169 # is performed. | 185 # is performed. |
| 170 # | 186 # |
| 171 do_test like-3.1 { | 187 do_test like-3.1 { |
| 172 set sqlite_like_count 0 | 188 set sqlite_like_count 0 |
| 173 queryplan { | 189 queryplan { |
| 174 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1; | 190 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1; |
| 175 } | 191 } |
| 176 } {ABC {ABC abc xyz} abc abcd sort t1 {}} | 192 } {ABC {ABC abc xyz} abc abcd sort t1 *} |
| 177 do_test like-3.2 { | 193 do_test like-3.2 { |
| 178 set sqlite_like_count | 194 set sqlite_like_count |
| 179 } {12} | 195 } {12} |
| 180 | 196 |
| 181 # With an index on t1.x and case sensitivity on, optimize completely. | 197 # With an index on t1.x and case sensitivity on, optimize completely. |
| 182 # | 198 # |
| 183 do_test like-3.3 { | 199 do_test like-3.3 { |
| 184 set sqlite_like_count 0 | 200 set sqlite_like_count 0 |
| 185 execsql { | 201 execsql { |
| 186 PRAGMA case_sensitive_like=on; | 202 PRAGMA case_sensitive_like=on; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 275 } |
| 260 } {abcd bcd nosort {} i1} | 276 } {abcd bcd nosort {} i1} |
| 261 do_test like-3.12 { | 277 do_test like-3.12 { |
| 262 set sqlite_like_count | 278 set sqlite_like_count |
| 263 } 12 | 279 } 12 |
| 264 | 280 |
| 265 # No optimization for case insensitive LIKE | 281 # No optimization for case insensitive LIKE |
| 266 # | 282 # |
| 267 do_test like-3.13 { | 283 do_test like-3.13 { |
| 268 set sqlite_like_count 0 | 284 set sqlite_like_count 0 |
| 285 db eval {PRAGMA case_sensitive_like=off;} |
| 269 queryplan { | 286 queryplan { |
| 270 PRAGMA case_sensitive_like=off; | |
| 271 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1; | 287 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1; |
| 272 } | 288 } |
| 273 } {ABC {ABC abc xyz} abc abcd nosort {} i1} | 289 } {ABC {ABC abc xyz} abc abcd nosort {} i1} |
| 274 do_test like-3.14 { | 290 do_test like-3.14 { |
| 275 set sqlite_like_count | 291 set sqlite_like_count |
| 276 } 12 | 292 } 12 |
| 277 | 293 |
| 278 # No optimization without an index. | 294 # No optimization without an index. |
| 279 # | 295 # |
| 280 do_test like-3.15 { | 296 do_test like-3.15 { |
| 281 set sqlite_like_count 0 | 297 set sqlite_like_count 0 |
| 282 queryplan { | 298 db eval { |
| 283 PRAGMA case_sensitive_like=on; | 299 PRAGMA case_sensitive_like=on; |
| 284 DROP INDEX i1; | 300 DROP INDEX i1; |
| 301 } |
| 302 queryplan { |
| 285 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1; | 303 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1; |
| 286 } | 304 } |
| 287 } {abc abcd sort t1 {}} | 305 } {abc abcd sort t1 *} |
| 288 do_test like-3.16 { | 306 do_test like-3.16 { |
| 289 set sqlite_like_count | 307 set sqlite_like_count |
| 290 } 12 | 308 } 12 |
| 291 | 309 |
| 292 # No GLOB optimization without an index. | 310 # No GLOB optimization without an index. |
| 293 # | 311 # |
| 294 do_test like-3.17 { | 312 do_test like-3.17 { |
| 295 set sqlite_like_count 0 | 313 set sqlite_like_count 0 |
| 296 queryplan { | 314 queryplan { |
| 297 SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1; | 315 SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1; |
| 298 } | 316 } |
| 299 } {abc abcd sort t1 {}} | 317 } {abc abcd sort t1 *} |
| 300 do_test like-3.18 { | 318 do_test like-3.18 { |
| 301 set sqlite_like_count | 319 set sqlite_like_count |
| 302 } 12 | 320 } 12 |
| 303 | 321 |
| 304 # GLOB is optimized regardless of the case_sensitive_like setting. | 322 # GLOB is optimized regardless of the case_sensitive_like setting. |
| 305 # | 323 # |
| 306 do_test like-3.19 { | 324 do_test like-3.19 { |
| 307 set sqlite_like_count 0 | 325 set sqlite_like_count 0 |
| 326 db eval {CREATE INDEX i1 ON t1(x);} |
| 308 queryplan { | 327 queryplan { |
| 309 CREATE INDEX i1 ON t1(x); | |
| 310 SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1; | 328 SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1; |
| 311 } | 329 } |
| 312 } {abc abcd nosort {} i1} | 330 } {abc abcd nosort {} i1} |
| 313 do_test like-3.20 { | 331 do_test like-3.20 { |
| 314 set sqlite_like_count | 332 set sqlite_like_count |
| 315 } 0 | 333 } 0 |
| 316 do_test like-3.21 { | 334 do_test like-3.21 { |
| 317 set sqlite_like_count 0 | 335 set sqlite_like_count 0 |
| 336 db eval {PRAGMA case_sensitive_like=on;} |
| 318 queryplan { | 337 queryplan { |
| 319 PRAGMA case_sensitive_like=on; | |
| 320 SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1; | 338 SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1; |
| 321 } | 339 } |
| 322 } {abc abcd nosort {} i1} | 340 } {abc abcd nosort {} i1} |
| 323 do_test like-3.22 { | 341 do_test like-3.22 { |
| 324 set sqlite_like_count | 342 set sqlite_like_count |
| 325 } 0 | 343 } 0 |
| 326 do_test like-3.23 { | 344 do_test like-3.23 { |
| 327 set sqlite_like_count 0 | 345 set sqlite_like_count 0 |
| 346 db eval {PRAGMA case_sensitive_like=off;} |
| 328 queryplan { | 347 queryplan { |
| 329 PRAGMA case_sensitive_like=off; | |
| 330 SELECT x FROM t1 WHERE x GLOB 'a[bc]d' ORDER BY 1; | 348 SELECT x FROM t1 WHERE x GLOB 'a[bc]d' ORDER BY 1; |
| 331 } | 349 } |
| 332 } {abd acd nosort {} i1} | 350 } {abd acd nosort {} i1} |
| 333 do_test like-3.24 { | 351 do_test like-3.24 { |
| 334 set sqlite_like_count | 352 set sqlite_like_count |
| 335 } 6 | 353 } 6 |
| 336 | 354 |
| 337 # GLOB optimization when there is no wildcard. Ticket [e090183531fc2747] | 355 # GLOB optimization when there is no wildcard. Ticket [e090183531fc2747] |
| 338 # | 356 # |
| 339 do_test like-3.25 { | 357 do_test like-3.25 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 queryplan { | 414 queryplan { |
| 397 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1 | 415 SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1 |
| 398 } | 416 } |
| 399 } {ABC {ABC abc xyz} abc abcd nosort {} i1} | 417 } {ABC {ABC abc xyz} abc abcd nosort {} i1} |
| 400 do_test like-5.2 { | 418 do_test like-5.2 { |
| 401 set sqlite_like_count | 419 set sqlite_like_count |
| 402 } 12 | 420 } 12 |
| 403 do_test like-5.3 { | 421 do_test like-5.3 { |
| 404 execsql { | 422 execsql { |
| 405 CREATE TABLE t2(x TEXT COLLATE NOCASE); | 423 CREATE TABLE t2(x TEXT COLLATE NOCASE); |
| 406 INSERT INTO t2 SELECT * FROM t1; | 424 INSERT INTO t2 SELECT * FROM t1 ORDER BY rowid; |
| 407 CREATE INDEX i2 ON t2(x COLLATE NOCASE); | 425 CREATE INDEX i2 ON t2(x COLLATE NOCASE); |
| 408 } | 426 } |
| 409 set sqlite_like_count 0 | 427 set sqlite_like_count 0 |
| 410 queryplan { | 428 queryplan { |
| 411 SELECT x FROM t2 WHERE x LIKE 'abc%' ORDER BY 1 | 429 SELECT x FROM t2 WHERE x LIKE 'abc%' ORDER BY 1 |
| 412 } | 430 } |
| 413 } {abc ABC {ABC abc xyz} abcd nosort {} i2} | 431 } {abc ABC {ABC abc xyz} abcd nosort {} i2} |
| 414 do_test like-5.4 { | 432 do_test like-5.4 { |
| 415 set sqlite_like_count | 433 set sqlite_like_count |
| 416 } 0 | 434 } 0 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 queryplan { | 530 queryplan { |
| 513 SELECT x FROM t2 WHERE x LIKE 'Zz%'; | 531 SELECT x FROM t2 WHERE x LIKE 'Zz%'; |
| 514 } | 532 } |
| 515 } {zz-lower-lower zZ-lower-upper Zz-upper-lower ZZ-upper-upper nosort {} i2} | 533 } {zz-lower-lower zZ-lower-upper Zz-upper-lower ZZ-upper-upper nosort {} i2} |
| 516 do_test like-5.24 { | 534 do_test like-5.24 { |
| 517 queryplan { | 535 queryplan { |
| 518 SELECT x FROM t2 WHERE x LIKE 'ZZ%'; | 536 SELECT x FROM t2 WHERE x LIKE 'ZZ%'; |
| 519 } | 537 } |
| 520 } {zz-lower-lower zZ-lower-upper Zz-upper-lower ZZ-upper-upper nosort {} i2} | 538 } {zz-lower-lower zZ-lower-upper Zz-upper-lower ZZ-upper-upper nosort {} i2} |
| 521 do_test like-5.25 { | 539 do_test like-5.25 { |
| 522 queryplan { | 540 db eval { |
| 523 PRAGMA case_sensitive_like=on; | 541 PRAGMA case_sensitive_like=on; |
| 524 CREATE TABLE t3(x TEXT); | 542 CREATE TABLE t3(x TEXT); |
| 525 CREATE INDEX i3 ON t3(x); | 543 CREATE INDEX i3 ON t3(x); |
| 526 INSERT INTO t3 VALUES('ZZ-upper-upper'); | 544 INSERT INTO t3 VALUES('ZZ-upper-upper'); |
| 527 INSERT INTO t3 VALUES('zZ-lower-upper'); | 545 INSERT INTO t3 VALUES('zZ-lower-upper'); |
| 528 INSERT INTO t3 VALUES('Zz-upper-lower'); | 546 INSERT INTO t3 VALUES('Zz-upper-lower'); |
| 529 INSERT INTO t3 VALUES('zz-lower-lower'); | 547 INSERT INTO t3 VALUES('zz-lower-lower'); |
| 548 } |
| 549 queryplan { |
| 530 SELECT x FROM t3 WHERE x LIKE 'zz%'; | 550 SELECT x FROM t3 WHERE x LIKE 'zz%'; |
| 531 } | 551 } |
| 532 } {zz-lower-lower nosort {} i3} | 552 } {zz-lower-lower nosort {} i3} |
| 533 do_test like-5.26 { | 553 do_test like-5.26 { |
| 534 queryplan { | 554 queryplan { |
| 535 SELECT x FROM t3 WHERE x LIKE 'zZ%'; | 555 SELECT x FROM t3 WHERE x LIKE 'zZ%'; |
| 536 } | 556 } |
| 537 } {zZ-lower-upper nosort {} i3} | 557 } {zZ-lower-upper nosort {} i3} |
| 538 do_test like-5.27 { | 558 do_test like-5.27 { |
| 539 queryplan { | 559 queryplan { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 do_test like-9.4.2 { | 670 do_test like-9.4.2 { |
| 651 set res [sqlite3_exec_hex db { | 671 set res [sqlite3_exec_hex db { |
| 652 SELECT substr(x,2) AS x FROM t2 WHERE x LIKE '%ff%25' | 672 SELECT substr(x,2) AS x FROM t2 WHERE x LIKE '%ff%25' |
| 653 }] | 673 }] |
| 654 } {0 {x hello}} | 674 } {0 {x hello}} |
| 655 ifcapable explain { | 675 ifcapable explain { |
| 656 do_test like-9.4.3 { | 676 do_test like-9.4.3 { |
| 657 set res [sqlite3_exec_hex db { | 677 set res [sqlite3_exec_hex db { |
| 658 EXPLAIN QUERY PLAN SELECT x FROM t2 WHERE x LIKE '%ff%25' | 678 EXPLAIN QUERY PLAN SELECT x FROM t2 WHERE x LIKE '%ff%25' |
| 659 }] | 679 }] |
| 660 regexp {INDEX i2} $res | 680 regexp {SCAN TABLE t2} $res |
| 661 } {0} | 681 } {1} |
| 662 } | 682 } |
| 663 do_test like-9.5.1 { | 683 do_test like-9.5.1 { |
| 664 set res [sqlite3_exec_hex db { | 684 set res [sqlite3_exec_hex db { |
| 665 SELECT x FROM t2 WHERE x LIKE '%fe%25' | 685 SELECT x FROM t2 WHERE x LIKE '%fe%25' |
| 666 }] | 686 }] |
| 667 } {0 {}} | 687 } {0 {}} |
| 668 ifcapable explain { | 688 ifcapable explain { |
| 669 do_test like-9.5.2 { | 689 do_test like-9.5.2 { |
| 670 set res [sqlite3_exec_hex db { | 690 set res [sqlite3_exec_hex db { |
| 671 EXPLAIN QUERY PLAN SELECT x FROM t2 WHERE x LIKE '%fe%25' | 691 EXPLAIN QUERY PLAN SELECT x FROM t2 WHERE x LIKE '%fe%25' |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 INSERT INTO t11 VALUES(7, 'ABC','ABC'); | 817 INSERT INTO t11 VALUES(7, 'ABC','ABC'); |
| 798 INSERT INTO t11 VALUES(8, 'ABCD','ABCD'); | 818 INSERT INTO t11 VALUES(8, 'ABCD','ABCD'); |
| 799 INSERT INTO t11 VALUES(9, 'x','x'); | 819 INSERT INTO t11 VALUES(9, 'x','x'); |
| 800 INSERT INTO t11 VALUES(10, 'yz','yz'); | 820 INSERT INTO t11 VALUES(10, 'yz','yz'); |
| 801 INSERT INTO t11 VALUES(11, 'X','X'); | 821 INSERT INTO t11 VALUES(11, 'X','X'); |
| 802 INSERT INTO t11 VALUES(12, 'YZ','YZ'); | 822 INSERT INTO t11 VALUES(12, 'YZ','YZ'); |
| 803 SELECT count(*) FROM t11; | 823 SELECT count(*) FROM t11; |
| 804 } | 824 } |
| 805 } {12} | 825 } {12} |
| 806 do_test like-11.1 { | 826 do_test like-11.1 { |
| 827 db eval {PRAGMA case_sensitive_like=OFF;} |
| 807 queryplan { | 828 queryplan { |
| 808 PRAGMA case_sensitive_like=OFF; | |
| 809 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a; | 829 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a; |
| 810 } | 830 } |
| 811 } {abc abcd ABC ABCD nosort t11 *} | 831 } {abc abcd ABC ABCD nosort t11 *} |
| 812 do_test like-11.2 { | 832 do_test like-11.2 { |
| 833 db eval {PRAGMA case_sensitive_like=ON;} |
| 813 queryplan { | 834 queryplan { |
| 814 PRAGMA case_sensitive_like=ON; | |
| 815 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a; | 835 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a; |
| 816 } | 836 } |
| 817 } {abc abcd nosort t11 *} | 837 } {abc abcd nosort t11 *} |
| 818 do_test like-11.3 { | 838 do_test like-11.3 { |
| 819 queryplan { | 839 db eval { |
| 820 PRAGMA case_sensitive_like=OFF; | 840 PRAGMA case_sensitive_like=OFF; |
| 821 CREATE INDEX t11b ON t11(b); | 841 CREATE INDEX t11b ON t11(b); |
| 842 } |
| 843 queryplan { |
| 822 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; | 844 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; |
| 823 } | 845 } |
| 824 } {abc abcd ABC ABCD sort {} t11b} | 846 } {abc abcd ABC ABCD sort {} t11b} |
| 825 do_test like-11.4 { | 847 do_test like-11.4 { |
| 848 db eval {PRAGMA case_sensitive_like=ON;} |
| 826 queryplan { | 849 queryplan { |
| 827 PRAGMA case_sensitive_like=ON; | |
| 828 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a; | 850 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a; |
| 829 } | 851 } |
| 830 } {abc abcd nosort t11 *} | 852 } {abc abcd nosort t11 *} |
| 831 do_test like-11.5 { | 853 do_test like-11.5 { |
| 832 queryplan { | 854 db eval { |
| 833 PRAGMA case_sensitive_like=OFF; | 855 PRAGMA case_sensitive_like=OFF; |
| 834 DROP INDEX t11b; | 856 DROP INDEX t11b; |
| 835 CREATE INDEX t11bnc ON t11(b COLLATE nocase); | 857 CREATE INDEX t11bnc ON t11(b COLLATE nocase); |
| 858 } |
| 859 queryplan { |
| 836 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; | 860 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; |
| 837 } | 861 } |
| 838 } {abc abcd ABC ABCD sort {} t11bnc} | 862 } {abc abcd ABC ABCD sort {} t11bnc} |
| 839 do_test like-11.6 { | 863 do_test like-11.6 { |
| 864 db eval {CREATE INDEX t11bb ON t11(b COLLATE binary);} |
| 840 queryplan { | 865 queryplan { |
| 841 CREATE INDEX t11bb ON t11(b COLLATE binary); | |
| 842 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; | 866 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; |
| 843 } | 867 } |
| 844 } {abc abcd ABC ABCD sort {} t11bnc} | 868 } {abc abcd ABC ABCD sort {} t11bnc} |
| 845 do_test like-11.7 { | 869 do_test like-11.7 { |
| 870 db eval {PRAGMA case_sensitive_like=ON;} |
| 846 queryplan { | 871 queryplan { |
| 847 PRAGMA case_sensitive_like=ON; | |
| 848 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; | 872 SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a; |
| 849 } | 873 } |
| 850 } {abc abcd sort {} t11bb} | 874 } {abc abcd sort {} t11bb} |
| 851 do_test like-11.8 { | 875 do_test like-11.8 { |
| 876 db eval {PRAGMA case_sensitive_like=OFF;} |
| 852 queryplan { | 877 queryplan { |
| 853 PRAGMA case_sensitive_like=OFF; | |
| 854 SELECT b FROM t11 WHERE b GLOB 'abc*' ORDER BY +a; | 878 SELECT b FROM t11 WHERE b GLOB 'abc*' ORDER BY +a; |
| 855 } | 879 } |
| 856 } {abc abcd sort {} t11bb} | 880 } {abc abcd sort {} t11bb} |
| 857 do_test like-11.9 { | 881 do_test like-11.9 { |
| 858 queryplan { | 882 db eval { |
| 859 CREATE INDEX t11cnc ON t11(c COLLATE nocase); | 883 CREATE INDEX t11cnc ON t11(c COLLATE nocase); |
| 860 CREATE INDEX t11cb ON t11(c COLLATE binary); | 884 CREATE INDEX t11cb ON t11(c COLLATE binary); |
| 885 } |
| 886 queryplan { |
| 861 SELECT c FROM t11 WHERE c LIKE 'abc%' ORDER BY +a; | 887 SELECT c FROM t11 WHERE c LIKE 'abc%' ORDER BY +a; |
| 862 } | 888 } |
| 863 } {abc abcd ABC ABCD sort {} t11cnc} | 889 } {abc abcd ABC ABCD sort {} t11cnc} |
| 864 do_test like-11.10 { | 890 do_test like-11.10 { |
| 865 queryplan { | 891 queryplan { |
| 866 SELECT c FROM t11 WHERE c GLOB 'abc*' ORDER BY +a; | 892 SELECT c FROM t11 WHERE c GLOB 'abc*' ORDER BY +a; |
| 867 } | 893 } |
| 868 } {abc abcd sort {} t11cb} | 894 } {abc abcd sort {} t11cb} |
| 869 | 895 |
| 896 # A COLLATE clause on the pattern does not change the result of a |
| 897 # LIKE operator. |
| 898 # |
| 899 do_execsql_test like-12.1 { |
| 900 CREATE TABLE t12nc(id INTEGER, x TEXT UNIQUE COLLATE nocase); |
| 901 INSERT INTO t12nc VALUES(1,'abcde'),(2,'uvwxy'),(3,'ABCDEF'); |
| 902 CREATE TABLE t12b(id INTEGER, x TEXT UNIQUE COLLATE binary); |
| 903 INSERT INTO t12b VALUES(1,'abcde'),(2,'uvwxy'),(3,'ABCDEF'); |
| 904 SELECT id FROM t12nc WHERE x LIKE 'abc%' ORDER BY +id; |
| 905 } {1 3} |
| 906 do_execsql_test like-12.2 { |
| 907 SELECT id FROM t12b WHERE x LIKE 'abc%' ORDER BY +id; |
| 908 } {1 3} |
| 909 do_execsql_test like-12.3 { |
| 910 SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id; |
| 911 } {1 3} |
| 912 do_execsql_test like-12.4 { |
| 913 SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id; |
| 914 } {1 3} |
| 915 do_execsql_test like-12.5 { |
| 916 SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id; |
| 917 } {1 3} |
| 918 do_execsql_test like-12.6 { |
| 919 SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id; |
| 920 } {1 3} |
| 921 |
| 922 # Adding a COLLATE clause to the pattern of a LIKE operator does nothing |
| 923 # to change the suitability of using an index to satisfy that LIKE |
| 924 # operator. |
| 925 # |
| 926 do_execsql_test like-12.11 { |
| 927 EXPLAIN QUERY PLAN |
| 928 SELECT id FROM t12nc WHERE x LIKE 'abc%' ORDER BY +id; |
| 929 } {/SEARCH/} |
| 930 do_execsql_test like-12.12 { |
| 931 EXPLAIN QUERY PLAN |
| 932 SELECT id FROM t12b WHERE x LIKE 'abc%' ORDER BY +id; |
| 933 } {/SCAN/} |
| 934 do_execsql_test like-12.13 { |
| 935 EXPLAIN QUERY PLAN |
| 936 SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id; |
| 937 } {/SEARCH/} |
| 938 do_execsql_test like-12.14 { |
| 939 EXPLAIN QUERY PLAN |
| 940 SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id; |
| 941 } {/SCAN/} |
| 942 do_execsql_test like-12.15 { |
| 943 EXPLAIN QUERY PLAN |
| 944 SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id; |
| 945 } {/SEARCH/} |
| 946 do_execsql_test like-12.16 { |
| 947 EXPLAIN QUERY PLAN |
| 948 SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id; |
| 949 } {/SCAN/} |
| 950 |
| 870 | 951 |
| 871 finish_test | 952 finish_test |
| OLD | NEW |