mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Simplify the range scan code generate while also avoiding an unnecessary
OP_Affinity opcode. FossilOrigin-Name: 372686bfbb1da08b04bddb085e30da5dbc8b30d8
This commit is contained in:
23
src/where.c
23
src/where.c
@@ -3001,7 +3001,7 @@ static Bitmask codeOneLoopStart(
|
||||
int nExtraReg = 0; /* Number of extra registers needed */
|
||||
int op; /* Instruction opcode */
|
||||
char *zStartAff; /* Affinity for start of range constraint */
|
||||
char *zEndAff; /* Affinity for end of range constraint */
|
||||
char cEndAff = 0; /* Affinity for end of range constraint */
|
||||
|
||||
pIdx = pLoop->u.btree.pIndex;
|
||||
iIdxCur = pLevel->iIdxCur;
|
||||
@@ -3042,7 +3042,8 @@ static Bitmask codeOneLoopStart(
|
||||
** starting at regBase.
|
||||
*/
|
||||
regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
|
||||
zEndAff = sqlite3DbStrDup(db, zStartAff);
|
||||
assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
|
||||
if( zStartAff ) cEndAff = zStartAff[nEq];
|
||||
addrNxt = pLevel->addrNxt;
|
||||
|
||||
/* If we are doing a reverse order scan on an ascending index, or
|
||||
@@ -3112,23 +3113,15 @@ static Bitmask codeOneLoopStart(
|
||||
if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
|
||||
sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
|
||||
}
|
||||
if( zEndAff ){
|
||||
if( sqlite3CompareAffinity(pRight, zEndAff[nEq])==SQLITE_AFF_NONE){
|
||||
/* Since the comparison is to be performed with no conversions
|
||||
** applied to the operands, set the affinity to apply to pRight to
|
||||
** SQLITE_AFF_NONE. */
|
||||
zEndAff[nEq] = SQLITE_AFF_NONE;
|
||||
}
|
||||
if( sqlite3ExprNeedsNoAffinityChange(pRight, zEndAff[nEq]) ){
|
||||
zEndAff[nEq] = SQLITE_AFF_NONE;
|
||||
}
|
||||
}
|
||||
codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
|
||||
if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
|
||||
&& !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
|
||||
){
|
||||
codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
|
||||
}
|
||||
nConstraint++;
|
||||
testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
|
||||
}
|
||||
sqlite3DbFree(db, zStartAff);
|
||||
sqlite3DbFree(db, zEndAff);
|
||||
|
||||
/* Top of the loop body */
|
||||
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
|
||||
|
||||
Reference in New Issue
Block a user