From 413b94af8931eceb52b329ee0019628eb059e217 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 10 Jul 2020 19:09:40 +0000 Subject: [PATCH] An attempt to get the Min/Max optimization working with IN constraints. Not currently working. FossilOrigin-Name: 4a64c16fb7a07431e534fb9bbcf778646be8a1c718d5d10873fbccb0c867aac7 --- manifest | 18 +++++++++++------- manifest.uuid | 2 +- src/select.c | 5 ----- src/where.c | 13 ++++++++++++- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index a80c023d2c..550c4e40bc 100644 --- a/manifest +++ b/manifest @@ -1,6 +1,6 @@ B 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b -C Fix\shandling\sof\sanother\scorrupt\sdatabase\scase\sin\sfts3. -D 2020-07-09T21:29:34.103 +C An\sattempt\sto\sget\sthe\sMin/Max\soptimization\sworking\swith\sIN\sconstraints.\nNot\scurrently\sworking. +D 2020-07-10T19:09:40.123 F Makefile.in 19374a5db06c3199ec1bab71ab74a103d8abf21053c05e9389255dc58083f806 F Makefile.msc 48f5a3fc32672c09ad73795749f6253e406a31526935fbbffd8f021108d54574 F autoconf/Makefile.am a8d1d24affe52ebf8d7ddcf91aa973fa0316618ab95bb68c87cabf8faf527dc8 @@ -21,7 +21,7 @@ F src/parse.y b6b4b02f8cc8f94ac1d93a922543e0344dbb30b04877898736c01ec7ec03eaaa F src/pragma.c ae499b5ab8f4e833f67e28bf2322500e9aa612aadf12581d1324333f848d8b51 F src/pragma.h 8dc78ab7e9ec6ce3ded8332810a2066f1ef6267e2e03cd7356ee00276125c6cf F src/resolve.c 79cee37182fea66703f90365b8b0a646ed7e9bfa9238b91fa90dfc74258b940e -F src/select.c 860daa05592ed1b38f6266f067fa020b539548ab929aa60fa59e7681e7f3f8cb +F src/select.c 14d212b94088cf06f0074f080e46f858b36bf55a772029a7d006a16b305fe5a8 F src/shell.c.in 81fa23ac1a3d6ac9ed13e9ae711a3d8806396ca7cc12c5d6a2e2536f70b0c7ad F src/sqliteInt.h f89ed824bc55b6bd90ca692518f85eeb22f8962d46e0e12cad989d4aee1e7b8c F src/test1.c fe56c4bcaa2685ca9aa25d817a0ee9345e189aff4a5a71a3d8ba946c7776feb8 @@ -29,6 +29,7 @@ F src/update.c 6a0484134635f167594d597a33d186051125d3ef41803a90b246cea6cf7f11f9 F src/util.c c0bacc165f46169d2b720c37c8719165e383211698fad1de39dd16a8c161815a F src/vdbe.c 981666c49d33039df6dc9fccd40191575586ac4866255b2f57819cc5eb99f572 F src/vdbeapi.c c1a9004ac554d8d48794d2ce5f80397f8e419fd28643a543cc1e004c7713c3ef +F src/where.c a485bc1ec23b04ef6e7868abc559b8adc4c3fdc3314222386928b2e47f1e4505 F test/altertab.test b8b2104212e8ea87c75c3cbe3cb78ed7236a6c828ee2e59ed09d3dbe9812d002 F test/busy2.test 415364312743992641f9bf679c84918327296067f85a5d00012b339dc35acbd7 F test/decimal.test 12739a01bdba4c4d79f95b323e6b67b9fad1ab6ffb56116bd2b9c81a5b19e1d9 @@ -46,7 +47,10 @@ F tool/mksqlite3c.tcl f4ef476510eca4124c874a72029f1e01bc54a896b1724e8f9eef0d8bfa F tool/mksqlite3h.tcl 1f5e4a1dbbbc43c83cc6e74fe32c6c620502240b66c7c0f33a51378e78fc4edf F tool/showlocks.c 9cc5e66d4ebbf2d194f39db2527ece92077e86ae627ddd233ee48e16e8142564 F tool/speed-check.sh 615cbdf50f1409ef3bbf9f682e396df80f49d97ed93ed3e61c8e91fae6afde58 -P 610ee8d5dc855fd163daa3c93b44db7874463d69df5a01ab4113b725a031b9d4 -R f506df3e64449a71a2d48ebddc1578d7 -U dan -Z 1f24dc1574d5c512fe643a8c300eaca2 +P ccff8cb8267d4c5605484f7a35c1836937f20b3d6879fe84cd84dc24bbbffc77 +R 35d6b9743e23c38e933ae2f7f81185b9 +T *branch * minmax-opt-exp +T *sym-minmax-opt-exp * +T -sym-trunk * +U drh +Z 4df4fe61b85919c997c14bcb75af2a60 diff --git a/manifest.uuid b/manifest.uuid index 83875f548d..ddb1bc4f91 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ccff8cb8267d4c5605484f7a35c1836937f20b3d6879fe84cd84dc24bbbffc77 \ No newline at end of file +4a64c16fb7a07431e534fb9bbcf778646be8a1c718d5d10873fbccb0c867aac7 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 2df58fccd0..fcaf5aaee6 100644 --- a/src/select.c +++ b/src/select.c @@ -6769,11 +6769,6 @@ int sqlite3Select( } updateAccumulator(pParse, regAcc, pAggInfo); if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc); - if( sqlite3WhereIsOrdered(pWInfo)>0 ){ - sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo)); - VdbeComment((v, "%s() by index", - (minMaxFlag==WHERE_ORDERBY_MIN?"min":"max"))); - } sqlite3WhereEnd(pWInfo); finalizeAggFunctions(pParse, pAggInfo); } diff --git a/src/where.c b/src/where.c index a7df4b9b80..b88afc1097 100644 --- a/src/where.c +++ b/src/where.c @@ -3740,7 +3740,9 @@ static i8 wherePathSatisfiesOrderBy( orderDistinctMask = 0; ready = 0; eqOpMask = WO_EQ | WO_IS | WO_ISNULL; - if( wctrlFlags & WHERE_ORDERBY_LIMIT ) eqOpMask |= WO_IN; + if( wctrlFlags & (WHERE_ORDERBY_LIMIT|WHERE_ORDERBY_MAX|WHERE_ORDERBY_MIN) ){ + eqOpMask |= WO_IN; + } for(iLoop=0; isOrderDistinct && obSat0 ) ready |= pLoop->maskSelf; if( iLoopnOBSat==1 + && (pWInfo->wctrlFlags & (WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX))!=0 + ){ + pFrom->aLoop[nLoop-1]->wsFlags |= WHERE_ONEROW; } } if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) @@ -5328,6 +5334,11 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ #endif }else{ sqlite3VdbeResolveLabel(v, pLevel->addrCont); + if( pLevel->regBignull ){ + sqlite3VdbeResolveLabel(v, pLevel->addrBignull); + sqlite3VdbeAddOp2(v, OP_DecrJumpZero, pLevel->regBignull, pLevel->p2-1); + VdbeCoverage(v); + } } if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){ struct InLoop *pIn;