diff options
author | drh <drh@noemail.net> | 2016-09-07 01:51:46 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-09-07 01:51:46 +0000 |
commit | 57a8c615015de9f6d49fb259093db818735fe28c (patch) | |
tree | 7a742f9cd4cf55f25b1bc1d91543c1dc7bb7a377 /src/where.c | |
parent | 9f6dd025ba84d927c654b290bb23fa9a1630badc (diff) | |
download | sqlite-57a8c615015de9f6d49fb259093db818735fe28c.tar.gz sqlite-57a8c615015de9f6d49fb259093db818735fe28c.zip |
The ORDER BY LIMIT optimization is not valid unless the inner-most IN operator
loop is actually used by the query plan.
Fix for ticket [0c4df46116e90f92].
FossilOrigin-Name: 820644b886f81e991fceb5f1c3290b8959b34528
Diffstat (limited to 'src/where.c')
-rw-r--r-- | src/where.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/where.c b/src/where.c index c2706dc5d..c18c09d7f 100644 --- a/src/where.c +++ b/src/where.c @@ -3401,6 +3401,14 @@ static i8 wherePathSatisfiesOrderBy( pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn, ~ready, eqOpMask, 0); if( pTerm==0 ) continue; + if( pTerm->eOperator==WO_IN ){ + /* IN terms are only valid for sorting in the ORDER BY LIMIT + ** optimization, and then only if they are actually used + ** by the query plan */ + assert( wctrlFlags & WHERE_ORDERBY_LIMIT ); + for(j=0; j<pLoop->nLTerm && pTerm!=pLoop->aLTerm[j]; j++){} + if( j>=pLoop->nLTerm ) continue; + } if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){ const char *z1, *z2; pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr); |