aboutsummaryrefslogtreecommitdiff
path: root/src/vdbeblob.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-01-20 00:40:26 +0000
committerdrh <drh@noemail.net>2017-01-20 00:40:26 +0000
commit4df65fc20f617dbd01028e5987c1b1dcb0ca70aa (patch)
tree950e7db8742e698c3ebf09e7ac261e04b580f5ea /src/vdbeblob.c
parent8674e49214c8d9a0e23cf46c15d6bd4b74b00c4d (diff)
downloadsqlite-4df65fc20f617dbd01028e5987c1b1dcb0ca70aa.tar.gz
sqlite-4df65fc20f617dbd01028e5987c1b1dcb0ca70aa.zip
Minor performance optimizations to sqlite3_blob_open() and
sqlite3_blob_reopen(). FossilOrigin-Name: 52a61967d920047ea0b4409b79793e05c0128964
Diffstat (limited to 'src/vdbeblob.c')
-rw-r--r--src/vdbeblob.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/vdbeblob.c b/src/vdbeblob.c
index 520d16c98..b2902ba32 100644
--- a/src/vdbeblob.c
+++ b/src/vdbeblob.c
@@ -57,12 +57,17 @@ static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){
char *zErr = 0; /* Error message */
Vdbe *v = (Vdbe *)p->pStmt;
- /* Set the value of the SQL statements only variable to integer iRow.
- ** This is done directly instead of using sqlite3_bind_int64() to avoid
- ** triggering asserts related to mutexes.
+ /* Set the value of register r[1] in the SQL statement to integer iRow.
+ ** This is done directly as a performance optimization
*/
- assert( v->aVar[0].flags&MEM_Int );
- v->aVar[0].u.i = iRow;
+ v->aMem[1].flags = MEM_Int;
+ v->aMem[1].u.i = iRow;
+
+ /* If the statement has been run before (and is paused at the OP_ResultRow)
+ ** then back it up to the point where it does the OP_SeekRowid. This could
+ ** have been down with an extra OP_Goto, but simply setting the program
+ ** counter is faster. */
+ if( v->pc>3 ) v->pc = 3;
rc = sqlite3_step(p->pStmt);
if( rc==SQLITE_ROW ){
@@ -257,12 +262,11 @@ int sqlite3_blob_open(
static const VdbeOpList openBlob[] = {
{OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
{OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
- {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */
- {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */
- {OP_Column, 0, 0, 1}, /* 4 */
- {OP_ResultRow, 1, 0, 0}, /* 5 */
- {OP_Goto, 0, 2, 0}, /* 6 */
- {OP_Halt, 0, 0, 0}, /* 7 */
+ /* blobSeekToRow() will initialize r[1] to the desired rowid */
+ {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
+ {OP_Column, 0, 0, 1}, /* 3 */
+ {OP_ResultRow, 1, 0, 0}, /* 4 */
+ {OP_Halt, 0, 0, 0}, /* 5 */
};
Vdbe *v = (Vdbe *)pBlob->pStmt;
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -306,9 +310,9 @@ int sqlite3_blob_open(
*/
aOp[1].p4type = P4_INT32;
aOp[1].p4.i = pTab->nCol+1;
- aOp[4].p2 = pTab->nCol;
+ aOp[3].p2 = pTab->nCol;
- pParse->nVar = 1;
+ pParse->nVar = 0;
pParse->nMem = 1;
pParse->nTab = 1;
sqlite3VdbeMakeReady(v, pParse);