1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Speed improvement by avoiding a call to sqliteBtreeLast() when inserting a

new row into a table. (CVS 763)

FossilOrigin-Name: d0af59fe6b9d5d026786e7cce1c49c208a0335cc
This commit is contained in:
drh
2002-10-19 20:16:37 +00:00
parent 906bf2a316
commit 32fbe342db
3 changed files with 39 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sthe\sURL\sfor\spointing\sto\sMinGW\son\sthe\shomepage.\s(CVS\s762) C Speed\simprovement\sby\savoiding\sa\scall\sto\ssqliteBtreeLast()\swhen\sinserting\sa\nnew\srow\sinto\sa\stable.\s(CVS\s763)
D 2002-10-19T20:13:51 D 2002-10-19T20:16:38
F Makefile.in d6c9a85c2a5e696843201d090dcf8bf2f8716f2a F Makefile.in d6c9a85c2a5e696843201d090dcf8bf2f8716f2a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -52,7 +52,7 @@ F src/tokenize.c 62c98842447effe92eba9622bb2f9a2a8a4b97ad
F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481 F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481
F src/update.c 881e4c8e7c786545da4fd2d95da19252b2e31137 F src/update.c 881e4c8e7c786545da4fd2d95da19252b2e31137
F src/util.c cd28b33c6849c9722ab72758b7b86989bc64fa27 F src/util.c cd28b33c6849c9722ab72758b7b86989bc64fa27
F src/vdbe.c ac4ccc17d965e5754144cfec493093cf4272c126 F src/vdbe.c 4144effb953f1f25eb451dba85e69f0c34e3b788
F src/vdbe.h b7584044223104ba7896a7f87b66daebdd6022ba F src/vdbe.h b7584044223104ba7896a7f87b66daebdd6022ba
F src/where.c 8ff2acfcb9bb15a057512bd6207b259feed57a2c F src/where.c 8ff2acfcb9bb15a057512bd6207b259feed57a2c
F test/all.test efd958d048c70a3247997c482f0b33561f7759f0 F test/all.test efd958d048c70a3247997c482f0b33561f7759f0
@@ -149,7 +149,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P b53ab71d074ada47ce22bd161f6aee24587302af P 16aad98aad4d8dd4a8400cdee32004b8c4785d60
R dc777f5c50257e5bd8bd8e95ead8ade9 R 1de19ca25a16a11c2dec003aa1ffd1a2
U drh U drh
Z 2951b597bc23253105199ba2fa6ecd1d Z 58d83640e24d56cfd3739aa320366770

View File

@@ -1 +1 @@
16aad98aad4d8dd4a8400cdee32004b8c4785d60 d0af59fe6b9d5d026786e7cce1c49c208a0335cc

View File

@@ -36,7 +36,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** 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 "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -83,11 +83,13 @@ typedef unsigned char Bool;
struct Cursor { struct Cursor {
BtCursor *pCursor; /* The cursor structure of the backend */ BtCursor *pCursor; /* The cursor structure of the backend */
int lastRecno; /* Last recno from a Next or NextIdx operation */ 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 recnoIsValid; /* True if lastRecno is valid */
Bool keyAsData; /* The OP_Column command works on key instead of data */ Bool keyAsData; /* The OP_Column command works on key instead of data */
Bool atFirst; /* True if pointing to first entry */ Bool atFirst; /* True if pointing to first entry */
Bool useRandomRowid; /* Generate new record numbers semi-randomly */ Bool useRandomRowid; /* Generate new record numbers semi-randomly */
Bool nullRow; /* True if pointing to a row with no data */ 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 */ Btree *pBt; /* Separate file holding temporary table */
}; };
typedef struct Cursor Cursor; typedef struct Cursor Cursor;
@@ -3560,18 +3562,28 @@ case OP_NewRecno: {
int res, rx, cnt, x; int res, rx, cnt, x;
cnt = 0; cnt = 0;
if( !pC->useRandomRowid ){ if( !pC->useRandomRowid ){
rx = sqliteBtreeLast(pC->pCursor, &res); if( pC->nextRowidValid ){
if( res ){ v = pC->nextRowid;
v = 1;
}else{ }else{
sqliteBtreeKey(pC->pCursor, 0, sizeof(v), (void*)&v); rx = sqliteBtreeLast(pC->pCursor, &res);
v = keyToInt(v); if( res ){
if( v==0x7fffffff ){ v = 1;
pC->useRandomRowid = 1;
}else{ }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 ){ if( pC->useRandomRowid ){
v = db->priorNewRowid; v = db->priorNewRowid;
@@ -3627,8 +3639,9 @@ case OP_PutStrKey: {
int tos = p->tos; int tos = p->tos;
int nos = p->tos-1; int nos = p->tos-1;
int i = pOp->p1; int i = pOp->p1;
Cursor *pC;
VERIFY( if( nos<0 ) goto not_enough_stack; ) 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; char *zKey;
int nKey, iKey; int nKey, iKey;
if( pOp->opcode==OP_PutStrKey ){ if( pOp->opcode==OP_PutStrKey ){
@@ -3642,10 +3655,13 @@ case OP_PutStrKey: {
zKey = (char*)&iKey; zKey = (char*)&iKey;
db->lastRowid = aStack[nos].i; db->lastRowid = aStack[nos].i;
if( pOp->p2 ) db->nChange++; 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); zStack[tos], aStack[tos].n);
p->aCsr[i].recnoIsValid = 0; pC->recnoIsValid = 0;
} }
POPSTACK; POPSTACK;
POPSTACK; POPSTACK;
@@ -3666,8 +3682,10 @@ case OP_PutStrKey: {
*/ */
case OP_Delete: { case OP_Delete: {
int i = pOp->p1; int i = pOp->p1;
if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor!=0 ){ Cursor *pC;
rc = sqliteBtreeDelete(p->aCsr[i].pCursor); 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++; if( pOp->p2 ) db->nChange++;
break; break;