From a6353a3f64584ac73a11b4afbe5147244a64f8aa Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Dec 2013 19:03:26 +0000 Subject: [PATCH 1/6] Performance optimizations for sqlite3VXPrintf(). FossilOrigin-Name: 9227ad48e1612b32a3a3e9551c49890f93abc0a7 --- manifest | 20 +++++++++---------- manifest.uuid | 2 +- src/btree.c | 2 +- src/build.c | 4 ++-- src/printf.c | 52 +++++++++++++++++++++++++++++++------------------ src/sqliteInt.h | 1 + src/where.c | 4 ++-- 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/manifest b/manifest index eb6e212626..029bbd9b38 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sincorrect\stest\snumber\sin\sthe\soutput\sof\sthe\sspeedtest1.c\sprogram.\s\sNo\nchanges\sto\sthe\stest\salgorithms. -D 2013-12-09T12:24:23.629 +C Performance\soptimizations\sfor\ssqlite3VXPrintf(). +D 2013-12-09T19:03:26.813 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,10 +166,10 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 1809a7caa2504233bdddd12f5018422421789537 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 432c3e22ff76e8ee1caf57ff88ba9f8af1fcfc30 +F src/btree.c 44a44aa21ee24763ddda98d9a41bd85498359ae2 F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9 F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0 -F src/build.c 9b40580b62916612678bdb69ce0286e39c29a862 +F src/build.c 47ef8209e56d840d2b35b8a243c6ee567ad52bda F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 77779efbe78dd678d84bfb4fc2e87b6b6ad8dccd @@ -215,7 +215,7 @@ F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63 F src/pragma.c 5ab7279d132143feb77f773688a24ab05da75fd7 F src/prepare.c 359d1a1e9c9bd4488e4dd3a1aaaf2d2ebb9bb768 -F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b +F src/printf.c aacd7f73018122689dbbe89d85c2e37f737b931f F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68 F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 @@ -224,7 +224,7 @@ F src/shell.c 936a72ff784efff3832cce274a96ed0b036e6758 F src/sqlite.h.in 125dc0b76f0116f1cd6f13536db52ba981e1c5bd F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h f3a5d663fe9c6c0b2ee7fc2e20a6204eaea5bc7c +F src/sqliteInt.h c59b756b3aebefdce24ff44c4a7b3c155a3c26ee F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -293,7 +293,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74 -F src/where.c e6a4e713abe6f995495ea53dd6a5e48f88b53883 +F src/where.c b8f3aab1e5843012895b89a183dcdd6cef0708db F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 2d6dd7c2eb5a64f8994162b564a99ef0014b7460 -R 9b7d54400c77029a626c96270fd35702 +P fbfc075a5a3c9c5c98353f396f9da7f7ec7c1c04 +R b8ab7b74939c13b89c303e9a6e5110d1 U drh -Z a893e863f82f8a1033dbfe922fa06c0b +Z 3687c2e0d19ee741a7e8e3f49ed7da21 diff --git a/manifest.uuid b/manifest.uuid index 7d8b23433a..e6e97065a9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fbfc075a5a3c9c5c98353f396f9da7f7ec7c1c04 \ No newline at end of file +9227ad48e1612b32a3a3e9551c49890f93abc0a7 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4974d57ee5..a03737701e 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7745,7 +7745,7 @@ static void checkAppendMsg( sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); } if( zMsg1 ){ - sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1); + sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1); } sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); va_end(ap); diff --git a/src/build.c b/src/build.c index a7d5a29946..c83ce57cfa 100644 --- a/src/build.c +++ b/src/build.c @@ -3989,9 +3989,9 @@ void sqlite3UniqueConstraint( for(j=0; jnKeyCol; j++){ char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); - sqlite3StrAccumAppend(&errMsg, pTab->zName, -1); + sqlite3StrAccumAppendAll(&errMsg, pTab->zName); sqlite3StrAccumAppend(&errMsg, ".", 1); - sqlite3StrAccumAppend(&errMsg, zCol, -1); + sqlite3StrAccumAppendAll(&errMsg, zCol); } zErr = sqlite3StrAccumFinish(&errMsg); sqlite3HaltConstraint(pParse, diff --git a/src/printf.c b/src/printf.c index f9e5c6406d..011eecdfaa 100644 --- a/src/printf.c +++ b/src/printf.c @@ -148,6 +148,14 @@ void sqlite3AppendSpace(StrAccum *pAccum, int N){ } } +/* +** Set the StrAccum object to an error mode. +*/ +void setStrAccumError(StrAccum *p, u8 eError){ + p->accError = eError; + p->nAlloc = 0; +} + /* ** On machines with a small stack size, you can redefine the ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. @@ -359,7 +367,7 @@ void sqlite3VXPrintf( nOut = precision + 10; zOut = zExtra = sqlite3Malloc( nOut ); if( zOut==0 ){ - pAccum->accError = STRACCUM_NOMEM; + setStrAccumError(pAccum, STRACCUM_NOMEM); return; } } @@ -471,7 +479,7 @@ void sqlite3VXPrintf( if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); if( bufpt==0 ){ - pAccum->accError = STRACCUM_NOMEM; + setStrAccumError(pAccum, STRACCUM_NOMEM); return; } } @@ -606,7 +614,7 @@ void sqlite3VXPrintf( if( n>etBUFSIZE ){ bufpt = zExtra = sqlite3Malloc( n ); if( bufpt==0 ){ - pAccum->accError = STRACCUM_NOMEM; + setStrAccumError(pAccum, STRACCUM_NOMEM); return; } }else{ @@ -641,10 +649,10 @@ void sqlite3VXPrintf( struct SrcList_item *pItem = &pSrc->a[k]; assert( k>=0 && knSrc ); if( pItem->zDatabase ){ - sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1); + sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); sqlite3StrAccumAppend(pAccum, ".", 1); } - sqlite3StrAccumAppend(pAccum, pItem->zName, -1); + sqlite3StrAccumAppendAll(pAccum, pItem->zName); length = width = 0; break; } @@ -684,21 +692,19 @@ void sqlite3VXPrintf( */ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ assert( z!=0 || N==0 ); - if( p->accError ){ - testcase(p->accError==STRACCUM_TOOBIG); - testcase(p->accError==STRACCUM_NOMEM); - return; - } - assert( p->zText!=0 || p->nChar==0 ); - if( N<=0 ){ - if( N==0 || z[0]==0 ) return; - N = sqlite3Strlen30(z); - } + assert( p->zText!=0 || p->nChar==0 || p->accError ); + assert( N>=0 ); + assert( p->accError==0 || p->nAlloc==0 ); if( p->nChar+N >= p->nAlloc ){ char *zNew; + if( p->accError ){ + testcase(p->accError==STRACCUM_TOOBIG); + testcase(p->accError==STRACCUM_NOMEM); + return; + } if( !p->useMalloc ){ - p->accError = STRACCUM_TOOBIG; N = p->nAlloc - p->nChar - 1; + setStrAccumError(p, STRACCUM_TOOBIG); if( N<=0 ){ return; } @@ -708,7 +714,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ szNew += N + 1; if( szNew > p->mxAlloc ){ sqlite3StrAccumReset(p); - p->accError = STRACCUM_TOOBIG; + setStrAccumError(p, STRACCUM_TOOBIG); return; }else{ p->nAlloc = (int)szNew; @@ -722,8 +728,8 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); p->zText = zNew; }else{ - p->accError = STRACCUM_NOMEM; sqlite3StrAccumReset(p); + setStrAccumError(p, STRACCUM_NOMEM); return; } } @@ -733,6 +739,14 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ p->nChar += N; } +/* +** Append the complete text of zero-terminated string z[] to the p string. +*/ +void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ + return sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); +} + + /* ** Finish off a string by making sure it is zero-terminated. ** Return a pointer to the resulting string. Return a NULL @@ -750,7 +764,7 @@ char *sqlite3StrAccumFinish(StrAccum *p){ if( p->zText ){ memcpy(p->zText, p->zBase, p->nChar+1); }else{ - p->accError = STRACCUM_NOMEM; + setStrAccumError(p, STRACCUM_NOMEM); } } } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8bf05a9c8e..1f10c31cb5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3222,6 +3222,7 @@ int sqlite3OpenTempDatabase(Parse *); void sqlite3StrAccumInit(StrAccum*, char*, int, int); void sqlite3StrAccumAppend(StrAccum*,const char*,int); +void sqlite3StrAccumAppendAll(StrAccum*,const char*); void sqlite3AppendSpace(StrAccum*,int); char *sqlite3StrAccumFinish(StrAccum*); void sqlite3StrAccumReset(StrAccum*); diff --git a/src/where.c b/src/where.c index 7d3ec48dac..afe664aa02 100644 --- a/src/where.c +++ b/src/where.c @@ -2568,7 +2568,7 @@ static void explainAppendTerm( const char *zOp /* Name of the operator */ ){ if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5); - sqlite3StrAccumAppend(pStr, zColumn, -1); + sqlite3StrAccumAppendAll(pStr, zColumn); sqlite3StrAccumAppend(pStr, zOp, 1); sqlite3StrAccumAppend(pStr, "?", 1); } @@ -2614,7 +2614,7 @@ static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){ }else{ if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5); sqlite3StrAccumAppend(&txt, "ANY(", 4); - sqlite3StrAccumAppend(&txt, z, -1); + sqlite3StrAccumAppendAll(&txt, z); sqlite3StrAccumAppend(&txt, ")", 1); } } From c65faab2e126c0c6c650420f498adf40589ee602 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Dec 2013 19:25:28 +0000 Subject: [PATCH 2/6] Minor performance optimizations in pager.c. FossilOrigin-Name: ba9eef5f5293633d1479e1d877bf338edb2a9471 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 14 ++++---------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 029bbd9b38..9713b269fb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\soptimizations\sfor\ssqlite3VXPrintf(). -D 2013-12-09T19:03:26.813 +C Minor\sperformance\soptimizations\sin\spager.c. +D 2013-12-09T19:25:28.392 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -207,7 +207,7 @@ F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 60a7b3b23e6fcf83a50d1e320b280b551724e11f F src/os_win.c 4323dd0bac4f7a7037fc4cf87fb4692d17f0b108 -F src/pager.c 061d0b41354a8446256f5d765771e2a026ec8ed2 +F src/pager.c 19203eff37c099271189bf8b378a1143847b92e3 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y acee1a9958539e21263362b194594c5255ad2fca F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P fbfc075a5a3c9c5c98353f396f9da7f7ec7c1c04 -R b8ab7b74939c13b89c303e9a6e5110d1 +P 9227ad48e1612b32a3a3e9551c49890f93abc0a7 +R 2aecb7bab925cdbd0159d9e849c7e955 U drh -Z 3687c2e0d19ee741a7e8e3f49ed7da21 +Z 455daaba8769a2d87fdc74aa6d107f2c diff --git a/manifest.uuid b/manifest.uuid index e6e97065a9..c5695949d4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9227ad48e1612b32a3a3e9551c49890f93abc0a7 \ No newline at end of file +ba9eef5f5293633d1479e1d877bf338edb2a9471 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 7f79bd7eca..8cbb50ce3c 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5643,14 +5643,8 @@ static int pager_write(PgHdr *pPg){ || pPager->eState==PAGER_WRITER_DBMOD ); assert( assert_pager_state(pPager) ); - - /* If an error has been previously detected, report the same error - ** again. This should not happen, but the check provides robustness. */ - if( NEVER(pPager->errCode) ) return pPager->errCode; - - /* Higher-level routines never call this function if database is not - ** writable. But check anyway, just for robustness. */ - if( NEVER(pPager->readOnly) ) return SQLITE_PERM; + assert( pPager->errCode==0 ); + assert( pPager->readOnly==0 ); CHECK_PAGE(pPg); @@ -5779,19 +5773,19 @@ int sqlite3PagerWrite(DbPage *pDbPage){ PgHdr *pPg = pDbPage; Pager *pPager = pPg->pPager; - Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); assert( (pPg->flags & PGHDR_MMAP)==0 ); assert( pPager->eState>=PAGER_WRITER_LOCKED ); assert( pPager->eState!=PAGER_ERROR ); assert( assert_pager_state(pPager) ); - if( nPagePerSector>1 ){ + if( pPager->sectorSize > pPager->pageSize ){ Pgno nPageCount; /* Total number of pages in database file */ Pgno pg1; /* First page of the sector pPg is located on. */ int nPage = 0; /* Number of pages starting at pg1 to journal */ int ii; /* Loop counter */ int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ + Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow ** a journal header to be written between the pages journaled by From 2a8d2261ed2859b08f5423c1d0c3903498f71d9d Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Dec 2013 20:43:22 +0000 Subject: [PATCH 3/6] Simplify the sqlite3BtreeKeyFetch() and sqlite3BtreeDataFetch() interfaces to the storage engine. FossilOrigin-Name: bf97598592ff60fab2a06d8b31b0201200b91684 --- manifest | 12 +++++------ manifest.uuid | 2 +- src/btree.c | 56 +++++++++++---------------------------------------- 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/manifest b/manifest index 9713b269fb..63d41eac58 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sperformance\soptimizations\sin\spager.c. -D 2013-12-09T19:25:28.392 +C Simplify\sthe\ssqlite3BtreeKeyFetch()\sand\ssqlite3BtreeDataFetch()\sinterfaces\nto\sthe\sstorage\sengine. +D 2013-12-09T20:43:22.965 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,7 +166,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 1809a7caa2504233bdddd12f5018422421789537 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 44a44aa21ee24763ddda98d9a41bd85498359ae2 +F src/btree.c 09285d6ffe7d819b9656ea9b7ecf1ab949a926fb F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9 F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0 F src/build.c 47ef8209e56d840d2b35b8a243c6ee567ad52bda @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 9227ad48e1612b32a3a3e9551c49890f93abc0a7 -R 2aecb7bab925cdbd0159d9e849c7e955 +P ba9eef5f5293633d1479e1d877bf338edb2a9471 +R 11cbe9b8d7b59f7bcb32cf4280072bce U drh -Z 455daaba8769a2d87fdc74aa6d107f2c +Z c873c3f777f880d8ffd5cf3f18630860 diff --git a/manifest.uuid b/manifest.uuid index c5695949d4..4b979d210e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ba9eef5f5293633d1479e1d877bf338edb2a9471 \ No newline at end of file +bf97598592ff60fab2a06d8b31b0201200b91684 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a03737701e..da1b91940d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4192,10 +4192,10 @@ int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ /* ** Return a pointer to payload information from the entry that the ** pCur cursor is pointing to. The pointer is to the beginning of -** the key if skipKey==0 and it points to the beginning of data if -** skipKey==1. The number of bytes of available key/data is written -** into *pAmt. If *pAmt==0, then the value returned will not be -** a valid pointer. +** the key if index btrees (pPage->intKey==0) and is the data for +** table btrees (pPage->intKey==1). The number of bytes of available +** key/data is written into *pAmt. If *pAmt==0, then the value +** returned will not be a valid pointer. ** ** This routine is an optimization. It is common for the entire key ** and data to fit on the local page and for there to be no overflow @@ -4208,41 +4208,21 @@ int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ ** page of the database. The data might change or move the next time ** any btree routine is called. */ -static const unsigned char *fetchPayload( +static const void *fetchPayload( BtCursor *pCur, /* Cursor pointing to entry to read from */ - u32 *pAmt, /* Write the number of available bytes here */ - int skipKey /* read beginning at data if this is true */ + u32 *pAmt /* Write the number of available bytes here */ ){ - unsigned char *aPayload; - MemPage *pPage; - u32 nKey; - u32 nLocal; - assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); assert( pCur->eState==CURSOR_VALID ); + assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); assert( cursorHoldsMutex(pCur) ); - pPage = pCur->apPage[pCur->iPage]; - assert( pCur->aiIdx[pCur->iPage]nCell ); + assert( pCur->aiIdx[pCur->iPage]apPage[pCur->iPage]->nCell ); if( pCur->info.nSize==0 ){ btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage], &pCur->info); } - aPayload = pCur->info.pCell; - aPayload += pCur->info.nHeader; - if( pPage->intKey ){ - nKey = 0; - }else{ - nKey = (int)pCur->info.nKey; - } - if( skipKey ){ - aPayload += nKey; - nLocal = pCur->info.nLocal - nKey; - }else{ - nLocal = pCur->info.nLocal; - assert( nLocal<=nKey ); - } - *pAmt = nLocal; - return aPayload; + *pAmt = pCur->info.nLocal; + return (void*)(pCur->info.pCell + pCur->info.nHeader); } @@ -4261,22 +4241,10 @@ static const unsigned char *fetchPayload( ** in the common case where no overflow pages are used. */ const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){ - const void *p = 0; - assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); - assert( cursorHoldsMutex(pCur) ); - if( ALWAYS(pCur->eState==CURSOR_VALID) ){ - p = (const void*)fetchPayload(pCur, pAmt, 0); - } - return p; + return fetchPayload(pCur, pAmt); } const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){ - const void *p = 0; - assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); - assert( cursorHoldsMutex(pCur) ); - if( ALWAYS(pCur->eState==CURSOR_VALID) ){ - p = (const void*)fetchPayload(pCur, pAmt, 1); - } - return p; + return fetchPayload(pCur, pAmt); } From a2a3028d5fd74f5fc4be57ff058cfe8761240c66 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Dec 2013 21:06:46 +0000 Subject: [PATCH 4/6] Reduce the number of times that OP_Column calls sqlite3VdbeMemMakeWriteable(). FossilOrigin-Name: 6b51863553e51334880fb322bdf74e51e35d0e61 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 63d41eac58..60ea04f4fb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\ssqlite3BtreeKeyFetch()\sand\ssqlite3BtreeDataFetch()\sinterfaces\nto\sthe\sstorage\sengine. -D 2013-12-09T20:43:22.965 +C Reduce\sthe\snumber\sof\stimes\sthat\sOP_Column\scalls\ssqlite3VdbeMemMakeWriteable(). +D 2013-12-09T21:06:46.044 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -280,7 +280,7 @@ F src/update.c d1c2477dcf14d90999d1935af4efb4806553250b F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c 76ed0519296e3f62e97e57dab1999e34184c8e49 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 6ccb107de55a34b7676a9eaa0aeb827015723fa4 +F src/vdbe.c 5338567d17c055b26b9b3d280bdd8aa4e8e13d3f F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P ba9eef5f5293633d1479e1d877bf338edb2a9471 -R 11cbe9b8d7b59f7bcb32cf4280072bce +P bf97598592ff60fab2a06d8b31b0201200b91684 +R 30f9bdfbb15779200abce614661249ba U drh -Z c873c3f777f880d8ffd5cf3f18630860 +Z 09a9fc22866f6b8bd3a17a9239808986 diff --git a/manifest.uuid b/manifest.uuid index 4b979d210e..65b1e84f6e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bf97598592ff60fab2a06d8b31b0201200b91684 \ No newline at end of file +6b51863553e51334880fb322bdf74e51e35d0e61 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 5133591e3c..1108a85341 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2496,7 +2496,7 @@ case OP_Column: { pDest->enc = encoding; op_column_out: - rc = sqlite3VdbeMemMakeWriteable(pDest); + Deephemeralize(pDest); op_column_error: UPDATE_MAX_BLOBSIZE(pDest); REGISTER_TRACE(pOp->p3, pDest); From 401387553d0c92b6452b22e4769bdf616c34c7de Mon Sep 17 00:00:00 2001 From: mistachkin Date: Mon, 9 Dec 2013 21:48:49 +0000 Subject: [PATCH 5/6] Correct the VFS name as reported by the file control when explicitly using the 'win32-longpath' VFS. FossilOrigin-Name: c43b59dac1fbb67ec3a9d921005543046ad416ce --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/os_win.c | 2 +- test/win32longpath.test | 16 ++++++++++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 60ea04f4fb..c03216855d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reduce\sthe\snumber\sof\stimes\sthat\sOP_Column\scalls\ssqlite3VdbeMemMakeWriteable(). -D 2013-12-09T21:06:46.044 +C Correct\sthe\sVFS\sname\sas\sreported\sby\sthe\sfile\scontrol\swhen\sexplicitly\susing\sthe\s'win32-longpath'\sVFS. +D 2013-12-09T21:48:49.439 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -206,7 +206,7 @@ F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 60a7b3b23e6fcf83a50d1e320b280b551724e11f -F src/os_win.c 4323dd0bac4f7a7037fc4cf87fb4692d17f0b108 +F src/os_win.c 16eac0961603182ffc10c02b39fe830126538e07 F src/pager.c 19203eff37c099271189bf8b378a1143847b92e3 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y acee1a9958539e21263362b194594c5255ad2fca @@ -1088,7 +1088,7 @@ F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361 -F test/win32longpath.test e2aafc07e6990fe86c69be22a3d1a0e210cd329b +F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d F test/without_rowid1.test aaa26da19d543cd8d3d2d0e686dfa255556c15c8 F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 F test/without_rowid3.test eac3d5c8a1924725b58503a368f2cbd24fd6c8a0 @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P bf97598592ff60fab2a06d8b31b0201200b91684 -R 30f9bdfbb15779200abce614661249ba -U drh -Z 09a9fc22866f6b8bd3a17a9239808986 +P 6b51863553e51334880fb322bdf74e51e35d0e61 +R 02366bc03c0aa38f7c8d01b5c92fd1d6 +U mistachkin +Z d9c38f842954179c02eb8030f4c6e2c4 diff --git a/manifest.uuid b/manifest.uuid index 65b1e84f6e..de251e1a19 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6b51863553e51334880fb322bdf74e51e35d0e61 \ No newline at end of file +c43b59dac1fbb67ec3a9d921005543046ad416ce \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 22052a3fe7..faa60569c9 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -3119,7 +3119,7 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){ return SQLITE_OK; } case SQLITE_FCNTL_VFSNAME: { - *(char**)pArg = sqlite3_mprintf("win32"); + *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); return SQLITE_OK; } diff --git a/test/win32longpath.test b/test/win32longpath.test index 0a6a8f98e6..9e9ed359c6 100644 --- a/test/win32longpath.test +++ b/test/win32longpath.test @@ -19,11 +19,19 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix win32longpath +do_test 1.0 { + file_control_vfsname db +} win32 + db close set path [file nativename [get_pwd]] sqlite3 db [file join $path test.db] -vfs win32-longpath do_test 1.1 { + file_control_vfsname db +} win32-longpath + +do_test 1.2 { db eval { BEGIN EXCLUSIVE; CREATE TABLE t1(x); @@ -47,13 +55,13 @@ make_win32_dir $longPath(3) set fileName $longPath(3)\\test.db -do_test 1.2 { +do_test 1.3 { list [catch {sqlite3 db2 [string range $fileName 4 end]} msg] $msg } {1 {unable to open database file}} sqlite3 db3 $fileName -vfs win32-longpath -do_test 1.3 { +do_test 1.4 { db3 eval { BEGIN EXCLUSIVE; CREATE TABLE t1(x); @@ -71,13 +79,13 @@ db3 close sqlite3 db3 $fileName -vfs win32-longpath -do_test 1.4 { +do_test 1.5 { db3 eval { PRAGMA journal_mode = WAL; } } {wal} -do_test 1.5 { +do_test 1.6 { db3 eval { BEGIN EXCLUSIVE; INSERT INTO t1 VALUES(9); From 038b7bc4efec2bd7bf30c441164b3d422012453d Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 9 Dec 2013 23:17:22 +0000 Subject: [PATCH 6/6] Simplifications to the OP_MakeRecord opcode and the sqlite3VdbeSerialPut() helper function. FossilOrigin-Name: 7277a769694787e0332d1a4efc02041834661e2a --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/vdbe.c | 28 +++++++++++++--------------- src/vdbeInt.h | 2 +- src/vdbeaux.c | 23 ++++------------------- src/vdbemem.c | 2 +- 6 files changed, 30 insertions(+), 47 deletions(-) diff --git a/manifest b/manifest index c03216855d..6901566020 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correct\sthe\sVFS\sname\sas\sreported\sby\sthe\sfile\scontrol\swhen\sexplicitly\susing\sthe\s'win32-longpath'\sVFS. -D 2013-12-09T21:48:49.439 +C Simplifications\sto\sthe\sOP_MakeRecord\sopcode\sand\sthe\ssqlite3VdbeSerialPut()\nhelper\sfunction. +D 2013-12-09T23:17:22.886 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -280,13 +280,13 @@ F src/update.c d1c2477dcf14d90999d1935af4efb4806553250b F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c 76ed0519296e3f62e97e57dab1999e34184c8e49 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 5338567d17c055b26b9b3d280bdd8aa4e8e13d3f +F src/vdbe.c 4bfb1fe75a0ad08646e9b82670691c62699bc5ee F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 -F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263 +F src/vdbeInt.h 7e38eef8f4bd7141e1638b0eacaebf9bc41b26bc F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed -F src/vdbeaux.c 09b79d475f5af2b3b5068f639609d88e0ced9d95 +F src/vdbeaux.c d64bc2a057e77aef3e2a4bc6670b80f516a36d55 F src/vdbeblob.c 8cd05a5630e6d5563ad017bf82edaf812b28acde -F src/vdbemem.c f12d087d92f57fc302028ac1b45374bf8a454d7e +F src/vdbemem.c 2293b66374f4adf54bbdcd662c05a003318600e1 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147 F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 6b51863553e51334880fb322bdf74e51e35d0e61 -R 02366bc03c0aa38f7c8d01b5c92fd1d6 -U mistachkin -Z d9c38f842954179c02eb8030f4c6e2c4 +P c43b59dac1fbb67ec3a9d921005543046ad416ce +R c11616a6774c1e84bdec6602d7be1c45 +U drh +Z 4d30567758bc854237be3d93d5ebeaed diff --git a/manifest.uuid b/manifest.uuid index de251e1a19..fae0da29de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c43b59dac1fbb67ec3a9d921005543046ad416ce \ No newline at end of file +7277a769694787e0332d1a4efc02041834661e2a \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 1108a85341..a0a69e8a5c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2599,29 +2599,27 @@ case OP_MakeRecord: { ** out how much space is required for the new record. */ assert( pData0<=pLast ); - pRec = pData0; + pRec = pLast; do{ assert( memIsValid(pRec) ); if( zAffinity ){ applyAffinity(pRec, zAffinity[pRec-pData0], encoding); } - if( (pRec->flags&MEM_Zero)!=0 && pRec->n>0 ){ - sqlite3VdbeMemExpandBlob(pRec); - } serial_type = sqlite3VdbeSerialType(pRec, file_format); len = sqlite3VdbeSerialTypeLen(serial_type); + if( pRec->flags & MEM_Zero ){ + if( nData ){ + sqlite3VdbeMemExpandBlob(pRec); + }else{ + nZero += pRec->u.nZero; + len -= pRec->u.nZero; + } + } nData += len; testcase( serial_type==127 ); testcase( serial_type==128 ); nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); - if( pRec->flags & MEM_Zero ){ - /* Only pure zero-filled BLOBs can be input to this Opcode. - ** We do not allow blobs with a prefix and a zero-filled tail. */ - nZero += pRec->u.nZero; - }else if( len ){ - nZero = 0; - } - }while( (++pRec)<=pLast ); + }while( (--pRec)>=pData0 ); /* Add the initial header varint and total the size */ testcase( nHdr==126 ); @@ -2635,7 +2633,7 @@ case OP_MakeRecord: { nHdr += nVarint; if( nVarintdb->aLimit[SQLITE_LIMIT_LENGTH] ){ goto too_big; } @@ -2657,8 +2655,8 @@ case OP_MakeRecord: { pRec = pData0; do{ serial_type = sqlite3VdbeSerialType(pRec, file_format); - i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ - j += sqlite3VdbeSerialPut(&zNewRecord[j], (int)(nByte-j), pRec,file_format); + i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ + j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, file_format); /* content */ }while( (++pRec)<=pLast ); assert( i==nHdr ); assert( j==nByte ); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 371c4d6dc1..b01af20188 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -389,7 +389,7 @@ void sqlite3VdbePrintOp(FILE*, int, Op*); #endif u32 sqlite3VdbeSerialTypeLen(u32); u32 sqlite3VdbeSerialType(Mem*, int); -u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int); +u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, int); u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 5b5d82aed8..c610de4562 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -2827,20 +2827,15 @@ static u64 floatSwap(u64 in){ ** buf. It is assumed that the caller has allocated sufficient space. ** Return the number of bytes written. ** -** nBuf is the amount of space left in buf[]. nBuf must always be -** large enough to hold the entire field. Except, if the field is -** a blob with a zero-filled tail, then buf[] might be just the right -** size to hold everything except for the zero-filled tail. If buf[] -** is only big enough to hold the non-zero prefix, then only write that -** prefix into buf[]. But if buf[] is large enough to hold both the -** prefix and the tail then write the prefix and set the tail to all -** zeros. +** nBuf is the amount of space left in buf[]. The caller is responsible +** for allocating enough space to buf[] to hold the entire field, exclusive +** of the pMem->u.nZero bytes for a MEM_Zero value. ** ** Return the number of bytes actually written into buf[]. The number ** of bytes in the zero-filled tail is included in the return value only ** if those bytes were zeroed in buf[]. */ -u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){ +u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, int file_format){ u32 serial_type = sqlite3VdbeSerialType(pMem, file_format); u32 len; @@ -2856,7 +2851,6 @@ u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){ v = pMem->u.i; } len = i = sqlite3VdbeSerialTypeLen(serial_type); - assert( len<=(u32)nBuf ); while( i-- ){ buf[i] = (u8)(v&0xFF); v >>= 8; @@ -2868,17 +2862,8 @@ u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){ if( serial_type>=12 ){ assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) == (int)sqlite3VdbeSerialTypeLen(serial_type) ); - assert( pMem->n<=nBuf ); len = pMem->n; memcpy(buf, pMem->z, len); - if( pMem->flags & MEM_Zero ){ - len += pMem->u.nZero; - assert( nBuf>=0 ); - if( len > (u32)nBuf ){ - len = (u32)nBuf; - } - memset(&buf[pMem->n], 0, len-pMem->n); - } return len; } diff --git a/src/vdbemem.c b/src/vdbemem.c index 8a3acd5308..451744291f 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1221,7 +1221,7 @@ static void recordFunc( }else{ aRet[0] = nSerial+1; sqlite3PutVarint(&aRet[1], iSerial); - sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format); + sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], file_format); sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); sqlite3DbFree(db, aRet); }