diff options
author | drh <drh@noemail.net> | 2020-11-17 21:26:13 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2020-11-17 21:26:13 +0000 |
commit | 32881bebbeb4a0c92d09a0ddcd5714497ecc4fd3 (patch) | |
tree | 42c8962e326575b2f0b2ac6f3c5e2923cc70f907 /src | |
parent | ea2487200f1587fbf5bd14a32e1bd240beb7f899 (diff) | |
download | sqlite-32881bebbeb4a0c92d09a0ddcd5714497ecc4fd3.tar.gz sqlite-32881bebbeb4a0c92d09a0ddcd5714497ecc4fd3.zip |
Claw back most of the performance lost in the previous commit.
FossilOrigin-Name: df8ce2675b070fcdc338918e7652a26ffc90439fe399ceac206fadf8a93a681f
Diffstat (limited to 'src')
-rw-r--r-- | src/update.c | 9 | ||||
-rw-r--r-- | src/vdbe.c | 17 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/update.c b/src/update.c index 04648149c..f8cb2afed 100644 --- a/src/update.c +++ b/src/update.c @@ -652,8 +652,7 @@ void sqlite3Update( if( nChangeFrom==0 && HasRowid(pTab) ){ sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); iEph = pParse->nTab++; - addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, 0); - sqlite3VdbeLoadString(v, regRowSet, ""); + addrOpen = sqlite3VdbeAddOp3(v, OP_OpenEphemeral, iEph, 0, regRowSet); }else{ assert( pPk!=0 || HasRowid(pTab) ); nPk = pPk ? pPk->nKeyCol : 0; @@ -748,7 +747,7 @@ void sqlite3Update( aRegIdx[nAllIdx] = ++pParse->nMem; sqlite3VdbeAddOp3(v, OP_Insert, iEph, regRowSet, regOldRowid); }else{ - if( addrOpen ) sqlite3VdbeChangeToNoop(v, addrOpen); + if( ALWAYS(addrOpen) ) sqlite3VdbeChangeToNoop(v, addrOpen); } }else{ /* Read the PK of the current row into an array of registers. In @@ -1088,11 +1087,9 @@ void sqlite3Update( }else if( eOnePass==ONEPASS_MULTI ){ sqlite3VdbeResolveLabel(v, labelContinue); sqlite3WhereEnd(pWInfo); - }else /*if( pPk || nChangeFrom )*/{ + }else{ sqlite3VdbeResolveLabel(v, labelContinue); sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v); -// }else{ -// sqlite3VdbeGoto(v, labelContinue); } sqlite3VdbeResolveLabel(v, labelBreak); diff --git a/src/vdbe.c b/src/vdbe.c index 5823ebd92..b9b6b398a 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3901,7 +3901,7 @@ case OP_OpenDup: { } -/* Opcode: OpenEphemeral P1 P2 * P4 P5 +/* Opcode: OpenEphemeral P1 P2 P3 P4 P5 ** Synopsis: nColumn=P2 ** ** Open a new cursor P1 to a transient table. @@ -3921,6 +3921,10 @@ case OP_OpenDup: { ** in btree.h. These flags control aspects of the operation of ** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are ** added automatically. +** +** If P3 is positive, then reg[P3] is modified slightly so that it +** can be used as zero-length data for OP_Insert. This is an optimization +** that avoids an extra OP_Blob opcode to initialize that register. */ /* Opcode: OpenAutoindex P1 P2 * P4 * ** Synopsis: nColumn=P2 @@ -3943,6 +3947,15 @@ case OP_OpenEphemeral: { SQLITE_OPEN_TRANSIENT_DB; assert( pOp->p1>=0 ); assert( pOp->p2>=0 ); + if( pOp->p3>0 ){ + /* Make register reg[P3] into a value that can be used as the data + ** form sqlite3BtreeInsert() where the length of the data is zero. */ + assert( pOp->p2==0 ); /* Only used when number of columns is zero */ + assert( pOp->opcode==OP_OpenEphemeral ); + assert( aMem[pOp->p3].flags & MEM_Null ); + aMem[pOp->p3].n = 0; + aMem[pOp->p3].z = ""; + } pCx = p->apCsr[pOp->p1]; if( pCx && pCx->pBtx ){ /* If the ephermeral table is already open, erase all existing content @@ -5102,7 +5115,7 @@ case OP_Insert: { if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey; - assert( pData->flags & (MEM_Blob|MEM_Str) ); + assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 ); x.pData = pData->z; x.nData = pData->n; seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); |