From: drh Date: Thu, 17 Dec 2015 19:17:43 +0000 (+0000) Subject: Make the VdbeCursor object even smaller. But the resulting library is bigger X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Foptimize-vdbecursor;p=thirdparty%2Fsqlite.git 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 --- diff --git a/manifest b/manifest index db1dc9a1b1..1f44687c6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reduce\sthe\ssize\sof\sthe\sVdbeCursor\sobject\sby\sa\spointer\s(the\spBt\spointer\sused\nfor\sephemeral\stables). -D 2015-12-17T17:30:53.420 +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 @@ -398,11 +398,11 @@ F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c e802e8e311a0d6c48cd1b3e89db164f6f0248d70 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c 1879236383d730d99abb825d14b9c06ecfec931d +F src/vdbe.c 3bedca4adcf7dc42224a20049883c89819c459b0 F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637 -F src/vdbeInt.h 6c879b499dc98dbc0ec5edb92a210fdcc979b919 +F src/vdbeInt.h 06caadd917765d7b981686b1dd33845023ccfbdc F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca -F src/vdbeaux.c 7b2db8d1b5042920f9c775b4c0bf23f50b2f5f9d +F src/vdbeaux.c b0d427a5070bae99f137368356674457d018c168 F src/vdbeblob.c fdc4a81605ae7a35ae94a55bd768b66d6be16f15 F src/vdbemem.c fdd1578e47bea61390d472de53c565781d81e045 F src/vdbesort.c 90a3545ed856e1007c77ca3ac4f9c1975a64ed23 @@ -1405,10 +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 7adfa4a5794e47f97491c08abeaaac90e826b331 -R a16632c6e8507cdeda30edf695604402 -T *branch * optimize-vdbecursor -T *sym-optimize-vdbecursor * -T -sym-trunk * +P 98b710c36343fc213c8223f353907934be60b60d +R 10fdd2deb8319d6498b358eb4665321f U drh -Z 6d89310e965f290e1d3a90698ce47a16 +Z dceb428fbc78dc00f293c1c742052765 diff --git a/manifest.uuid b/manifest.uuid index f6f0fb0bc4..6d373813d8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -98b710c36343fc213c8223f353907934be60b60d \ No newline at end of file +896a06cc182491d87950c287df45c0656e284d35 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index b234a387f2..99891d3e43 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3529,7 +3529,8 @@ case OP_SequenceTest: { assert( pOp->p1>=0 && pOp->p1nCursor ); 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; @@ -3759,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; } @@ -3867,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; } @@ -4060,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; @@ -4088,9 +4093,11 @@ case OP_NotExists: { /* jump, in3 */ case OP_Sequence: { /* out2 */ assert( pOp->p1>=0 && pOp->p1nCursor ); 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; } @@ -4375,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 @@ -4395,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++; @@ -4586,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 ); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 6d6426156f..fcca3bb1a3 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -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 { @@ -96,9 +98,10 @@ struct VdbeCursor { VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */ } uc; 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 diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 7a52bca19d..7e055665ec 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -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