diff options
author | drh <> | 2021-11-02 20:52:20 +0000 |
---|---|---|
committer | drh <> | 2021-11-02 20:52:20 +0000 |
commit | 5d742e39d98d8553cb321005431ece612979b635 (patch) | |
tree | 680965c0ff7f57ee89411d843a3aeeee43a880e2 /src/wherecode.c | |
parent | 61a8ad7cf952bc65b76b0a3a035ce5708459c853 (diff) | |
download | sqlite-5d742e39d98d8553cb321005431ece612979b635.tar.gz sqlite-5d742e39d98d8553cb321005431ece612979b635.zip |
Proposed fix for a problem associated with OP_SeekScan that results in an
incorrect answer. See ticket [5981a8c041a3c2f3].
FossilOrigin-Name: 266e9cbada531716c908c21d60a6038109722e3dd040237679ac0240fb5020ea
Diffstat (limited to 'src/wherecode.c')
-rw-r--r-- | src/wherecode.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/wherecode.c b/src/wherecode.c index 4dc94f7fa..460ac4fe3 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -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 ){ |