1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-15 11:41:13 +03:00

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
This commit is contained in:
drh
2016-09-07 01:51:46 +00:00
parent 9f6dd025ba
commit 57a8c61501
4 changed files with 28 additions and 9 deletions

View File

@@ -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);