1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Modify the OP_RowData opcode so that when P3!=0 it is allowed to hold an

ephemeral copy of the content.  This avoids unnecessary memcpy() operations
in the xfer-optimization and VACUUM.

FossilOrigin-Name: 6e106acd74da3baa5c308a76443d2f0a7c904e5e
This commit is contained in:
drh
2017-01-09 15:44:25 +00:00
parent f4e994b23a
commit e7b554d615
4 changed files with 27 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
C Add\sthe\sSQLITE_UINT64_TYPE\scompile-time\soption.
D 2017-01-09T13:43:09.245
C Modify\sthe\sOP_RowData\sopcode\sso\sthat\swhen\sP3!=0\sit\sis\sallowed\sto\shold\san\nephemeral\scopy\sof\sthe\scontent.\s\sThis\savoids\sunnecessary\smemcpy()\soperations\nin\sthe\sxfer-optimization\sand\sVACUUM.
D 2017-01-09T15:44:25.721
F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -350,7 +350,7 @@ F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd
F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4
F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c ad2a0b2757a23b6f9297ee414eeab22b52fbde75
F src/insert.c 7761fd63136771d411f096f4d7a1af9c5057ddd4
F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e
F src/loadext.c 5d6642d141c07d366e43d359e94ec9de47add41d
F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0
@@ -455,7 +455,7 @@ F src/update.c 1da7c462110bffed442a42884cb0d528c1db46d8
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
F src/util.c a88b0466fddf445ce752226d4698ca3faada620a
F src/vacuum.c 33c174b28886b2faf26e503b5a49a1c01a9b1c16
F src/vdbe.c 88bd6c32b333580d2661ac3afe33369757fb1522
F src/vdbe.c b7f39cec8b572df61cdbd26426e285f8fd759db3
F src/vdbe.h b0866e4191f096f1c987a84b042c3599bdf5423b
F src/vdbeInt.h 281cb70332dc8b593b8c7afe776f3a2ba7d4255e
F src/vdbeapi.c d6ebaa465f070eb1af8ba4e7b34583ece87bdd24
@@ -1543,7 +1543,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 3178ec4c27efc4ff84bcd17ddb17ec50a6ac96b3
R ff5d1e49d008400e89044e5b599d5e72
P a5fe03bc419d9c7e6068ed38810e3f183de179b5
R 1f3e0de052f41632eb2fb92e1db69d89
U drh
Z 9ff193ccbc51dd8562e9e65994630a91
Z 8ba5841c95779521fe8c2f52b8a5492f

View File

@@ -1 +1 @@
a5fe03bc419d9c7e6068ed38810e3f183de179b5
6e106acd74da3baa5c308a76443d2f0a7c904e5e

View File

@@ -2138,7 +2138,7 @@ static int xferOptimization(
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
assert( (pDest->tabFlags & TF_Autoincrement)==0 );
}
sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
if( db->flags & SQLITE_Vacuum ){
sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
@@ -2170,7 +2170,7 @@ static int xferOptimization(
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
VdbeComment((v, "%s", pDestIdx->zName));
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
if( db->flags & SQLITE_Vacuum ){
/* This INSERT command is part of a VACUUM operation, which guarantees
** that the destination table is empty. If all indexed columns use

View File

@@ -4632,7 +4632,7 @@ case OP_SorterData: {
break;
}
/* Opcode: RowData P1 P2 * * *
/* Opcode: RowData P1 P2 P3 * *
** Synopsis: r[P2]=data
**
** Write into register P2 the complete row content for the row at
@@ -4646,14 +4646,26 @@ case OP_SorterData: {
**
** If the P1 cursor must be pointing to a valid row (not a NULL row)
** of a real table, not a pseudo-table.
**
** If P3!=0 then this opcode is allowed to make an ephermeral pointer
** into the database page. That means that the content of the output
** register will be invalidated as soon as the cursor moves - including
** moves caused by other cursors that "save" the the current cursors
** position in order that they can write to the same table. If P3==0
** then a copy of the data is made into memory. P3!=0 is faster, but
** P3==0 is safer.
**
** If P3!=0 then the content of the P2 register is unsuitable for use
** in OP_Result and any OP_Result will invalidate the P2 register content.
** The P2 register content is invalided by opcodes like OP_Function or
** by any use of another cursor pointing to the same table.
*/
case OP_RowData: {
VdbeCursor *pC;
BtCursor *pCrsr;
u32 n;
pOut = &aMem[pOp->p2];
memAboutToChange(p, pOut);
pOut = out2Prerelease(p, pOp);
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
pC = p->apCsr[pOp->p1];
@@ -4684,14 +4696,9 @@ case OP_RowData: {
goto too_big;
}
testcase( n==0 );
if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
goto no_mem;
}
pOut->n = n;
MemSetTypeFlag(pOut, MEM_Blob);
rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z);
rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut);
if( rc ) goto abort_due_to_error;
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
if( !pOp->p3 ) Deephemeralize(pOut);
UPDATE_MAX_BLOBSIZE(pOut);
REGISTER_TRACE(pOp->p2, pOut);
break;