1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-21 09:00:59 +03:00

Do not suppress the ORDER BY clause on a virtual table query if an IN

constraint is used.  Fix for ticket [f69b96e3076e].  Testing done on
TH3 using cov1/where37.test.

FossilOrigin-Name: 61b2a7be3b9c04bf45bffa93a7d3a480fc5c947a
This commit is contained in:
drh
2013-04-18 02:55:54 +00:00
parent 44fddcad02
commit 83b5bfc7d3
3 changed files with 15 additions and 18 deletions

View File

@@ -2275,9 +2275,8 @@ static void bestVirtualIndex(WhereBestIdx *p){
struct sqlite3_index_constraint *pIdxCons;
struct sqlite3_index_constraint_usage *pUsage;
WhereTerm *pTerm;
int i, j, k;
int i, j;
int nOrderBy;
int sortOrder; /* Sort order for IN clauses */
int bAllowIN; /* Allow IN optimizations */
double rCost;
@@ -2376,7 +2375,6 @@ static void bestVirtualIndex(WhereBestIdx *p){
return;
}
sortOrder = SQLITE_SO_ASC;
pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){
if( pUsage[i].argvIndex>0 ){
@@ -2391,12 +2389,12 @@ static void bestVirtualIndex(WhereBestIdx *p){
** repeated in the output. */
break;
}
for(k=0; k<pIdxInfo->nOrderBy; k++){
if( pIdxInfo->aOrderBy[k].iColumn==pIdxCons->iColumn ){
sortOrder = pIdxInfo->aOrderBy[k].desc;
break;
}
}
/* A virtual table that is constrained by an IN clause may not
** consume the ORDER BY clause because (1) the order of IN terms
** is not necessarily related to the order of output terms and
** (2) Multiple outputs from a single IN value will not merge
** together. */
pIdxInfo->orderByConsumed = 0;
}
}
}
@@ -2426,8 +2424,7 @@ static void bestVirtualIndex(WhereBestIdx *p){
}
p->cost.plan.u.pVtabIdx = pIdxInfo;
if( pIdxInfo->orderByConsumed ){
assert( sortOrder==0 || sortOrder==1 );
p->cost.plan.wsFlags |= WHERE_ORDERED + sortOrder*WHERE_REVERSE;
p->cost.plan.wsFlags |= WHERE_ORDERED;
p->cost.plan.nOBSat = nOrderBy;
}else{
p->cost.plan.nOBSat = p->i ? p->aLevel[p->i-1].plan.nOBSat : 0;