From: dan Date: Thu, 29 Mar 2012 14:29:07 +0000 (+0000) Subject: Disable the LIKE optimization if the column on the left-hand-side of the LIKE operato... X-Git-Tag: mountain-lion~3^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c68939ef3e403e8996a11f5805a9bb12415318c8;p=thirdparty%2Fsqlite.git Disable the LIKE optimization if the column on the left-hand-side of the LIKE operator belongs to a virtual table. FossilOrigin-Name: 0bacb879e18026f2a8e22fe3e4bc8d27de5c4416 --- diff --git a/manifest b/manifest index 508e95c5af..3caf718a94 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sout\sof\sdate\scomment\son\ssqlite3ArrayAllocate(). -D 2012-03-29T07:51:45.964 +C Disable\sthe\sLIKE\soptimization\sif\sthe\scolumn\son\sthe\sleft-hand-side\sof\sthe\sLIKE\soperator\sbelongs\sto\sa\svirtual\stable. +D 2012-03-29T14:29:07.705 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -253,7 +253,7 @@ F src/vtab.c ab90fb600a3f5e4b7c48d22a4cdb2d6b23239847 F src/wal.c 7bb3ad807afc7973406c805d5157ec7a2f65e146 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f -F src/where.c 44d78f5811594065ebbb5354da7f9e6b8b1306d6 +F src/where.c 2112422a404dcca5d47f6630bdf180bccd36c62b F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 @@ -890,7 +890,7 @@ F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 7701bb609fe8bf6535514e8b849a309e8f00573b F test/view.test b182a67ec43f490b156b5a710827a341be83dd17 -F test/vtab1.test 17d0db1096b603a357f943a9dcbdc3e30c6f04f2 +F test/vtab1.test e429a6835faa3870016c55d1178dcfead85f936a F test/vtab2.test 7bcffc050da5c68f4f312e49e443063e2d391c0d F test/vtab3.test baad99fd27217f5d6db10660522e0b7192446de1 F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 @@ -993,7 +993,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 0733c98c329bc9942460746e9bbaf4b4c94c1520 -R cdd95431de81f865d03de0c1a140cd52 +P 4afdd5ae53ef0ff7c0fde74eaa04638c923c679b +R def111c8a7bf40297c8914cb6a05a57c U dan -Z 5c9d2afc31444fe45f09b85b23502baf +Z 4348a3207684ec0ef401a834e1562981 diff --git a/manifest.uuid b/manifest.uuid index 48ec1465b4..611c0d9d53 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4afdd5ae53ef0ff7c0fde74eaa04638c923c679b \ No newline at end of file +0bacb879e18026f2a8e22fe3e4bc8d27de5c4416 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 2f3dc77e12..5471f71dcf 100644 --- a/src/where.c +++ b/src/where.c @@ -686,7 +686,10 @@ static int isLikeOrGlob( #endif pList = pExpr->x.pList; pLeft = pList->a[1].pExpr; - if( pLeft->op!=TK_COLUMN || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT ){ + if( pLeft->op!=TK_COLUMN + || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT + || IsVirtual(pLeft->pTab) + ){ /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must ** be the name of an indexed column with TEXT affinity. */ return 0; diff --git a/test/vtab1.test b/test/vtab1.test index f056b2f368..38aec09eae 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -15,6 +15,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix vtab1 ifcapable !vtab||!schema_pragmas { finish_test @@ -43,6 +44,9 @@ ifcapable !vtab||!schema_pragmas { # # vtab1-14.*: Test 'IN' constraints - i.e. "SELECT * FROM t1 WHERE id IN(...)" # +# vtab1-18.*: Check that the LIKE optimization is not applied when the lhs +# is a virtual table column. +# #---------------------------------------------------------------------- @@ -1218,5 +1222,57 @@ do_test vtab1-17.1 { } } {} +#------------------------------------------------------------------------- +# The following tests - vtab1-18.* - test that the optimization of LIKE +# constraints in where.c plays well with virtual tables. +# +# 18.1.*: Case-insensitive LIKE. +# 18.2.*: Case-sensitive LIKE. +# unset -nocomplain echo_module_begin_fail + +do_execsql_test 18.1.0 { + CREATE TABLE t6(a, b TEXT); + CREATE INDEX i6 ON t6(b, a); + INSERT INTO t6 VALUES(1, 'Peter'); + INSERT INTO t6 VALUES(2, 'Andrew'); + INSERT INTO t6 VALUES(3, 'James'); + INSERT INTO t6 VALUES(4, 'John'); + INSERT INTO t6 VALUES(5, 'Phillip'); + INSERT INTO t6 VALUES(6, 'Bartholomew'); + CREATE VIRTUAL TABLE e6 USING echo(t6); +} + +foreach {tn sql res filter} { + 1.1 "SELECT a FROM e6 WHERE b>'James'" {4 1 5} + {xFilter {SELECT rowid, * FROM 't6' WHERE b > ?} James} + + 1.2 "SELECT a FROM e6 WHERE b>='J' AND b<'K'" {3 4} + {xFilter {SELECT rowid, * FROM 't6' WHERE b >= ? AND b < ?} J K} + + 1.3 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4} + {xFilter {SELECT rowid, * FROM 't6'}} + + 1.4 "SELECT a FROM e6 WHERE b LIKE 'j%'" {3 4} + {xFilter {SELECT rowid, * FROM 't6'}} +} { + set echo_module {} + do_execsql_test 18.$tn.1 $sql $res + do_test 18.$tn.2 { lrange $::echo_module 2 end } $filter +} + +do_execsql_test 18.2.0 { PRAGMA case_sensitive_like = ON } +foreach {tn sql res filter} { + 2.1 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4} + {xFilter {SELECT rowid, * FROM 't6'}} + + 2.2 "SELECT a FROM e6 WHERE b LIKE 'j%'" {} + {xFilter {SELECT rowid, * FROM 't6'}} +} { + set echo_module {} + do_execsql_test 18.$tn.1 $sql $res + do_test 18.$tn.2 { lrange $::echo_module 2 end } $filter +} +do_execsql_test 18.2.x { PRAGMA case_sensitive_like = OFF } + finish_test