mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Performance optimization to the OP_Next and OP_Prev opcodes.
FossilOrigin-Name: ecaac28a2e78aca148fc614fe54bf2706aed8be2
This commit is contained in:
17
manifest
17
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Refactor\sthe\sOP_Column\sopcode\sto\smake\sit\sclearer\sand\seasier\sto\smaintain.\nOverall,\sperformance\stests\sshow\sabout\sa\s1%\sspeed\sincrease\swith\sthis\schange.
|
C Performance\soptimization\sto\sthe\sOP_Next\sand\sOP_Prev\sopcodes.
|
||||||
D 2013-11-21T01:33:45.684
|
D 2013-11-21T03:12:25.082
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 8a07bebafbfda0eb67728f4bd15a36201662d1a1
|
F Makefile.in 8a07bebafbfda0eb67728f4bd15a36201662d1a1
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -280,11 +280,11 @@ F src/update.c c05a0ee658f1a149e0960dfd110f3b8bd846bcb0
|
|||||||
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
|
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
|
||||||
F src/util.c 2fa6c821d28bbdbeec1b2a7b091a281c9ef8f918
|
F src/util.c 2fa6c821d28bbdbeec1b2a7b091a281c9ef8f918
|
||||||
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
|
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
|
||||||
F src/vdbe.c c375ba0385f747e58d98686f5f4f0439c6297b35
|
F src/vdbe.c 1aabde68130182a3cceb70d1c59122b93244b97e
|
||||||
F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644
|
F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644
|
||||||
F src/vdbeInt.h 0ac03c790b8ea4568b747550ba9bbf92a8e8feb2
|
F src/vdbeInt.h 0ac03c790b8ea4568b747550ba9bbf92a8e8feb2
|
||||||
F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
|
F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
|
||||||
F src/vdbeaux.c bbf06ccbb159611d55e32783c6e9fdec75b120d0
|
F src/vdbeaux.c 648f72365268979e89cd2ba8e5f2b4ecb1843fb0
|
||||||
F src/vdbeblob.c 8cd05a5630e6d5563ad017bf82edaf812b28acde
|
F src/vdbeblob.c 8cd05a5630e6d5563ad017bf82edaf812b28acde
|
||||||
F src/vdbemem.c cc529bbf4f13e4e181bdb446bf6e6962ab030b4b
|
F src/vdbemem.c cc529bbf4f13e4e181bdb446bf6e6962ab030b4b
|
||||||
F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
|
F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
|
||||||
@@ -293,7 +293,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
|
|||||||
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
|
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
|
||||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||||
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
|
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
|
||||||
F src/where.c aa72ba871fa835a513cae1c7432dc1d785eb23e4
|
F src/where.c e558bfa67009ab7de08a7a1960ae0dd443241cdd
|
||||||
F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358
|
F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358
|
||||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||||
@@ -1140,8 +1140,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
||||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||||
P 5562cd343d8f69242e06a51a7f1aef7ee7d78eec 933939932c44bccb0958f203a5bd24e683c1cf38
|
P 972881c6d394c199961f01dcbeb4a6e8b5c919a1
|
||||||
R 842b8e02c5c12ba51889f25ba6cef74b
|
R d4a5420dc1635b387e6b0a099e73a8c3
|
||||||
T +closed 933939932c44bccb0958f203a5bd24e683c1cf38
|
|
||||||
U drh
|
U drh
|
||||||
Z 16455d71573d7ca0de3f10177a1e6082
|
Z 0f90f7ea40ab09ca14f9f529358ed102
|
||||||
|
@@ -1 +1 @@
|
|||||||
972881c6d394c199961f01dcbeb4a6e8b5c919a1
|
ecaac28a2e78aca148fc614fe54bf2706aed8be2
|
60
src/vdbe.c
60
src/vdbe.c
@@ -4467,7 +4467,8 @@ case OP_Rewind: { /* jump */
|
|||||||
** to the following instruction. But if the cursor advance was successful,
|
** to the following instruction. But if the cursor advance was successful,
|
||||||
** jump immediately to P2.
|
** jump immediately to P2.
|
||||||
**
|
**
|
||||||
** The P1 cursor must be for a real table, not a pseudo-table.
|
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
|
||||||
|
** been opened prior to this opcode or the program will segfault.
|
||||||
**
|
**
|
||||||
** P4 is always of type P4_ADVANCE. The function pointer points to
|
** P4 is always of type P4_ADVANCE. The function pointer points to
|
||||||
** sqlite3BtreeNext().
|
** sqlite3BtreeNext().
|
||||||
@@ -4475,7 +4476,12 @@ case OP_Rewind: { /* jump */
|
|||||||
** If P5 is positive and the jump is taken, then event counter
|
** If P5 is positive and the jump is taken, then event counter
|
||||||
** number P5-1 in the prepared statement is incremented.
|
** number P5-1 in the prepared statement is incremented.
|
||||||
**
|
**
|
||||||
** See also: Prev
|
** See also: Prev, NextIfOpen
|
||||||
|
*/
|
||||||
|
/* Opcode: NextIfOpen P1 P2 * * P5
|
||||||
|
**
|
||||||
|
** This opcode works just like OP_Next except that if cursor P1 is not
|
||||||
|
** open it behaves a no-op.
|
||||||
*/
|
*/
|
||||||
/* Opcode: Prev P1 P2 * * P5
|
/* Opcode: Prev P1 P2 * * P5
|
||||||
**
|
**
|
||||||
@@ -4484,7 +4490,8 @@ case OP_Rewind: { /* jump */
|
|||||||
** to the following instruction. But if the cursor backup was successful,
|
** to the following instruction. But if the cursor backup was successful,
|
||||||
** jump immediately to P2.
|
** jump immediately to P2.
|
||||||
**
|
**
|
||||||
** The P1 cursor must be for a real table, not a pseudo-table.
|
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
|
||||||
|
** not open then the behavior is undefined.
|
||||||
**
|
**
|
||||||
** P4 is always of type P4_ADVANCE. The function pointer points to
|
** P4 is always of type P4_ADVANCE. The function pointer points to
|
||||||
** sqlite3BtreePrevious().
|
** sqlite3BtreePrevious().
|
||||||
@@ -4492,38 +4499,47 @@ case OP_Rewind: { /* jump */
|
|||||||
** If P5 is positive and the jump is taken, then event counter
|
** If P5 is positive and the jump is taken, then event counter
|
||||||
** number P5-1 in the prepared statement is incremented.
|
** number P5-1 in the prepared statement is incremented.
|
||||||
*/
|
*/
|
||||||
case OP_SorterNext: /* jump */
|
/* Opcode: PrevIfOpen P1 P2 * * P5
|
||||||
case OP_Prev: /* jump */
|
**
|
||||||
case OP_Next: { /* jump */
|
** This opcode works just like OP_Prev except that if cursor P1 is not
|
||||||
|
** open it behaves a no-op.
|
||||||
|
*/
|
||||||
|
case OP_SorterNext: { /* jump */
|
||||||
VdbeCursor *pC;
|
VdbeCursor *pC;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
pC = p->apCsr[pOp->p1];
|
||||||
|
assert( isSorter(pC) );
|
||||||
|
rc = sqlite3VdbeSorterNext(db, pC, &res);
|
||||||
|
goto next_tail;
|
||||||
|
case OP_PrevIfOpen: /* jump */
|
||||||
|
case OP_NextIfOpen: /* jump */
|
||||||
|
if( p->apCsr[pOp->p1]==0 ) break;
|
||||||
|
/* Fall through */
|
||||||
|
case OP_Prev: /* jump */
|
||||||
|
case OP_Next: /* jump */
|
||||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||||
assert( pOp->p5<ArraySize(p->aCounter) );
|
assert( pOp->p5<ArraySize(p->aCounter) );
|
||||||
pC = p->apCsr[pOp->p1];
|
pC = p->apCsr[pOp->p1];
|
||||||
if( pC==0 ){
|
assert( pC!=0 );
|
||||||
break; /* See ticket #2273 */
|
assert( pC->deferredMoveto==0 );
|
||||||
}
|
assert( pC->pCursor );
|
||||||
assert( isSorter(pC)==(pOp->opcode==OP_SorterNext) );
|
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
|
||||||
if( isSorter(pC) ){
|
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
|
||||||
assert( pOp->opcode==OP_SorterNext );
|
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
|
||||||
rc = sqlite3VdbeSorterNext(db, pC, &res);
|
assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
|
||||||
}else{
|
rc = pOp->p4.xAdvance(pC->pCursor, &res);
|
||||||
/* res = 1; // Always initialized by the xAdvance() call */
|
next_tail:
|
||||||
assert( pC->deferredMoveto==0 );
|
|
||||||
assert( pC->pCursor );
|
|
||||||
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
|
|
||||||
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
|
|
||||||
rc = pOp->p4.xAdvance(pC->pCursor, &res);
|
|
||||||
}
|
|
||||||
pC->nullRow = (u8)res;
|
|
||||||
pC->cacheStatus = CACHE_STALE;
|
pC->cacheStatus = CACHE_STALE;
|
||||||
if( res==0 ){
|
if( res==0 ){
|
||||||
|
pC->nullRow = 0;
|
||||||
pc = pOp->p2 - 1;
|
pc = pOp->p2 - 1;
|
||||||
p->aCounter[pOp->p5]++;
|
p->aCounter[pOp->p5]++;
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
sqlite3_search_count++;
|
sqlite3_search_count++;
|
||||||
#endif
|
#endif
|
||||||
|
}else{
|
||||||
|
pC->nullRow = 1;
|
||||||
}
|
}
|
||||||
pC->rowidIsValid = 0;
|
pC->rowidIsValid = 0;
|
||||||
goto check_for_interrupt;
|
goto check_for_interrupt;
|
||||||
|
@@ -453,12 +453,14 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
case OP_Next:
|
case OP_Next:
|
||||||
|
case OP_NextIfOpen:
|
||||||
case OP_SorterNext: {
|
case OP_SorterNext: {
|
||||||
pOp->p4.xAdvance = sqlite3BtreeNext;
|
pOp->p4.xAdvance = sqlite3BtreeNext;
|
||||||
pOp->p4type = P4_ADVANCE;
|
pOp->p4type = P4_ADVANCE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OP_Prev: {
|
case OP_Prev:
|
||||||
|
case OP_PrevIfOpen: {
|
||||||
pOp->p4.xAdvance = sqlite3BtreePrevious;
|
pOp->p4.xAdvance = sqlite3BtreePrevious;
|
||||||
pOp->p4type = P4_ADVANCE;
|
pOp->p4type = P4_ADVANCE;
|
||||||
break;
|
break;
|
||||||
|
@@ -2406,7 +2406,7 @@ static int codeEqualityTerm(
|
|||||||
}else{
|
}else{
|
||||||
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
|
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
|
||||||
}
|
}
|
||||||
pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
|
pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
|
||||||
sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
|
sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
|
||||||
}else{
|
}else{
|
||||||
pLevel->u.in.nIn = 0;
|
pLevel->u.in.nIn = 0;
|
||||||
|
Reference in New Issue
Block a user