Small size reduction and performance improvement in the

sqlite3VdbeMemFromBtree() interface used to pull content out of the b-tree
and into an sqlite3_value object.

FossilOrigin-Name: ae6dd8d3e921670ee6450453b54245dd71bcfff3fd1bc7fdb7cf4cf9585c3375
This commit is contained in:
drh 2020-02-05 18:28:17 +00:00
parent 3cdc820544
commit 2a74006087
6 changed files with 22 additions and 24 deletions

View File

@ -1,5 +1,5 @@
C Enable\smore\sdetailed\slog\smessages\sin\sSQLITE_ENABLE_CORRUPT_PGNO\sbuilds\sif\sdatabase\scorruption\sis\sencountered. C Small\ssize\sreduction\sand\sperformance\simprovement\sin\sthe\nsqlite3VdbeMemFromBtree()\sinterface\sused\sto\spull\scontent\sout\sof\sthe\sb-tree\nand\sinto\san\ssqlite3_value\sobject.
D 2020-02-04T20:01:44.357 D 2020-02-05T18:28:17.819
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -603,13 +603,13 @@ F src/upsert.c 2920de71b20f04fe25eb00b655d086f0ba60ea133c59d7fa3325c49838818e78
F src/utf.c 736ff76753236ffbc8b5b939f5e0607f28aeaa7c780b3a56b419228f0a81c87b F src/utf.c 736ff76753236ffbc8b5b939f5e0607f28aeaa7c780b3a56b419228f0a81c87b
F src/util.c d035b09df9cecbc0e8f07c34b815acbf0d43c8adc8d2c540e3dc92eecb27855a F src/util.c d035b09df9cecbc0e8f07c34b815acbf0d43c8adc8d2c540e3dc92eecb27855a
F src/vacuum.c 82dcec9e7b1afa980288718ad11bc499651c722d7b9f32933c4d694d91cb6ebf F src/vacuum.c 82dcec9e7b1afa980288718ad11bc499651c722d7b9f32933c4d694d91cb6ebf
F src/vdbe.c b34d430a44ebb9f4ccdaf590de641b8ef126480a64f1544b11146a5d8b672879 F src/vdbe.c 0fdca82c67c68499d1dc3e310e39b7ee30cd262a535f848f3d0a3fee00b70662
F src/vdbe.h defd693289c7bb8d325f109be9490c77138061211a116827da7244b6015a4934 F src/vdbe.h defd693289c7bb8d325f109be9490c77138061211a116827da7244b6015a4934
F src/vdbeInt.h 30d3e8b991547cdf39025e416a0a737b0416d46747af70ae058f60e2e0466fe7 F src/vdbeInt.h a17146053a1aa438474012998fe07e314f3df274a61491ad838ad85d848ac051
F src/vdbeapi.c 1252d80c548711e47a6d84dae88ed4e95d3fbb4e7bd0eaa1347299af7efddf02 F src/vdbeapi.c 1252d80c548711e47a6d84dae88ed4e95d3fbb4e7bd0eaa1347299af7efddf02
F src/vdbeaux.c 873d96bc4c046a016b3a35c736a45f26a31b59b1480a0cdd79e40f02c9bd001c F src/vdbeaux.c eaf1df6465f410e69330864bfc152458208f9bb2edd99930432ae342662d2ecd
F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b1 F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b1
F src/vdbemem.c 6200af702c87105d5b00d8ac5f5fa2c6d8f796aa974dbe2d15dcd95379ba1fa7 F src/vdbemem.c ff2a1fd86ea943efb7174bd74bc661815c449be6165e136e8849e1dc59e24353
F src/vdbesort.c 2be76d26998ce2b3324cdcc9f6443728e54b6c7677c553ad909c7d7cfab587df F src/vdbesort.c 2be76d26998ce2b3324cdcc9f6443728e54b6c7677c553ad909c7d7cfab587df
F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0 F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0
F src/vtab.c 7b704a90515a239c6cdba6a66b1bb3a385e62326cceb5ecb05ec7a091d6b8515 F src/vtab.c 7b704a90515a239c6cdba6a66b1bb3a385e62326cceb5ecb05ec7a091d6b8515
@ -1858,7 +1858,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 29a969d6b1709b80d9cb88b60971e4eb021f7f5f8ee9a619be74b833a78a35ef P 57c36a293e16bb4d9652874124ee1447bef278e08664bc8dd0070a0ee2ef1173
R 020ae1619dff77b0c976eacd97de532f R 9dccc312e85b3ed88562ba275ed8ce3c
U dan U drh
Z c5d72d1ce7fa174b00e7f8ecef1901cb Z 6739930e1718a08cc04c781aee16b618

View File

@ -1 +1 @@
57c36a293e16bb4d9652874124ee1447bef278e08664bc8dd0070a0ee2ef1173 ae6dd8d3e921670ee6450453b54245dd71bcfff3fd1bc7fdb7cf4cf9585c3375

View File

@ -2713,7 +2713,7 @@ case OP_Column: {
/* Make sure zData points to enough of the record to cover the header. */ /* Make sure zData points to enough of the record to cover the header. */
if( pC->aRow==0 ){ if( pC->aRow==0 ){
memset(&sMem, 0, sizeof(sMem)); memset(&sMem, 0, sizeof(sMem));
rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, 0, aOffset[0], &sMem); rc = sqlite3VdbeMemFromBtreeZeroOffset(pC->uc.pCursor,aOffset[0],&sMem);
if( rc!=SQLITE_OK ) goto abort_due_to_error; if( rc!=SQLITE_OK ) goto abort_due_to_error;
zData = (u8*)sMem.z; zData = (u8*)sMem.z;
}else{ }else{
@ -5209,7 +5209,7 @@ case OP_RowData: {
goto too_big; goto too_big;
} }
testcase( n==0 ); testcase( n==0 );
rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut); rc = sqlite3VdbeMemFromBtreeZeroOffset(pCrsr, n, pOut);
if( rc ) goto abort_due_to_error; if( rc ) goto abort_due_to_error;
if( !pOp->p3 ) Deephemeralize(pOut); if( !pOp->p3 ) Deephemeralize(pOut);
UPDATE_MAX_BLOBSIZE(pOut); UPDATE_MAX_BLOBSIZE(pOut);

View File

@ -532,6 +532,7 @@ int sqlite3VdbeMemRealify(Mem*);
int sqlite3VdbeMemNumerify(Mem*); int sqlite3VdbeMemNumerify(Mem*);
int sqlite3VdbeMemCast(Mem*,u8,u8); int sqlite3VdbeMemCast(Mem*,u8,u8);
int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
void sqlite3VdbeMemRelease(Mem *p); void sqlite3VdbeMemRelease(Mem *p);
int sqlite3VdbeMemFinalize(Mem*, FuncDef*); int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
#ifndef SQLITE_OMIT_WINDOWFUNC #ifndef SQLITE_OMIT_WINDOWFUNC

View File

@ -4862,7 +4862,7 @@ int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
/* Read in the complete content of the index entry */ /* Read in the complete content of the index entry */
sqlite3VdbeMemInit(&m, db, 0); sqlite3VdbeMemInit(&m, db, 0);
rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m);
if( rc ){ if( rc ){
return rc; return rc;
} }
@ -4944,7 +4944,7 @@ int sqlite3VdbeIdxKeyCompare(
return SQLITE_CORRUPT_BKPT; return SQLITE_CORRUPT_BKPT;
} }
sqlite3VdbeMemInit(&m, db, 0); sqlite3VdbeMemInit(&m, db, 0);
rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m);
if( rc ){ if( rc ){
return rc; return rc;
} }

View File

@ -1169,7 +1169,7 @@ int sqlite3VdbeMemSetStr(
** If this routine fails for any reason (malloc returns NULL or unable ** If this routine fails for any reason (malloc returns NULL or unable
** to read from the disk) then the pMem is left in an inconsistent state. ** to read from the disk) then the pMem is left in an inconsistent state.
*/ */
static SQLITE_NOINLINE int vdbeMemFromBtreeResize( int sqlite3VdbeMemFromBtree(
BtCursor *pCur, /* Cursor pointing at record to retrieve. */ BtCursor *pCur, /* Cursor pointing at record to retrieve. */
u32 offset, /* Offset from the start of data to return bytes from. */ u32 offset, /* Offset from the start of data to return bytes from. */
u32 amt, /* Number of bytes to return. */ u32 amt, /* Number of bytes to return. */
@ -1192,13 +1192,11 @@ static SQLITE_NOINLINE int vdbeMemFromBtreeResize(
} }
return rc; return rc;
} }
int sqlite3VdbeMemFromBtree( int sqlite3VdbeMemFromBtreeZeroOffset(
BtCursor *pCur, /* Cursor pointing at record to retrieve. */ BtCursor *pCur, /* Cursor pointing at record to retrieve. */
u32 offset, /* Offset from the start of data to return bytes from. */
u32 amt, /* Number of bytes to return. */ u32 amt, /* Number of bytes to return. */
Mem *pMem /* OUT: Return data in this Mem structure. */ Mem *pMem /* OUT: Return data in this Mem structure. */
){ ){
char *zData; /* Data from the btree layer */
u32 available = 0; /* Number of bytes available on the local btree page */ u32 available = 0; /* Number of bytes available on the local btree page */
int rc = SQLITE_OK; /* Return code */ int rc = SQLITE_OK; /* Return code */
@ -1208,15 +1206,14 @@ int sqlite3VdbeMemFromBtree(
/* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
** that both the BtShared and database handle mutexes are held. */ ** that both the BtShared and database handle mutexes are held. */
assert( !sqlite3VdbeMemIsRowSet(pMem) ); assert( !sqlite3VdbeMemIsRowSet(pMem) );
zData = (char *)sqlite3BtreePayloadFetch(pCur, &available); pMem->z = (char *)sqlite3BtreePayloadFetch(pCur, &available);
assert( zData!=0 ); assert( pMem->z!=0 );
if( offset+amt<=available ){ if( amt<=available ){
pMem->z = &zData[offset];
pMem->flags = MEM_Blob|MEM_Ephem; pMem->flags = MEM_Blob|MEM_Ephem;
pMem->n = (int)amt; pMem->n = (int)amt;
}else{ }else{
rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem); rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem);
} }
return rc; return rc;