Do not attempt the LIKE optimization on a column with numeric affinity if the rhs of the operator begins with whitespace. Fix for ticket [fd76310a5e].

FossilOrigin-Name: 94b58ab059cba9771e75f16d1460f313104a8fb879f9f8805725d362aa58cbcd
This commit is contained in:
dan 2019-06-10 13:46:42 +00:00
parent 55700bcd72
commit 32d0f64e8d
4 changed files with 35 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Remove\scode\sin\sthe\sround()\sSQL\sfunction\sthat\sbecame\sunreachable\sdue\sto\nthe\soptimization\sof\scheck-in\s[e95138f5f4febde5]
D 2019-06-07T22:51:13.798
C Do\snot\sattempt\sthe\sLIKE\soptimization\son\sa\scolumn\swith\snumeric\saffinity\sif\sthe\srhs\sof\sthe\soperator\sbegins\swith\swhitespace.\sFix\sfor\sticket\s[fd76310a5e].
D 2019-06-10T13:46:42.468
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -611,7 +611,7 @@ F src/walker.c 7607f1a68130c028255d8d56094ea602fc402c79e1e35a46e6282849d90d5fe4
F src/where.c 99c7b718ef846ac952016083aaf4e22ede2290beceaf4730a2df55c023251369
F src/whereInt.h 1b728f71654ebf8421a1715497a587f02d6f538e819af58dc826908f8577e810
F src/wherecode.c 37a1004237d630d785c47bba2290eac652a7a8b0047518eba3cb7c808b604c4a
F src/whereexpr.c 4219bdd5d310ba6424166d918efef301c21e1b7f6444e964b415c4a5b877a8fe
F src/whereexpr.c d0683adb125754b3edd44d7c73fa2e4ea175eaacd900f1dc6993da2f6f0149cc
F src/window.c 5be2cf7d8763cc97137fc44d015aed8a1a4a56fe9700d7933ed560172617c756
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@ -1093,7 +1093,7 @@ F test/kvtest.c 94da54bb66aae7a54e47cf7e4ea4acecc0f217560f79ad3abfcc0361d6d557ba
F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
F test/lemon-test01.y 58b764610fd934e189ffbb0bbfa33d171b9cb06019b55bdc04d090d6767e11d7
F test/like.test 11cfd7d4ef8625389df9efc46735ff0b0b41d5e62047ef0f3bc24c380d28a7a6
F test/like.test 5013f18e7242fe118524fcf8e484b8827bcd5906b509d106f3587c7bfcf274ae
F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
F test/like3.test ac61947ef35bde9d97718bcfa04659a17d9218f1fffc4104b135b3f82ed43836
F test/limit.test 0c99a27a87b14c646a9d583c7c89fd06c352663e
@ -1830,7 +1830,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 67a68af5578f08d2be2e48cf4fd12a6cf35a09c47d259deda81950f7ee1f02f7
R 6f81af875af4fc753423b0367cd03825
U drh
Z 994865afe67c9e685ee27813494924dd
P b141bae3f6d16c0ebb59dac9b02086a4370839e71ade34004f647b09b1083d1d
R 0edeeba297be7794a2df312af7fa73d6
U dan
Z f66db0d0d24acc61923a149ef2da89aa

View File

@ -1 +1 @@
b141bae3f6d16c0ebb59dac9b02086a4370839e71ade34004f647b09b1083d1d
94b58ab059cba9771e75f16d1460f313104a8fb879f9f8805725d362aa58cbcd

View File

@ -264,12 +264,12 @@ static int isLikeOrGlob(
zNew[iTo] = 0;
assert( iTo>0 );
/* If the RHS begins with a digit or a +/- sign, then the LHS must be
** an ordinary column (not a virtual table column) with TEXT affinity.
** Otherwise the LHS might be numeric and "lhs >= rhs" would be false
** even though "lhs LIKE rhs" is true. But if the RHS does not start
** with a digit or +/-, then "lhs LIKE rhs" will always be false if
** the LHS is numeric and so the optimization still works.
/* If the RHS begins with a digit, a +/- sign or whitespace, then the
** LHS must be an ordinary column (not a virtual table column) with
** TEXT affinity. Otherwise the LHS might be numeric and "lhs >= rhs"
** would be false even though "lhs LIKE rhs" is true. But if the RHS
** does not start with a digit or +/-, then "lhs LIKE rhs" will always
** be false if the LHS is numeric and so the optimization still works.
**
** 2018-09-10 ticket c94369cae9b561b1f996d0054bfab11389f9d033
** The RHS pattern must not be '/%' because the termination condition
@ -277,6 +277,7 @@ static int isLikeOrGlob(
** be converted into "x<0", which is incorrect.
*/
if( sqlite3Isdigit(zNew[0])
|| sqlite3Isspace(zNew[0])
|| zNew[0]=='-'
|| zNew[0]=='+'
|| zNew[iTo-1]=='0'-1

View File

@ -17,6 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix like
# Create some sample data to work with.
#
@ -1095,4 +1096,22 @@ do_execsql_test like-15.121 {
} {/SEARCH/}
}
#-------------------------------------------------------------------------
# Tests for ticket [b1d8c79314].
#
reset_db
do_execsql_test 16.0 {
CREATE TABLE t1(a INTEGER COLLATE NOCASE);
CREATE INDEX i1 ON t1(a);
INSERT INTO t1 VALUES(' 1x');
INSERT INTO t1 VALUES(' 1-');
}
do_execsql_test 16.1 {
SELECT * FROM t1 WHERE a LIKE ' 1%';
} {{ 1x} { 1-}}
do_execsql_test 16.2 {
SELECT * FROM t1 WHERE a LIKE ' 1-';
} {{ 1-}}
finish_test