1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-03 16:53:36 +03:00

Defer the {quote: MoveTo}

opcode in VDBE until the data is actually needed.  Sometimes
the data is never needed, resulting in a performance increase.  On an indexed
order search with a large OFFSET, queries times can be an order of magnitude
faster. (CVS 1165)

FossilOrigin-Name: d3e96da20d269a068188915b3cc0eb02d330d316
This commit is contained in:
drh
2004-01-07 18:52:56 +00:00
parent 912184b0cf
commit a11846b77a
5 changed files with 98 additions and 49 deletions

View File

@@ -992,3 +992,51 @@ void sqliteVdbeDelete(Vdbe *p){
p->magic = VDBE_MAGIC_DEAD;
sqliteFree(p);
}
/*
** Convert an integer in between the native integer format and
** the bigEndian format used as the record number for tables.
**
** The bigEndian format (most significant byte first) is used for
** record numbers so that records will sort into the correct order
** even though memcmp() is used to compare the keys. On machines
** whose native integer format is little endian (ex: i486) the
** order of bytes is reversed. On native big-endian machines
** (ex: Alpha, Sparc, Motorola) the byte order is the same.
**
** This function is its own inverse. In other words
**
** X == byteSwap(byteSwap(X))
*/
int sqliteVdbeByteSwap(int x){
union {
char zBuf[sizeof(int)];
int i;
} ux;
ux.zBuf[3] = x&0xff;
ux.zBuf[2] = (x>>8)&0xff;
ux.zBuf[1] = (x>>16)&0xff;
ux.zBuf[0] = (x>>24)&0xff;
return ux.i;
}
/*
** If a MoveTo operation is pending on the given cursor, then do that
** MoveTo now. Return an error code. If no MoveTo is pending, this
** routine does nothing and returns SQLITE_OK.
*/
int sqliteVdbeCursorMoveto(Cursor *p){
if( p->deferredMoveto ){
int res;
extern int sqlite_search_count;
sqliteBtreeMoveto(p->pCursor, (char*)&p->movetoTarget, sizeof(int), &res);
p->lastRecno = keyToInt(p->movetoTarget);
p->recnoIsValid = res==0;
if( res<0 ){
sqliteBtreeNext(p->pCursor, &res);
}
sqlite_search_count++;
p->deferredMoveto = 0;
}
return SQLITE_OK;
}