aboutsummaryrefslogtreecommitdiff
path: root/src/wherecode.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2016-09-03 15:31:20 +0000
committerdan <dan@noemail.net>2016-09-03 15:31:20 +0000
commit271896031628a161bc0c3937dc90af01029e8bdf (patch)
treed059c36476e371d078cfd4696429e51788d0827d /src/wherecode.c
parent4910a76d4501b11fdc639c01e531d5100401b444 (diff)
downloadsqlite-271896031628a161bc0c3937dc90af01029e8bdf.tar.gz
sqlite-271896031628a161bc0c3937dc90af01029e8bdf.zip
Consider the affinity of "b" when using an "a IN (SELECT b ...)" expression with an index on "a". Fix for [199df416].
FossilOrigin-Name: f5e49855412e389a8a410db5d7ffb2e3634c5fa3
Diffstat (limited to 'src/wherecode.c')
-rw-r--r--src/wherecode.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/wherecode.c b/src/wherecode.c
index 16ffb89db..896509bc3 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -649,13 +649,21 @@ static int codeAllEqualityTerms(
}
testcase( pTerm->eOperator & WO_ISNULL );
testcase( pTerm->eOperator & WO_IN );
- if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
- Expr *pRight = pTerm->pExpr->pRight;
- if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
- sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
- VdbeCoverage(v);
+ if( (pTerm->eOperator & WO_ISNULL)==0 ){
+ Expr *pRight = 0;
+ if( pTerm->eOperator & WO_IN ){
+ if( pTerm->pExpr->flags & EP_xIsSelect ){
+ int iField = pTerm->iField ? pTerm->iField-1 : 0;
+ pRight = pTerm->pExpr->x.pSelect->pEList->a[iField].pExpr;
+ }
+ }else{
+ pRight = pTerm->pExpr->pRight;
+ if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
+ VdbeCoverage(v);
+ }
}
- if( zAff ){
+ if( pRight && zAff ){
if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
zAff[j] = SQLITE_AFF_BLOB;
}