mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-18 10:21:03 +03:00
When constructing the sqlite3_index_info object for the xBestIndex method
of a virtual table, omit constant trims from the ORDER BY clause, as they will always be in the correct order. FossilOrigin-Name: 524c2b87d74c8cad6fb377aed7275788d61beafe61e675480de732519987102c
This commit is contained in:
15
src/where.c
15
src/where.c
@@ -1164,6 +1164,11 @@ static sqlite3_index_info *allocateIndexInfo(
|
||||
Expr *pExpr = pOrderBy->a[i].pExpr;
|
||||
Expr *pE2;
|
||||
|
||||
/* Skip over constant terms in the ORDER BY clause */
|
||||
if( sqlite3ExprIsConstant(pExpr) ){
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Virtual tables are unable to deal with NULLS FIRST */
|
||||
if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
|
||||
|
||||
@@ -1211,7 +1216,6 @@ static sqlite3_index_info *allocateIndexInfo(
|
||||
pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
|
||||
pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
|
||||
pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
|
||||
pIdxInfo->nOrderBy = nOrderBy;
|
||||
pIdxInfo->aConstraint = pIdxCons;
|
||||
pIdxInfo->aOrderBy = pIdxOrderBy;
|
||||
pIdxInfo->aConstraintUsage = pUsage;
|
||||
@@ -1258,14 +1262,17 @@ static sqlite3_index_info *allocateIndexInfo(
|
||||
}
|
||||
assert( j==nTerm );
|
||||
pIdxInfo->nConstraint = j;
|
||||
for(i=0; i<nOrderBy; i++){
|
||||
for(i=j=0; i<nOrderBy; i++){
|
||||
Expr *pExpr = pOrderBy->a[i].pExpr;
|
||||
if( sqlite3ExprIsConstant(pExpr) ) continue;
|
||||
assert( pExpr->op==TK_COLUMN
|
||||
|| (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
|
||||
&& pExpr->iColumn==pExpr->pLeft->iColumn) );
|
||||
pIdxOrderBy[i].iColumn = pExpr->iColumn;
|
||||
pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
|
||||
pIdxOrderBy[j].iColumn = pExpr->iColumn;
|
||||
pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
|
||||
j++;
|
||||
}
|
||||
pIdxInfo->nOrderBy = j;
|
||||
|
||||
*pmNoOmit = mNoOmit;
|
||||
return pIdxInfo;
|
||||
|
||||
Reference in New Issue
Block a user