Compare commits

...

2 Commits

Author SHA1 Message Date
drh 202dd9c2db Make the VdbeCursor object even smaller. But the resulting library is bigger
and slower than trunk.  This branch is a failed experiment.

FossilOrigin-Name: 896a06cc182491d87950c287df45c0656e284d35
2015-12-17 19:17:43 +00:00
drh 65b30ca58a Reduce the size of the VdbeCursor object by a pointer (the pBt pointer used
for ephemeral tables).

FossilOrigin-Name: 98b710c36343fc213c8223f353907934be60b60d
2015-12-17 17:30:53 +00:00
8 changed files with 86 additions and 61 deletions
+11 -11
View File
@@ -1,5 +1,5 @@
C Fix\sthe\sspellfix1_scriptcode()\sfunction\sto\signore\swhitespace\sand\spunctuation,\nand\sto\srecognize\shebrew\sand\sarabic\sscripts.
D 2015-12-17T14:18:21.904
C Make\sthe\sVdbeCursor\sobject\seven\ssmaller.\s\sBut\sthe\sresulting\slibrary\sis\sbigger\nand\sslower\sthan\strunk.\s\sThis\sbranch\sis\sa\sfailed\sexperiment.
D 2015-12-17T19:17:43.940
F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 5fff077fcc46de7714ed6eebb6159a4c00eab751
@@ -276,8 +276,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc
F src/bitvec.c 1a78d450a17c5016710eec900bedfc5729bf9bdf
F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
F src/btree.c 84ede51e371a11c3dbb3e24ccc5e3e99594a6c00
F src/btree.h 2d76dee44704c47eed323356a758662724b674a0
F src/btree.c cb0ed74a8212a7b31fb967a162658f490a302a18
F src/btree.h 778f36cd143dae941e8b8d0cbc7b0f43ba35dfef
F src/btreeInt.h 3ab435ed27adea54d040584b0bcc488ee7db1e38
F src/build.c e83da4d004a4e050c01acbb821ff7a7b1019c29b
F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
@@ -398,14 +398,14 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3
F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c
F src/util.c e802e8e311a0d6c48cd1b3e89db164f6f0248d70
F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
F src/vdbe.c 984c2be6691d3f67deb2e6747c2132150d776f32
F src/vdbe.c 3bedca4adcf7dc42224a20049883c89819c459b0
F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637
F src/vdbeInt.h 75c2e82ee3357e9210c06474f8d9bdf12c81105d
F src/vdbeInt.h 06caadd917765d7b981686b1dd33845023ccfbdc
F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca
F src/vdbeaux.c 68082d9991fc1b8625d34c8b5db1775c9dee426e
F src/vdbeaux.c b0d427a5070bae99f137368356674457d018c168
F src/vdbeblob.c fdc4a81605ae7a35ae94a55bd768b66d6be16f15
F src/vdbemem.c fdd1578e47bea61390d472de53c565781d81e045
F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d
F src/vdbesort.c 90a3545ed856e1007c77ca3ac4f9c1975a64ed23
F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0
F src/vtab.c 2a8b44aa372c33f6154208e7a7f6c44254549806
F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
@@ -1405,7 +1405,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 85ebd46c701e0a094a4690cd8f1d0cbae9aa257c
R 70cdc580d7d9b92b032d33f5e0d50f2e
P 98b710c36343fc213c8223f353907934be60b60d
R 10fdd2deb8319d6498b358eb4665321f
U drh
Z 6d4b5ed9cd1870281d7d851922f323d8
Z dceb428fbc78dc00f293c1c742052765
+1 -1
View File
@@ -1 +1 @@
7adfa4a5794e47f97491c08abeaaac90e826b331
896a06cc182491d87950c287df45c0656e284d35
+8
View File
@@ -4182,6 +4182,14 @@ void sqlite3BtreeCursorZero(BtCursor *p){
memset(p, 0, offsetof(BtCursor, iPage));
}
/*
** Return the Btree object associated with a BtCursor.
*/
Btree *sqlite3BtreeOfCursor(BtCursor *p){
assert( p!=0 );
return p->pBtree;
}
/*
** Close a cursor. The read lock on the database file is released
** when the last cursor is closed.
+1
View File
@@ -221,6 +221,7 @@ int sqlite3BtreeCursor(
int sqlite3BtreeCursorSize(void);
void sqlite3BtreeCursorZero(BtCursor*);
void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
Btree *sqlite3BtreeOfCursor(BtCursor*);
#ifdef SQLITE_ENABLE_CURSOR_HINTS
void sqlite3BtreeCursorHint(BtCursor*, int, ...);
#endif
+48 -36
View File
@@ -3441,6 +3441,7 @@ case OP_OpenAutoindex:
case OP_OpenEphemeral: {
VdbeCursor *pCx;
KeyInfo *pKeyInfo;
Btree *pBt;
static const int vfsFlags =
SQLITE_OPEN_READWRITE |
@@ -3453,35 +3454,39 @@ case OP_OpenEphemeral: {
pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
if( pCx==0 ) goto no_mem;
pCx->nullRow = 1;
pCx->isEphemeral = 1;
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt,
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
if( rc==SQLITE_OK ){
rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
}
if( rc==SQLITE_OK ){
/* If a transient index is required, create it by calling
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
** opening it. If a transient table is required, just use the
** automatically created table with root-page 1 (an BLOB_INTKEY table).
*/
if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
int pgno;
assert( pOp->p4type==P4_KEYINFO );
rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
if( rc==SQLITE_OK ){
assert( pgno==MASTER_ROOT+1 );
assert( pKeyInfo->db==db );
assert( pKeyInfo->enc==ENC(db) );
pCx->pKeyInfo = pKeyInfo;
rc = sqlite3BtreeCursor(pCx->pBt, pgno, BTREE_WRCSR,
pKeyInfo, pCx->uc.pCursor);
rc = sqlite3BtreeBeginTrans(pBt, 1);
if( rc==SQLITE_OK ){
/* If a transient index is required, create it by calling
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
** opening it. If a transient table is required, just use the
** automatically created table with root-page 1 (an BLOB_INTKEY table).
*/
if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
int pgno;
assert( pOp->p4type==P4_KEYINFO );
rc = sqlite3BtreeCreateTable(pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
if( rc==SQLITE_OK ){
assert( pgno==MASTER_ROOT+1 );
assert( pKeyInfo->db==db );
assert( pKeyInfo->enc==ENC(db) );
pCx->pKeyInfo = pKeyInfo;
rc = sqlite3BtreeCursor(pBt, pgno, BTREE_WRCSR,
pKeyInfo, pCx->uc.pCursor);
}
pCx->isTable = 0;
}else{
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, BTREE_WRCSR,
0, pCx->uc.pCursor);
pCx->isTable = 1;
}
pCx->isTable = 0;
}
if( rc==SQLITE_OK ){
pCx->isEphemeral = 1;
}else{
rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, BTREE_WRCSR,
0, pCx->uc.pCursor);
pCx->isTable = 1;
sqlite3BtreeClose(pBt);
}
}
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
@@ -3524,7 +3529,8 @@ case OP_SequenceTest: {
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
pC = p->apCsr[pOp->p1];
assert( isSorter(pC) );
if( (pC->seqCount++)==0 ){
assert( !pC->movetoUsed );
if( (pC->ux.seqCount++)==0 ){
goto jump_to_p2;
}
break;
@@ -3754,7 +3760,8 @@ case OP_SeekGT: { /* jump, in3 */
}
}
rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)iKey, 0, &res);
pC->movetoTarget = iKey; /* Used by OP_Delete */
VVA_ONLY( pC->movetoUsed = 1; )
pC->ux.movetoTarget = iKey; /* Used by OP_Delete */
if( rc!=SQLITE_OK ){
goto abort_due_to_error;
}
@@ -3862,11 +3869,13 @@ case OP_Seek: { /* in2 */
pC = p->apCsr[pOp->p1];
assert( pC!=0 );
assert( pC->eCurType==CURTYPE_BTREE );
assert( !pC->isEphemeral );
assert( pC->uc.pCursor!=0 );
assert( pC->isTable );
pC->nullRow = 0;
pIn2 = &aMem[pOp->p2];
pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
VVA_ONLY( pC->movetoUsed = 1; )
pC->ux.movetoTarget = sqlite3VdbeIntValue(pIn2);
pC->deferredMoveto = 1;
break;
}
@@ -4055,7 +4064,8 @@ case OP_NotExists: { /* jump, in3 */
iKey = pIn3->u.i;
rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
assert( rc==SQLITE_OK || res==0 );
pC->movetoTarget = iKey; /* Used by OP_Delete */
VVA_ONLY( pC->movetoUsed = 1; )
pC->ux.movetoTarget = iKey; /* Used by OP_Delete */
pC->nullRow = 0;
pC->cacheStatus = CACHE_STALE;
pC->deferredMoveto = 0;
@@ -4083,9 +4093,11 @@ case OP_NotExists: { /* jump, in3 */
case OP_Sequence: { /* out2 */
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
assert( p->apCsr[pOp->p1]!=0 );
assert( p->apCsr[pOp->p1]->eCurType!=CURTYPE_VTAB );
assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE );
assert( p->apCsr[pOp->p1]->isEphemeral );
assert( !p->apCsr[pOp->p1]->movetoUsed );
pOut = out2Prerelease(p, pOp);
pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
pOut->u.i = p->apCsr[pOp->p1]->ux.seqCount++;
break;
}
@@ -4370,17 +4382,17 @@ case OP_Delete: {
hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable;
if( pOp->p5 && hasUpdateCallback ){
sqlite3BtreeKeySize(pC->uc.pCursor, &pC->movetoTarget);
sqlite3BtreeKeySize(pC->uc.pCursor, &pC->ux.movetoTarget);
}
#ifdef SQLITE_DEBUG
/* The seek operation that positioned the cursor prior to OP_Delete will
** have also set the pC->movetoTarget field to the rowid of the row that
** have also set the pC->ux.movetoTarget field to the rowid of the row that
** is being deleted */
if( pOp->p4.z && pC->isTable && pOp->p5==0 ){
i64 iKey = 0;
sqlite3BtreeKeySize(pC->uc.pCursor, &iKey);
assert( pC->movetoTarget==iKey );
assert( pC->ux.movetoTarget==iKey );
}
#endif
@@ -4390,7 +4402,7 @@ case OP_Delete: {
/* Invoke the update-hook if required. */
if( rc==SQLITE_OK && hasUpdateCallback ){
db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
db->aDb[pC->iDb].zName, pOp->p4.z, pC->ux.movetoTarget);
assert( pC->iDb>=0 );
}
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
@@ -4581,7 +4593,7 @@ case OP_Rowid: { /* out2 */
pOut->flags = MEM_Null;
break;
}else if( pC->deferredMoveto ){
v = pC->movetoTarget;
v = pC->ux.movetoTarget;
#ifndef SQLITE_OMIT_VIRTUALTABLE
}else if( pC->eCurType==CURTYPE_VTAB ){
assert( pC->uc.pVCur!=0 );
+9 -7
View File
@@ -77,16 +77,18 @@ typedef struct AuxData AuxData;
struct VdbeCursor {
u8 eCurType; /* One of the CURTYPE_* values above */
i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
u8 nullRow; /* True if pointing to a row with no data */
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
u8 isTable; /* True for rowid tables. False for indexes */
#ifdef SQLITE_DEBUG
u8 seekOp; /* Most recent seek operation on this cursor */
Bool movetoUsed:1; /* True if ux.movetoTarget has been used */
#endif
Bool nullRow:1; /* True if pointing to a row with no data */
Bool deferredMoveto:1; /* A call to sqlite3BtreeMoveto() is needed */
Bool isTable:1; /* True for rowid tables. False for indexes */
Bool isEphemeral:1; /* True for an ephemeral table */
Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
Pgno pgnoRoot; /* Root page of the open btree cursor */
int seekResult; /* Result of previous sqlite3BtreeMoveto() */
i16 nField; /* Number of fields in the header */
u16 nHdrParsed; /* Number of header fields parsed so far */
union {
@@ -95,11 +97,11 @@ struct VdbeCursor {
int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
} uc;
Btree *pBt; /* Separate file holding temporary table */
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
int seekResult; /* Result of previous sqlite3BtreeMoveto() */
i64 seqCount; /* Sequence counter */
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
union {
i64 seqCount; /* Sequence counter. Only valid if movetoUsed==0 */
i64 movetoTarget; /* Rowid moved to. */
} ux;
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
u64 maskUsed; /* Mask of columns used by this cursor */
#endif
+7 -5
View File
@@ -1925,19 +1925,19 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
if( pCx==0 ){
return;
}
assert( pCx->pBt==0 || pCx->eCurType==CURTYPE_BTREE );
assert( pCx->isEphemeral==0 || pCx->eCurType==CURTYPE_BTREE );
switch( pCx->eCurType ){
case CURTYPE_SORTER: {
sqlite3VdbeSorterClose(p->db, pCx);
break;
}
case CURTYPE_BTREE: {
if( pCx->pBt ){
sqlite3BtreeClose(pCx->pBt);
assert( pCx->uc.pCursor!=0 );
if( pCx->isEphemeral ){
sqlite3BtreeClose(sqlite3BtreeOfCursor(pCx->uc.pCursor));
/* The pCx->pCursor will be close automatically, if it exists, by
** the call above. */
}else{
assert( pCx->uc.pCursor!=0 );
sqlite3BtreeCloseCursor(pCx->uc.pCursor);
}
break;
@@ -2940,7 +2940,9 @@ static int SQLITE_NOINLINE handleDeferredMoveto(VdbeCursor *p){
assert( p->deferredMoveto );
assert( p->isTable );
assert( p->eCurType==CURTYPE_BTREE );
rc = sqlite3BtreeMovetoUnpacked(p->uc.pCursor, 0, p->movetoTarget, 0, &res);
assert( !p->isEphemeral );
assert( p->movetoUsed );
rc = sqlite3BtreeMovetoUnpacked(p->uc.pCursor, 0, p->ux.movetoTarget, 0,&res);
if( rc ) return rc;
if( res!=0 ) return SQLITE_CORRUPT_BKPT;
#ifdef SQLITE_TEST
+1 -1
View File
@@ -960,7 +960,7 @@ int sqlite3VdbeSorterInit(
}
#endif
assert( pCsr->pKeyInfo && pCsr->pBt==0 );
assert( pCsr->pKeyInfo && !pCsr->isEphemeral );
assert( pCsr->eCurType==CURTYPE_SORTER );
szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);