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

Proposed fix for a problem associated with OP_SeekScan that results in an

incorrect answer.  See ticket [5981a8c041a3c2f3].

FossilOrigin-Name: 266e9cbada531716c908c21d60a6038109722e3dd040237679ac0240fb5020ea
This commit is contained in:
drh
2021-11-02 20:52:20 +00:00
parent 61a8ad7cf9
commit 5d742e39d9
4 changed files with 44 additions and 9 deletions

View File

@@ -1884,8 +1884,19 @@ Bitmask sqlite3WhereCodeOneLoopStart(
** range (if any).
*/
nConstraint = nEq;
assert( pLevel->p2==0 );
if( pRangeEnd ){
Expr *pRight = pRangeEnd->pExpr->pRight;
if( addrSeekScan ){
/* For a seek-scan that has a range on the lowest term of the index,
** we have to make the top of the loop be code that sets the end
** condition of the range. Otherwise, the OP_SeekScan might jump
** over that initialization, leaving the range-end value set to the
** range-start value, resulting in a wrong answer.
** See ticket 5981a8c041a3c2f3 (2021-11-02).
*/
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
}
codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
if( (pRangeEnd->wtFlags & TERM_VNULL)==0
@@ -1919,7 +1930,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
sqlite3DbFree(db, zEndAff);
/* Top of the loop body */
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v);
/* Check if the index cursor is past the end of the range. */
if( nConstraint ){