diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.c | 22 | ||||
-rw-r--r-- | src/where.c | 8 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/expr.c b/src/expr.c index 52f7cdb7d..10393e0a5 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.399 2008/10/11 16:47:36 drh Exp $ +** $Id: expr.c,v 1.400 2008/10/25 15:03:21 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1718,7 +1718,7 @@ void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){ ** of the iAlias-th alias is stored. If zero, that means that the ** alias has not yet been computed. */ -static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){ +static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr, int target){ sqlite3 *db = pParse->db; int iReg; if( pParse->aAlias==0 ){ @@ -1729,9 +1729,13 @@ static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){ assert( iAlias>0 && iAlias<=pParse->nAlias ); iReg = pParse->aAlias[iAlias-1]; if( iReg==0 ){ - iReg = ++pParse->nMem; - sqlite3ExprCode(pParse, pExpr, iReg); - pParse->aAlias[iAlias-1] = iReg; + if( pParse->disableColCache ){ + iReg = sqlite3ExprCodeTarget(pParse, pExpr, target); + }else{ + iReg = ++pParse->nMem; + sqlite3ExprCode(pParse, pExpr, iReg); + pParse->aAlias[iAlias-1] = iReg; + } } return iReg; } @@ -1840,7 +1844,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ break; } case TK_AS: { - inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft); + inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft, target); break; } #ifndef SQLITE_OMIT_CAST @@ -2500,9 +2504,11 @@ int sqlite3ExprCodeExprList( n = pList->nExpr; for(pItem=pList->a, i=0; i<n; i++, pItem++){ if( pItem->iAlias ){ - int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr); + int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr, target+i); Vdbe *v = sqlite3GetVdbe(pParse); - sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i); + if( iReg!=target+i ){ + sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i); + } }else{ sqlite3ExprCode(pParse, pItem->pExpr, target+i); } diff --git a/src/where.c b/src/where.c index 22a3598cd..d5f8dabd2 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.326 2008/10/11 16:47:36 drh Exp $ +** $Id: where.c,v 1.327 2008/10/25 15:03:21 drh Exp $ */ #include "sqliteInt.h" @@ -2349,7 +2349,7 @@ WhereInfo *sqlite3WhereBegin( */ notReady = ~(Bitmask)0; for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ - int j; + int j, k; int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */ Index *pIdx; /* The index we will be using */ int nxt; /* Where to jump to continue with the next IN case */ @@ -2716,6 +2716,7 @@ WhereInfo *sqlite3WhereBegin( /* Insert code to test every subexpression that can be completely ** computed using the current set of tables. */ + k = 0; for(pTerm=wc.a, j=wc.nTerm; j>0; j--, pTerm++){ Expr *pE; testcase( pTerm->flags & TERM_VIRTUAL ); @@ -2727,7 +2728,10 @@ WhereInfo *sqlite3WhereBegin( if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){ continue; } + pParse->disableColCache += k; sqlite3ExprIfFalse(pParse, pE, cont, SQLITE_JUMPIFNULL); + pParse->disableColCache -= k; + k = 1; pTerm->flags |= TERM_CODED; } |