From 52fc05ba1c4c297560ec28906b2902e2a3c522c5 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 7 Mar 2015 20:32:49 +0000 Subject: [PATCH] Fix another problem with the LIKE optimization. FossilOrigin-Name: 465bfc72d252f94778248253142faeba78ceea02 --- manifest | 16 +++++++++------- manifest.uuid | 2 +- src/where.c | 26 +++++++++++++++----------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 55fca4b7f9..8ac17721f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sLIKE\soptimization\sso\sthat\sit\sfinds\sBLOB\sentries\sin\saddition\sto\stext\nentries.\s\sTicket\s[05f43be8fdda9f]. -D 2015-03-07T13:56:48.044 +C Fix\sanother\sproblem\swith\sthe\sLIKE\soptimization. +D 2015-03-07T20:32:49.790 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f643d6968dfc0b82d2e546a0525a39079f9e928 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -307,7 +307,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 84104123394d38aa530f4e3e12b4ac7efcd7fe19 +F src/where.c 65813699926c15b7041ff2021731f03183aac493 F src/whereInt.h cbe4aa57326998d89e7698ca65bb7c28541d483c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1241,8 +1241,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 8c1e85aab9e0d90726057e25e2ea0663341c070f 50fa3c5fae90bd3b2f4121e99ab52d79963a6fda -R 2fc7830b1fa14938513120a1368ba854 -T +closed 50fa3c5fae90bd3b2f4121e99ab52d79963a6fda +P 74cb0b032fcf598537fae04412771450124ae712 +R 23dd5631417bc0e4cabfa079f9a22509 +T *branch * like-opt-fix +T *sym-like-opt-fix * +T -sym-trunk * U drh -Z 4859c93f290241201b6571a3ac6035f4 +Z c34701a311a2e64477c46e48ef38102d diff --git a/manifest.uuid b/manifest.uuid index e2d06d5c80..e3c0591701 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74cb0b032fcf598537fae04412771450124ae712 \ No newline at end of file +465bfc72d252f94778248253142faeba78ceea02 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 64c9652b0b..3e2558d00e 100644 --- a/src/where.c +++ b/src/where.c @@ -3024,12 +3024,17 @@ static void addScanStatus( ** bound string contants to blobs. This routine makes the necessary changes ** to the OP_String opcodes for that to happen. */ -static void whereLikeOptimizationStringFixup(Vdbe *v, WhereLevel *pLevel){ - VdbeOp *pOp; - pOp = sqlite3VdbeGetOp(v, -1); - if( pLevel->iLikeRepCntr && pOp->opcode==OP_String8 ){ - pOp->p3 = pLevel->iLikeRepCntr; - pOp->p5 = 1; +static void whereLikeOptimizationStringFixup( + Vdbe *v, /* prepared statement under construction */ + WhereLevel *pLevel, /* The loop that contains the LIKE operator */ + WhereTerm *pTerm /* The upper or lower bound just coded */ +){ + if( pTerm->wtFlags & TERM_LIKEOPT ){ + VdbeOp *pOp = sqlite3VdbeGetOp(v, -1); + if( pLevel->iLikeRepCntr && pOp->opcode==OP_String8 ){ + pOp->p3 = pLevel->iLikeRepCntr; + pOp->p5 = 1; + } } } @@ -3365,9 +3370,8 @@ static Bitmask codeOneLoopStart( if( pLoop->wsFlags & WHERE_TOP_LIMIT ){ pRangeEnd = pLoop->aLTerm[j++]; nExtraReg = 1; - if( pRangeStart - && (pRangeStart->wtFlags & TERM_LIKEOPT)!=0 - && (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 + if( (pRangeStart && (pRangeStart->wtFlags & TERM_LIKEOPT)!=0) + || (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){ pLevel->iLikeRepCntr = ++pParse->nMem; testcase( bRev ); @@ -3420,7 +3424,7 @@ static Bitmask codeOneLoopStart( if( pRangeStart ){ Expr *pRight = pRangeStart->pExpr->pRight; sqlite3ExprCode(pParse, pRight, regBase+nEq); - whereLikeOptimizationStringFixup(v, pLevel); + whereLikeOptimizationStringFixup(v, pLevel, pRangeStart); if( (pRangeStart->wtFlags & TERM_VNULL)==0 && sqlite3ExprCanBeNull(pRight) ){ @@ -3466,7 +3470,7 @@ static Bitmask codeOneLoopStart( Expr *pRight = pRangeEnd->pExpr->pRight; sqlite3ExprCacheRemove(pParse, regBase+nEq, 1); sqlite3ExprCode(pParse, pRight, regBase+nEq); - whereLikeOptimizationStringFixup(v, pLevel); + whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd); if( (pRangeEnd->wtFlags & TERM_VNULL)==0 && sqlite3ExprCanBeNull(pRight) ){