From: drh Date: Thu, 17 Dec 2015 17:30:53 +0000 (+0000) Subject: Reduce the size of the VdbeCursor object by a pointer (the pBt pointer used X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65b30ca58a41f00e505018478cf7949a99587444;p=thirdparty%2Fsqlite.git Reduce the size of the VdbeCursor object by a pointer (the pBt pointer used for ephemeral tables). FossilOrigin-Name: 98b710c36343fc213c8223f353907934be60b60d --- diff --git a/manifest b/manifest index 799ac619df..db1dc9a1b1 100644 --- a/manifest +++ b/manifest @@ -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 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 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 1879236383d730d99abb825d14b9c06ecfec931d F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637 -F src/vdbeInt.h 75c2e82ee3357e9210c06474f8d9bdf12c81105d +F src/vdbeInt.h 6c879b499dc98dbc0ec5edb92a210fdcc979b919 F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca -F src/vdbeaux.c 68082d9991fc1b8625d34c8b5db1775c9dee426e +F src/vdbeaux.c 7b2db8d1b5042920f9c775b4c0bf23f50b2f5f9d 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,10 @@ 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 7adfa4a5794e47f97491c08abeaaac90e826b331 +R a16632c6e8507cdeda30edf695604402 +T *branch * optimize-vdbecursor +T *sym-optimize-vdbecursor * +T -sym-trunk * U drh -Z 6d4b5ed9cd1870281d7d851922f323d8 +Z 6d89310e965f290e1d3a90698ce47a16 diff --git a/manifest.uuid b/manifest.uuid index eebc618153..f6f0fb0bc4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7adfa4a5794e47f97491c08abeaaac90e826b331 \ No newline at end of file +98b710c36343fc213c8223f353907934be60b60d \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4e384e2c4f..3d53e56ab4 100644 --- a/src/btree.c +++ b/src/btree.c @@ -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. diff --git a/src/btree.h b/src/btree.h index 09b713f3db..7b46bc86bc 100644 --- a/src/btree.h +++ b/src/btree.h @@ -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 diff --git a/src/vdbe.c b/src/vdbe.c index 894758a01c..b234a387f2 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -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); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index d1de55eb1c..6d6426156f 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -95,7 +95,6 @@ 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 */ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index a266177ac5..7a52bca19d 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -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; diff --git a/src/vdbesort.c b/src/vdbesort.c index 54e538fd50..40e7454da0 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -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);