diff options
author | drh <drh@noemail.net> | 2015-08-26 14:01:41 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-08-26 14:01:41 +0000 |
commit | 5579d59fb3ccb9e9db9913a5bd50871d8e893d95 (patch) | |
tree | bd2507abb65a3e31578751108f0eef1baafefae2 /src/expr.c | |
parent | 0576bc59a730c57f14f037dc90a28d0a7ec2d51f (diff) | |
download | sqlite-5579d59fb3ccb9e9db9913a5bd50871d8e893d95.tar.gz sqlite-5579d59fb3ccb9e9db9913a5bd50871d8e893d95.zip |
Evaluate expressions only once when the same expression is used in both the
result set and in the ORDER BY clause.
FossilOrigin-Name: c2f3bbad778504681b39ab9399a1eb3c1a35ab3f
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/expr.c b/src/expr.c index 1aebef6b1..71c552c68 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2912,7 +2912,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ } sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */ - sqlite3ExprCodeExprList(pParse, pFarg, r1, + sqlite3ExprCodeExprList(pParse, pFarg, r1, 0, SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR); sqlite3ExprCachePop(pParse); /* Ticket 2ea2425d34be */ }else{ @@ -3328,11 +3328,13 @@ int sqlite3ExprCodeExprList( Parse *pParse, /* Parsing context */ ExprList *pList, /* The expression list to be coded */ int target, /* Where to write results */ + int srcReg, /* Source registers if SQLITE_ECEL_REF */ u8 flags /* SQLITE_ECEL_* flags */ ){ struct ExprList_item *pItem; - int i, n; + int i, j, n; u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy; + Vdbe *v = pParse->pVdbe; assert( pList!=0 ); assert( target>0 ); assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */ @@ -3340,13 +3342,14 @@ int sqlite3ExprCodeExprList( if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR; for(pItem=pList->a, i=0; i<n; i++, pItem++){ Expr *pExpr = pItem->pExpr; - if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ + if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){ + sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i); + }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); }else{ int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); if( inReg!=target+i ){ VdbeOp *pOp; - Vdbe *v = pParse->pVdbe; if( copyOp==OP_Copy && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy && pOp->p1+pOp->p3+1==inReg |