aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan <dan@noemail.net>2018-04-24 18:53:24 +0000
committerdan <dan@noemail.net>2018-04-24 18:53:24 +0000
commit820fcd2ce9379d3ee4619016c53f450b6422332b (patch)
tree4a2d7129ae10957534a89addf1ae09f3c60617fe /src
parentc447595df535cf900bfc47fd6ff0524f2ee6837a (diff)
downloadsqlite-820fcd2ce9379d3ee4619016c53f450b6422332b.tar.gz
sqlite-820fcd2ce9379d3ee4619016c53f450b6422332b.zip
Fix a problem with processing "LEFT JOIN tbl ON tbl.a = ? AND (tbl.b=? OR
tbl.c=?)" in cases where there are indexes on both tbl(a, b) and tbl(a, c). FossilOrigin-Name: ce35e39c5cc2b00dd6b4a9ffaa9d5eb7d9b862759e87d5f053729de7643eee9c
Diffstat (limited to 'src')
-rw-r--r--src/wherecode.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/wherecode.c b/src/wherecode.c
index 3432d4b6b..818a7a208 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -1215,6 +1215,9 @@ Bitmask sqlite3WhereCodeOneLoopStart(
** initialize a memory cell that records if this table matches any
** row of the left table of the join.
*/
+ assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
+ || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
+ );
if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
pLevel->iLeftJoin = ++pParse->nMem;
sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
@@ -1913,7 +1916,6 @@ Bitmask sqlite3WhereCodeOneLoopStart(
for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
Expr *pExpr = pWC->a[iTerm].pExpr;
if( &pWC->a[iTerm] == pTerm ) continue;
- if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
@@ -1938,7 +1940,10 @@ Bitmask sqlite3WhereCodeOneLoopStart(
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
int jmp1 = 0; /* Address of jump operation */
- if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
+ assert( (pTabItem[0].fg.jointype & JT_LEFT)==0
+ || ExprHasProperty(pOrExpr, EP_FromJoin)
+ );
+ if( pAndExpr ){
pAndExpr->pLeft = pOrExpr;
pOrExpr = pAndExpr;
}
@@ -2121,7 +2126,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
}
pE = pTerm->pExpr;
assert( pE!=0 );
- if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
+ if( (pTabItem->fg.jointype&JT_LEFT) && !ExprHasProperty(pE,EP_FromJoin) ){
continue;
}