diff options
author | drh <drh@noemail.net> | 2006-12-16 16:25:15 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2006-12-16 16:25:15 +0000 |
commit | 61dfc31d807d8958c18a37c0dcb0c155bd349b69 (patch) | |
tree | 44916e207f8ed871edf708e6ad60af6b90a86e0f /src/expr.c | |
parent | f0fa1c1b9fca7b7c849ffaf2bc15d6cf9f97ff2e (diff) | |
download | sqlite-61dfc31d807d8958c18a37c0dcb0c155bd349b69.tar.gz sqlite-61dfc31d807d8958c18a37c0dcb0c155bd349b69.zip |
Query optimizer enhancement: In "FROM a,b,c left join d" allow the C table
to be reordered with A and B. This used to be the case but the capability
was removed by (3203) and (3052) in response to ticket #1652. This change
restores the capability. (CVS 3529)
FossilOrigin-Name: 7393c81b8cb9d4344ae744de9eabcb3af64f1db8
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/expr.c b/src/expr.c index 2ea27f5b8..1d5e186a0 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.269 2006/11/23 11:59:13 drh Exp $ +** $Id: expr.c,v 1.270 2006/12/16 16:25:15 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -891,22 +891,23 @@ static int lookupName( pExpr->iColumn = j==pTab->iPKey ? -1 : j; pExpr->affinity = pTab->aCol[j].affinity; pExpr->pColl = sqlite3FindCollSeq(db, ENC(db), zColl,-1, 0); - if( pItem->jointype & JT_NATURAL ){ - /* If this match occurred in the left table of a natural join, - ** then skip the right table to avoid a duplicate match */ - pItem++; - i++; - } - if( (pUsing = pItem->pUsing)!=0 ){ - /* If this match occurs on a column that is in the USING clause - ** of a join, skip the search of the right table of the join - ** to avoid a duplicate match there. */ - int k; - for(k=0; k<pUsing->nId; k++){ - if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ){ - pItem++; - i++; - break; + if( i<pSrcList->nSrc-1 ){ + if( pItem[1].jointype & JT_NATURAL ){ + /* If this match occurred in the left table of a natural join, + ** then skip the right table to avoid a duplicate match */ + pItem++; + i++; + }else if( (pUsing = pItem[1].pUsing)!=0 ){ + /* If this match occurs on a column that is in the USING clause + ** of a join, skip the search of the right table of the join + ** to avoid a duplicate match there. */ + int k; + for(k=0; k<pUsing->nId; k++){ + if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ){ + pItem++; + i++; + break; + } } } } |