From: drh Date: Fri, 23 Sep 2016 18:06:22 +0000 (+0000) Subject: Fix the ORDER BY LIMIT optimization backport so that it works when the X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4427e597b217219b5a7a853e4a1007cc6bf35bb1;p=thirdparty%2Fsqlite.git Fix the ORDER BY LIMIT optimization backport so that it works when the ORDER BY uses the DESC direction. FossilOrigin-Name: 0c3cafb7ebb887dbfa2652f8bf69b52ed265c344 --- diff --git a/manifest b/manifest index a62fe6bd61..14c7a6db34 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Backport\sthe\sORDER\sBY\sLIMIT\soptimization\sto\sversion\s3.8.9. -D 2016-09-14T01:43:24.978 +C Fix\sthe\sORDER\sBY\sLIMIT\soptimization\sbackport\sso\sthat\sit\sworks\swhen\sthe\nORDER\sBY\suses\sthe\sDESC\sdirection. +D 2016-09-23T18:06:22.679 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 00d12636df7a5b08af09116bcd6c7bfd49b8b3b4 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 878c8e1a51cb2ec45c395d26b7d5cd9e1a098e4a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 3028fd1c63c2c9a8f6897f839b01287a024b3ac9 +F src/where.c 8cb63bd44ed75c0abdee39a988255d94153fbb1e F src/whereInt.h 1d1fd0b3b9b56e08f5d3583c70a2c785a3c43941 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -698,7 +698,7 @@ F test/like.test 4f2a71d36a536233727f71995fef900756705e56 F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da F test/like3.test 7b0525a39e4f25c4fd113de7e2e28eb712dcdedf F test/limit.test 0c99a27a87b14c646a9d583c7c89fd06c352663e -F test/limit2.test ac97b8d07060a0280162ba4159e4c0c765861127 +F test/limit2.test 7e7744cc548d7e4c92e1dd3edc30dd0f86adafd5 F test/loadext.test 648cb95f324d1775c54a55c12271b2d1156b633b F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7 F test/lock.test b984ab9034e7389be0d863fe4e64cbbc4d2028f5 @@ -1250,10 +1250,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8a8ffc862e96f57aa698f93de10dee28e69f6e09 -R cb2965d27bc117ed4d5058b40e772fea -T *branch * branch-3.8.9 -T *sym-branch-3.8.9 * -T -sym-trunk * +P db3614825fa02ddacc76b85d76a37aad9d2a9dc8 +R 8fe93701829063e8060746a016609ed6 U drh -Z 9f0b78af32a328047c54447fa4f1ec76 +Z 16e3e2667c5c6f66c3599e3dc9698a2d diff --git a/manifest.uuid b/manifest.uuid index f18499c30d..5e3cf14f6a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -db3614825fa02ddacc76b85d76a37aad9d2a9dc8 \ No newline at end of file +0c3cafb7ebb887dbfa2652f8bf69b52ed265c344 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 6ebe62fcec..ac59fcaab7 100644 --- a/src/where.c +++ b/src/where.c @@ -6272,7 +6272,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ if( pWInfo->nOBSat<=0 ){ pWInfo->nOBSat = 0; if( nLoop>0 && (pFrom->aLoop[nLoop-1]->wsFlags & WHERE_ONEROW)==0 ){ - Bitmask m; + Bitmask m = 0; int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, pFrom, WHERE_ORDERBY_LIMIT, nLoop-1, pFrom->aLoop[nLoop-1], &m); if( rc==pWInfo->pOrderBy->nExpr ){ @@ -6281,7 +6281,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ } } } - pWInfo->revMask = pFrom->revLoop; } if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr diff --git a/test/limit2.test b/test/limit2.test index 0f82ab8d55..4d03180729 100644 --- a/test/limit2.test +++ b/test/limit2.test @@ -109,7 +109,15 @@ do_execsql_test limit2-310 { SELECT *,'.' FROM t300 WHERE a=0 AND (c=0 OR c=99) ORDER BY c DESC LIMIT 1; } {0 1 99 .} - - +# Make sure the SELECT loop is ordered correctly for the direction of +# the ORDER BY +# +do_execsql_test limit2-400 { + CREATE TABLE t400(a,b); + CREATE INDEX t400_ab ON t400(a,b); + INSERT INTO t400(a,b) VALUES(1,90),(1,40),(2,80),(2,30),(3,70),(3,20); + SELECT *,'x' FROM t400 WHERE a IN (1,2,3) ORDER BY b DESC LIMIT 3; + SELECT *,'y' FROM t400 WHERE a IN (1,2,3) ORDER BY +b DESC LIMIT 3; +} {1 90 x 2 80 x 3 70 x 1 90 y 2 80 y 3 70 y} finish_test