From: drh Date: Sat, 12 Jun 2004 18:12:15 +0000 (+0000) Subject: Improve the speed of OP_Column through better caching. (CVS 1577) X-Git-Tag: version-3.0.0~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e61cffc20326c4fd4369b8bed68134b42b0591ed;p=thirdparty%2Fsqlite.git Improve the speed of OP_Column through better caching. (CVS 1577) FossilOrigin-Name: f687977a28eda5ce0aa1cba2fdfb0152443032bc --- diff --git a/manifest b/manifest index 3f7e2ae8a6..42030e5a20 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\sthe\slocking\sdocument.\s(CVS\s1576) -D 2004-06-12T14:11:38 +C Improve\sthe\sspeed\sof\sOP_Column\sthrough\sbetter\scaching.\s(CVS\s1577) +D 2004-06-12T18:12:16 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -41,7 +41,7 @@ F src/legacy.c ad23746f15f67e34577621b1875f639c94839e1f F src/main.c 9061fff2b04759d849155a334bf2a9f158d325d7 F src/md5.c d77a389955759c8329bb357e3d71bac3d6eb710b F src/os.h 23c69c5084e71b5fe199ff1c4e35a4aded0f1380 -F src/os_common.h 6393ac67a3a7b4aea19ff17529980ecf77eb2348 +F src/os_common.h ba1b7306e16e2091718f2c48db0fe6c1d7a31bb8 F src/os_mac.c b823874690615ace0dd520d3ad1fe8bfd864b7e0 F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4 F src/os_unix.c 7ece785e36c4ecb57c73db8d374b56912d742c4a @@ -71,9 +71,9 @@ F src/update.c 168b6d523087ca4545b74ec9f3102b1f3c6b1e38 F src/utf.c e16737b3fc4201bf7ce9bd8ced5250596aa31b76 F src/util.c 90375fa253137562d536ccdd40b297f0fd7413fc F src/vacuum.c b921eb778842592e1fb48a9d4cef7e861103878f -F src/vdbe.c 026b78bc404a2585aaefbf876295ed3ae892d769 +F src/vdbe.c 9f941bbdf0bcbc18fbdfceecbc2322e82084e094 F src/vdbe.h 46f74444a213129bc4b5ce40124dd8ed613b0cde -F src/vdbeInt.h c4ff480cd8f859c9862d759aebd0fe5ebaef47a1 +F src/vdbeInt.h 1cc767a63eefd1d1114e190336588c6d4f70a6a0 F src/vdbeapi.c ee350b552fc4c1c695b760f914f69e9c5556e829 F src/vdbeaux.c 1d0dbaf73c89bd1cc27abad19ee0aa26ab5d03f4 F src/vdbemem.c 34f59988831ea032b7f526c2c73175f9f4c0f3ad @@ -223,7 +223,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 5903f53828b5d282b33e27813417e4317c9ecf0b -R a46c51da808bad8e24d7946d300b2226 +P 99a7bd83ac38e14bb936a834634313cf98279a62 +R 1e1692dcb3026c03937468eb4d723051 U drh -Z e597c81eeb6dd60916f877dd834b0e9c +Z 511db11f04adc59072cae9559d18a6b6 diff --git a/manifest.uuid b/manifest.uuid index 8b0b602465..3a7b8c7357 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -99a7bd83ac38e14bb936a834634313cf98279a62 \ No newline at end of file +f687977a28eda5ce0aa1cba2fdfb0152443032bc \ No newline at end of file diff --git a/src/os_common.h b/src/os_common.h index 088750963b..a8ac2707ae 100644 --- a/src/os_common.h +++ b/src/os_common.h @@ -24,7 +24,7 @@ ** on i486 hardware. */ int sqlite3_os_trace = 0; -#if 1 +#ifdef SQLITE_DEBUG static int last_page = 0; __inline__ unsigned long long int hwtime(void){ unsigned long long int x; diff --git a/src/vdbe.c b/src/vdbe.c index fc2d9cff87..4c1faef212 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.368 2004/06/12 09:25:25 danielk1977 Exp $ +** $Id: vdbe.c,v 1.369 2004/06/12 18:12:16 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -1899,7 +1899,7 @@ case OP_Column: { int p1 = pOp->p1; /* P1 value of the opcode */ int p2 = pOp->p2; /* column number to retrieve */ Cursor *pC = 0; /* The VDBE cursor */ - char *zRec; /* Pointer to record-data from stack or pseudo-table. */ + char *zRec; /* Pointer to complete record-data */ BtCursor *pCrsr; /* The BTree cursor */ u32 *aType; /* aType[i] holds the numeric type of the i-th column */ u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ @@ -1916,9 +1916,15 @@ case OP_Column: { assert( p1nCursor ); pTos++; - /* This block sets the variable payloadSize, and if the data is coming - ** from the stack or from a pseudo-table zRec. If the data is coming - ** from a real cursor, then zRec is left as NULL. + /* This block sets the variable payloadSize to be the total number of + ** bytes in the record. + ** + ** zRec is set to be the complete text of the record if it is available. + ** The complete record text is always available for pseudo-tables and + ** when we are decoded a record from the stack. If the record is stored + ** in a cursor, the complete record text might be available in the + ** pC->aRow cache. Or it might not be. If the data is unavailable, + ** zRec is set to NULL. ** ** We also compute the number of columns in the record. For cursors, ** the number of columns is stored in the Cursor.nField element. For @@ -1926,6 +1932,7 @@ case OP_Column: { ** which is the number of records. */ if( p1<0 ){ + /* Take the record off of the stack */ Mem *pRec = &pTos[p1]; Mem *pCnt = &pRec[-1]; assert( pRec>=p->aStack ); @@ -1936,6 +1943,7 @@ case OP_Column: { assert( pCnt->flags & MEM_Int ); nField = pCnt->i; }else if( (pC = p->apCsr[p1])->pCursor!=0 ){ + /* The record is stored in a B-Tree */ sqlite3VdbeCursorMoveto(pC); zRec = 0; pCrsr = pC->pCursor; @@ -1943,6 +1951,7 @@ case OP_Column: { payloadSize = 0; }else if( pC->cacheValid ){ payloadSize = pC->payloadSize; + zRec = pC->aRow; }else if( pC->keyAsData ){ i64 payloadSize64; sqlite3BtreeKeySize(pCrsr, &payloadSize64); @@ -1952,6 +1961,7 @@ case OP_Column: { } nField = pC->nField; }else if( pC->pseudoTable ){ + /* The record is the sole entry of a pseudo-table */ payloadSize = pC->nData; zRec = pC->pData; pC->cacheValid = 0; @@ -1996,11 +2006,27 @@ case OP_Column: { }else{ zData = (char*)sqlite3BtreeDataFetch(pCrsr, &avail); } + /* If KeyFetch()/DataFetch() managed to get the entire payload, + ** save the payload in the pC->aRow cache. That will save us from + ** having to make additional calls to fetch the content portion of + ** the record. + */ + if( avail>=payloadSize ){ + zRec = pC->aRow = zData; + }else{ + pC->aRow = 0; + } } idx = sqlite3GetVarint32(zData, &szHdr); - /* Get the complete header text */ - if( !zRec && availkeyAsData, &sMem); if( rc!=SQLITE_OK ){ goto abort_due_to_error; diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 709287d92e..39f27c1f60 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -83,11 +83,14 @@ struct Cursor { int nField; /* Number of fields in the header */ /* Cached information about the header for the data record that the - ** cursor is currently pointing to */ + ** cursor is currently pointing to. Only valid if cacheValid is true. + ** zRow might point to (ephemeral) data for the current row, or it might + ** be NULL. */ Bool cacheValid; /* True if the cache is valid */ int payloadSize; /* Total number of bytes in the record */ u32 *aType; /* Type values for all entries in the record */ u32 *aOffset; /* Cached offsets to the start of each columns data */ + u8 *aRow; /* Data for the current row, if all on one page */ }; typedef struct Cursor Cursor;