aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2014-02-26 02:26:09 +0000
committerdrh <drh@noemail.net>2014-02-26 02:26:09 +0000
commit434a93147cfa23b7a9bd49fef8f1f1b59c9da4d3 (patch)
tree09edd3af9284a5b999c4ddcad3e1b877b0b52692 /src
parent0baa035a1e3339d8bb0aea2205a2dee4f56fcc9e (diff)
downloadsqlite-434a93147cfa23b7a9bd49fef8f1f1b59c9da4d3.tar.gz
sqlite-434a93147cfa23b7a9bd49fef8f1f1b59c9da4d3.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/where.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/where.c b/src/where.c
index f5d44a387..a5dd7b59e 100644
--- a/src/where.c
+++ b/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. */