]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Tweaks to make OP_Column run a fraction faster. (CVS 2941)
authordanielk1977 <danielk1977@noemail.net>
Fri, 13 Jan 2006 17:12:01 +0000 (17:12 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Fri, 13 Jan 2006 17:12:01 +0000 (17:12 +0000)
FossilOrigin-Name: 2d74cc22de2aa59329b1ea5c26acd6ebe46e16c2

manifest
manifest.uuid
src/vdbe.c

index 7d91834c49a9c6cbc9021a7665f4291af486cef2..5eb7c6ec22fc1540eab8ac12480b1cf243cef40b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Avoid\sparsing\san\sentire\srecord\sheader\swhen\sit\sis\snot\srequired.\s(CVS\s2940)
-D 2006-01-13T15:58:43
+C Tweaks\sto\smake\sOP_Column\srun\sa\sfraction\sfaster.\s(CVS\s2941)
+D 2006-01-13T17:12:01
 F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -87,7 +87,7 @@ F src/update.c 261d75c702c2852d1a64274d7c414485e6f2d177
 F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d
 F src/util.c b26be916edd1c991450cccc6503356c4f776598b
 F src/vacuum.c 21a3c7f6f7be86bb1182fbc3df416ad702435b9e
-F src/vdbe.c e2f081425c3b2be6e7ff25fbb2f3f70fa95413ee
+F src/vdbe.c bf64026224ade859b32e6c01fcf292fbf069cb95
 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
 F src/vdbeInt.h 5451cf71f229e366ac543607c0a17f36e5737ea9
 F src/vdbeapi.c afd3837cea0dec93dcb4724d073c84fa0da68e23
@@ -340,7 +340,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 55b7dfaf4d3a6d01fffdaf1707e88bcd215d7333
-R 07d8c70ff570eb317ee47042ddb86743
+P 0de729d9144afba144811799f65e32140c14ef8a
+R 4fc53b80c7e70cf5aaa2736ccda17872
 U danielk1977
-Z 7bb864839753b74a0c8dfa1447111caa
+Z 8db44b8359d9daca4aa7858d0ea683db
index a05cca946c930d7952f38c455b3da547f022620a..83b708ac5ae3fda6ef6b69c6a59501605b5bf166 100644 (file)
@@ -1 +1 @@
-0de729d9144afba144811799f65e32140c14ef8a
\ No newline at end of file
+2d74cc22de2aa59329b1ea5c26acd6ebe46e16c2
\ No newline at end of file
index 563fd7561a58415c2e792470a75b78f399524995..2859eb9f0a0b1b23c9623c55a960061b3b4985ab 100644 (file)
@@ -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.528 2006/01/13 15:58:43 danielk1977 Exp $
+** $Id: vdbe.c,v 1.529 2006/01/13 17:12:01 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -1883,10 +1883,7 @@ case OP_Column: {
   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 */
   u32 nField;        /* number of fields in the record */
-  u32 szHdr;         /* Number of bytes in the record header */
   int len;           /* The length of the serialized data for the column */
-  int offset = 0;    /* Offset into the data */
-  int idx;           /* Index into the header */
   int i;             /* Loop counter */
   char *zData;       /* Part of the record being decoded */
   Mem sMem;          /* For storing the record being decoded */
@@ -1975,7 +1972,10 @@ case OP_Column: {
     aType = pC->aType;
     aOffset = pC->aOffset;
   }else{
-    int avail;    /* Number of bytes of available data */
+    u8 *zIdx;        /* Index into header */
+    u8 *zEndHdr;     /* Pointer to first byte after the header */
+    u32 offset;      /* Offset into the data */
+    int avail;       /* Number of bytes of available data */
     if( pC && pC->aType ){
       aType = pC->aType;
     }else{
@@ -2007,8 +2007,7 @@ case OP_Column: {
         pC->aRow = 0;
       }
     }
-    idx = GetVarint((u8*)zData, szHdr);
-
+    zIdx = (u8 *)GetVarint((u8*)zData, offset);
 
     /* The KeyFetch() or DataFetch() above are fast and will get the entire
     ** record header in most cases.  But they will fail to get the complete
@@ -2016,46 +2015,44 @@ case OP_Column: {
     ** in the B-Tree.  When that happens, use sqlite3VdbeMemFromBtree() to
     ** acquire the complete header text.
     */
-    if( !zRec && avail<szHdr ){
-      rc = sqlite3VdbeMemFromBtree(pCrsr, 0, szHdr, pC->isIndex, &sMem);
+    if( !zRec && avail<offset ){
+      rc = sqlite3VdbeMemFromBtree(pCrsr, 0, offset, pC->isIndex, &sMem);
       if( rc!=SQLITE_OK ){
         goto op_column_out;
       }
       zData = sMem.z;
     }
+    zEndHdr = (u8 *)zData + offset;
+    zIdx = zData + (int)zIdx;
 
     /* Scan the header and use it to fill in the aType[] and aOffset[]
     ** arrays.  aType[i] will contain the type integer for the i-th
     ** column and aOffset[i] will contain the offset from the beginning
     ** of the record to the start of the data for the i-th column
     */
-    offset = szHdr;
-    assert( offset>0 );
-    i = 0;
-    while( idx<szHdr && i<nField && offset<=payloadSize ){
-      aOffset[i] = offset;
-      idx += GetVarint((u8*)&zData[idx], aType[i]);
-      offset += sqlite3VdbeSerialTypeLen(aType[i]);
-      i++;
+    for(i=0; i<nField; i++){
+      if( zIdx<zEndHdr ){
+        aOffset[i] = offset;
+        zIdx += GetVarint(zIdx, aType[i]);
+        offset += sqlite3VdbeSerialTypeLen(aType[i]);
+      }else{
+        /* If i is less that nField, then there are less fields in this
+        ** record than SetNumColumns indicated there are columns in the
+        ** table. Set the offset for any extra columns not present in
+        ** the record to 0. This tells code below to push a NULL onto the
+        ** stack instead of deserializing a value from the record.
+        */
+        aOffset[i] = 0;
+      }
     }
     Release(&sMem);
     sMem.flags = MEM_Null;
 
-    /* If i is less that nField, then there are less fields in this
-    ** record than SetNumColumns indicated there are columns in the
-    ** table. Set the offset for any extra columns not present in
-    ** the record to 0. This tells code below to push a NULL onto the
-    ** stack instead of deserializing a value from the record.
-    */
-    while( i<nField ){
-      aOffset[i++] = 0;
-    }
-
     /* If we have read more header data than was contained in the header,
     ** or if the end of the last field appears to be past the end of the
     ** record, then we must be dealing with a corrupt database.
     */
-    if( idx>szHdr || offset>payloadSize ){
+    if( zIdx>zEndHdr || offset>payloadSize ){
       rc = SQLITE_CORRUPT_BKPT;
       goto op_column_out;
     }