1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Simplification of the skip-ahead-distinct logic. There is still an issue

with handling COLLATE.

FossilOrigin-Name: 57c5173b6376a76013b0611ce9770100bd8c04e80402e35d821d8614709f4795
This commit is contained in:
drh
2017-04-13 19:48:29 +00:00
parent a74f5c2923
commit c04ea80f64
3 changed files with 23 additions and 24 deletions

View File

@@ -3437,7 +3437,7 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
}
/*
** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
** parameters) to see if it outputs rows in the requested ORDER BY
** (or GROUP BY) without requiring a separate sort operation. Return N:
**
@@ -4849,6 +4849,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
pLoop = pLevel->pWLoop;
if( pLevel->op!=OP_Noop ){
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
int addrSeek = 0;
int n = -1;
int j, k, op;
int r1 = pParse->nMem+1;
@@ -4897,25 +4898,23 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
}
pParse->nMem += n;
op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
k = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
VdbeCoverageIf(v, op==OP_SeekLT);
VdbeCoverageIf(v, op==OP_SeekGT);
sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
sqlite3VdbeJumpHere(v, k);
}else
#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
{
/* The common case: Advance to the next row */
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
sqlite3VdbeChangeP5(v, pLevel->p5);
VdbeCoverage(v);
VdbeCoverageIf(v, pLevel->op==OP_Next);
VdbeCoverageIf(v, pLevel->op==OP_Prev);
VdbeCoverageIf(v, pLevel->op==OP_VNext);
}
#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
/* The common case: Advance to the next row */
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
sqlite3VdbeChangeP5(v, pLevel->p5);
VdbeCoverage(v);
VdbeCoverageIf(v, pLevel->op==OP_Next);
VdbeCoverageIf(v, pLevel->op==OP_Prev);
VdbeCoverageIf(v, pLevel->op==OP_VNext);
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
#endif
}else{
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
}