mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-08 03:22:21 +03:00
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
This commit is contained in:
25
src/expr.c
25
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user