]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Speed improvement by avoiding a call to sqliteBtreeLast() when inserting a
authordrh <drh@noemail.net>
Sat, 19 Oct 2002 20:16:37 +0000 (20:16 +0000)
committerdrh <drh@noemail.net>
Sat, 19 Oct 2002 20:16:37 +0000 (20:16 +0000)
new row into a table. (CVS 763)

FossilOrigin-Name: d0af59fe6b9d5d026786e7cce1c49c208a0335cc

manifest
manifest.uuid
src/vdbe.c

index 236f1f5bede01cc1cf4a6924f94f88a6dfdd403b..2bba6412c9c283c1981f6775adbfc0249025c361 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\sURL\sfor\spointing\sto\sMinGW\son\sthe\shomepage.\s(CVS\s762)
-D 2002-10-19T20:13:51
+C Speed\simprovement\sby\savoiding\sa\scall\sto\ssqliteBtreeLast()\swhen\sinserting\sa\nnew\srow\sinto\sa\stable.\s(CVS\s763)
+D 2002-10-19T20:16:38
 F Makefile.in d6c9a85c2a5e696843201d090dcf8bf2f8716f2a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -52,7 +52,7 @@ F src/tokenize.c 62c98842447effe92eba9622bb2f9a2a8a4b97ad
 F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481
 F src/update.c 881e4c8e7c786545da4fd2d95da19252b2e31137
 F src/util.c cd28b33c6849c9722ab72758b7b86989bc64fa27
-F src/vdbe.c ac4ccc17d965e5754144cfec493093cf4272c126
+F src/vdbe.c 4144effb953f1f25eb451dba85e69f0c34e3b788
 F src/vdbe.h b7584044223104ba7896a7f87b66daebdd6022ba
 F src/where.c 8ff2acfcb9bb15a057512bd6207b259feed57a2c
 F test/all.test efd958d048c70a3247997c482f0b33561f7759f0
@@ -149,7 +149,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P b53ab71d074ada47ce22bd161f6aee24587302af
-R dc777f5c50257e5bd8bd8e95ead8ade9
+P 16aad98aad4d8dd4a8400cdee32004b8c4785d60
+R 1de19ca25a16a11c2dec003aa1ffd1a2
 U drh
-Z 2951b597bc23253105199ba2fa6ecd1d
+Z 58d83640e24d56cfd3739aa320366770
index a2f0d47b9181d0178a3ea572f6ef20aa71a85fee..e0fbf054dfce9b6b84ae0fd5d44d0a540310ebad 100644 (file)
@@ -1 +1 @@
-16aad98aad4d8dd4a8400cdee32004b8c4785d60
\ No newline at end of file
+d0af59fe6b9d5d026786e7cce1c49c208a0335cc
\ No newline at end of file
index a5189c36a8a148013307eae87138f7a0534d7c77..e22953595b257d3234d1a1b24192baec6bb3c0a9 100644 (file)
@@ -36,7 +36,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.179 2002/09/17 03:20:46 drh Exp $
+** $Id: vdbe.c,v 1.180 2002/10/19 20:16:38 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -83,11 +83,13 @@ typedef unsigned char Bool;
 struct Cursor {
   BtCursor *pCursor;    /* The cursor structure of the backend */
   int lastRecno;        /* Last recno from a Next or NextIdx operation */
+  int nextRowid;        /* Next rowid returned by OP_NewRowid */
   Bool recnoIsValid;    /* True if lastRecno is valid */
   Bool keyAsData;       /* The OP_Column command works on key instead of data */
   Bool atFirst;         /* True if pointing to first entry */
   Bool useRandomRowid;  /* Generate new record numbers semi-randomly */
   Bool nullRow;         /* True if pointing to a row with no data */
+  Bool nextRowidValid;  /* True if the nextRowid field is valid */
   Btree *pBt;           /* Separate file holding temporary table */
 };
 typedef struct Cursor Cursor;
@@ -3560,18 +3562,28 @@ case OP_NewRecno: {
     int res, rx, cnt, x;
     cnt = 0;
     if( !pC->useRandomRowid ){
-      rx = sqliteBtreeLast(pC->pCursor, &res);
-      if( res ){
-        v = 1;
+      if( pC->nextRowidValid ){
+        v = pC->nextRowid;
       }else{
-        sqliteBtreeKey(pC->pCursor, 0, sizeof(v), (void*)&v);
-        v = keyToInt(v);
-        if( v==0x7fffffff ){
-          pC->useRandomRowid = 1;
+        rx = sqliteBtreeLast(pC->pCursor, &res);
+        if( res ){
+          v = 1;
         }else{
-          v++;
+          sqliteBtreeKey(pC->pCursor, 0, sizeof(v), (void*)&v);
+          v = keyToInt(v);
+          if( v==0x7fffffff ){
+            pC->useRandomRowid = 1;
+          }else{
+            v++;
+          }
         }
       }
+      if( v<0x7fffffff ){
+        pC->nextRowidValid = 1;
+        pC->nextRowid = v+1;
+      }else{
+        pC->nextRowidValid = 0;
+      }
     }
     if( pC->useRandomRowid ){
       v = db->priorNewRowid;
@@ -3627,8 +3639,9 @@ case OP_PutStrKey: {
   int tos = p->tos;
   int nos = p->tos-1;
   int i = pOp->p1;
+  Cursor *pC;
   VERIFY( if( nos<0 ) goto not_enough_stack; )
-  if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor!=0 ){
+  if( VERIFY( i>=0 && i<p->nCursor && ) (pC = &p->aCsr[i])->pCursor!=0 ){
     char *zKey;
     int nKey, iKey;
     if( pOp->opcode==OP_PutStrKey ){
@@ -3642,10 +3655,13 @@ case OP_PutStrKey: {
       zKey = (char*)&iKey;
       db->lastRowid = aStack[nos].i;
       if( pOp->p2 ) db->nChange++;
+      if( pC->nextRowidValid && aStack[nos].i>=pC->nextRowid ){
+        pC->nextRowidValid = 0;
+      }
     }
-    rc = sqliteBtreeInsert(p->aCsr[i].pCursor, zKey, nKey,
+    rc = sqliteBtreeInsert(pC->pCursor, zKey, nKey,
                         zStack[tos], aStack[tos].n);
-    p->aCsr[i].recnoIsValid = 0;
+    pC->recnoIsValid = 0;
   }
   POPSTACK;
   POPSTACK;
@@ -3666,8 +3682,10 @@ case OP_PutStrKey: {
 */
 case OP_Delete: {
   int i = pOp->p1;
-  if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor!=0 ){
-    rc = sqliteBtreeDelete(p->aCsr[i].pCursor);
+  Cursor *pC;
+  if( VERIFY( i>=0 && i<p->nCursor && ) (pC = &p->aCsr[i])->pCursor!=0 ){
+    rc = sqliteBtreeDelete(pC->pCursor);
+    pC->nextRowidValid = 0;
   }
   if( pOp->p2 ) db->nChange++;
   break;