mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Improved handling of constants and especially constant functions in the
ORDER BY clause of a query. Do not optimize out "ORDER BY random()". Fix for ticket [65bdeb9739605cc2296]. FossilOrigin-Name: dca1945aeb3fb005263f9be00ee8e72b966ae303
This commit is contained in:
21
src/where.c
21
src/where.c
@@ -4901,9 +4901,12 @@ static int wherePathSatisfiesOrderBy(
|
||||
orderDistinctMask |= pLoop->maskSelf;
|
||||
for(i=0; i<nOrderBy; i++){
|
||||
Expr *p;
|
||||
Bitmask mTerm;
|
||||
if( MASKBIT(i) & obSat ) continue;
|
||||
p = pOrderBy->a[i].pExpr;
|
||||
if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){
|
||||
mTerm = exprTableUsage(&pWInfo->sMaskSet,p);
|
||||
if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue;
|
||||
if( (mTerm&~orderDistinctMask)==0 ){
|
||||
obSat |= MASKBIT(i);
|
||||
}
|
||||
}
|
||||
@@ -5526,22 +5529,6 @@ WhereInfo *sqlite3WhereBegin(
|
||||
goto whereBeginError;
|
||||
}
|
||||
|
||||
/* If the ORDER BY (or GROUP BY) clause contains references to general
|
||||
** expressions, then we won't be able to satisfy it using indices, so
|
||||
** go ahead and disable it now.
|
||||
*/
|
||||
if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
|
||||
for(ii=0; ii<pOrderBy->nExpr; ii++){
|
||||
Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
|
||||
if( pExpr->op!=TK_COLUMN ){
|
||||
pWInfo->pOrderBy = pOrderBy = 0;
|
||||
break;
|
||||
}else if( pExpr->iColumn<0 ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( wctrlFlags & WHERE_WANT_DISTINCT ){
|
||||
if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
|
||||
/* The DISTINCT marking is pointless. Ignore it. */
|
||||
|
||||
Reference in New Issue
Block a user