From: drh Date: Wed, 7 Sep 2016 12:20:45 +0000 (+0000) Subject: Correct affinity computations for a SELECT on the RHS of an IN operator. X-Git-Tag: version-3.14.2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3d9f19fc86b3589b355dd01605f37793279c08c;p=thirdparty%2Fsqlite.git Correct affinity computations for a SELECT on the RHS of an IN operator. Fix for ticket [199df4168c]. FossilOrigin-Name: 2d1983ff9f786ead159a900b8c023ab5507ce26b --- diff --git a/manifest b/manifest index 30f65d37a5..7e624b61cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sORDER\sBY\sLIMIT\soptimization\sis\snot\svalid\sunless\sthe\sinner-most\sIN\soperator\nloop\sis\sactually\sused\sby\sthe\squery\splan.\nFix\sfor\sticket\s[0c4df46116e90f92]. -D 2016-09-07T12:08:37.662 +C Correct\saffinity\scomputations\sfor\sa\sSELECT\son\sthe\sRHS\sof\san\sIN\soperator.\nFix\sfor\sticket\s[199df4168c]. +D 2016-09-07T12:20:45.996 F Makefile.in cfd8fb987cd7a6af046daa87daa146d5aad0e088 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a @@ -465,7 +465,7 @@ F src/wal.h 6dd221ed384afdc204bc61e25c23ef7fd5a511f2 F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 F src/where.c 4bbc3f1dcda64c96ed5f0ffe51be7c0d7adb6c62 F src/whereInt.h e5b939701a7ceffc5a3a8188a37f9746416ebcd0 -F src/wherecode.c 99707d11907c71d289ee9553d2d1a22f1fd8ba41 +F src/wherecode.c 019a050e92526bd6734cca7ca7673c9eb8d0ec32 F src/whereexpr.c d7dcbf14ce1b5876c1f76496162c30fcba669563 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1312,7 +1312,7 @@ F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9 F test/tt3_stress.c c57d804716165811d979d4a719e05baccd79277f F test/tt3_vacuum.c 1753f45917699c9c1f66b64c717a717c9379f776 F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff -F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 +F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a F test/unique.test 93f8b2ef5ea51b9495f8d6493429b1fd0f465264 F test/unique2.test 3674e9f2a3f1fbbfd4772ac74b7a97090d0f77d2 @@ -1509,8 +1509,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 e5c30f227b3f6cae18cc85655149636372592bf8 -Q +820644b886f81e991fceb5f1c3290b8959b34528 -R 9e05f10224481d9859c9095e6e7d395f +P b4f8be1f3258823b3a8f316c92f9019f71ef86a0 +R 742bc7defda07dd553a21f17dc41fbef U drh -Z 1319827703ca94f3fde0a55b291e91eb +Z 287fe50a673ea0ec508c0e86ae809b4b diff --git a/manifest.uuid b/manifest.uuid index 49d7a4d43a..f4461cd8de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b4f8be1f3258823b3a8f316c92f9019f71ef86a0 \ No newline at end of file +2d1983ff9f786ead159a900b8c023ab5507ce26b \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index d78982f5b5..7cc7b7abc7 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -536,9 +536,15 @@ static int codeAllEqualityTerms( sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j); } } - testcase( pTerm->eOperator & WO_ISNULL ); - testcase( pTerm->eOperator & WO_IN ); - if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){ + if( (pTerm->eOperator & WO_IN)!=0 ){ + if( pTerm->pExpr->flags & EP_xIsSelect ){ + /* No affinity ever needs to be (or should be) applied to a value + ** from the RHS of an "? IN (SELECT ...)" expression. The + ** sqlite3FindInIndex() routine has already ensured that the + ** affinity of the comparison has been applied to the value. */ + if( zAff ) zAff[j] = SQLITE_AFF_BLOB; + } + }else if( (pTerm->eOperator & WO_ISNULL)==0 ){ Expr *pRight = pTerm->pExpr->pRight; if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk); diff --git a/test/types2.test b/test/types2.test index 4a70aa5fe2..d6d84e65b5 100644 --- a/test/types2.test +++ b/test/types2.test @@ -333,7 +333,7 @@ ifcapable subquery { test_boolset types2-8.8 {o IN (SELECT t FROM t4)} {7} test_boolset types2-8.9 {i IN (SELECT o FROM t4)} {9 10 11 12} test_boolset types2-8.6 {n IN (SELECT o FROM t4)} {9 10 11 12} - test_boolset types2-8.7 {t IN (SELECT o FROM t4)} {9 11} + test_boolset types2-8.7 {t IN (SELECT o FROM t4)} {} test_boolset types2-8.8 {o IN (SELECT o FROM t4)} {9 10} }