diff options
author | drh <drh@noemail.net> | 2009-02-20 03:55:05 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2009-02-20 03:55:05 +0000 |
commit | 08de14908d354c34206db249807703683e84676a (patch) | |
tree | e9ee637fd892230952aeecb9638f32713c26b7b1 /src/expr.c | |
parent | 5053a79b6ce3fde5f832a0af9206571e7aca19bd (diff) | |
download | sqlite-08de14908d354c34206db249807703683e84676a.tar.gz sqlite-08de14908d354c34206db249807703683e84676a.zip |
Add a count parameter to the OP_Variable opcode and use it to simplify
prepared statements that copy consecutive unnamed parameters into
consecutive registers (a common case). (CVS 6309)
FossilOrigin-Name: 48b77b04935d8942eb22f0c061f3bc5e99bbd7db
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/expr.c b/src/expr.c index ef7c54d28..8bc85fcb5 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.412 2009/02/19 14:39:25 danielk1977 Exp $ +** $Id: expr.c,v 1.413 2009/02/20 03:55:05 drh Exp $ */ #include "sqliteInt.h" @@ -2002,9 +2002,26 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ } #endif case TK_VARIABLE: { - sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iTable, target); - if( pExpr->token.n>1 ){ - sqlite3VdbeChangeP4(v, -1, (char*)pExpr->token.z, pExpr->token.n); + int iPrior; + VdbeOp *pOp; + if( pExpr->token.n<=1 + && (iPrior = sqlite3VdbeCurrentAddr(v)-1)>=0 + && (pOp = sqlite3VdbeGetOp(v, iPrior))->opcode==OP_Variable + && pOp->p1+pOp->p3==pExpr->iTable + && pOp->p2+pOp->p3==target + && pOp->p4.z==0 + ){ + /* If the previous instruction was a copy of the previous unnamed + ** parameter into the previous register, then simply increment the + ** repeat count on the prior instruction rather than making a new + ** instruction. + */ + pOp->p3++; + }else{ + sqlite3VdbeAddOp3(v, OP_Variable, pExpr->iTable, target, 1); + if( pExpr->token.n>1 ){ + sqlite3VdbeChangeP4(v, -1, (char*)pExpr->token.z, pExpr->token.n); + } } break; } |