From: drh Date: Fri, 25 Oct 2019 14:46:05 +0000 (+0000) Subject: Performance optimization in sqlite3BtreeCursor(). X-Git-Tag: version-3.31.0~384 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db561bcedaa38da1c4ac5097d6cab9e9567b1f1d;p=thirdparty%2Fsqlite.git Performance optimization in sqlite3BtreeCursor(). FossilOrigin-Name: ea068b099c96b8b9526114732d2a6be186cf381b7329d102778ad25b95510c9e --- diff --git a/manifest b/manifest index f9593b107f..ca33b71ebd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sfts5,\sfix\sa\scase\sof\soverreading\sa\sbuffer\sby\s1\sbyte\swhen\scounting\scharacters\sin\smalformed\sutf-8.\sFix\sfor\s[dd1f67bf]. -D 2019-10-24T20:35:27.749 +C Performance\soptimization\sin\ssqlite3BtreeCursor(). +D 2019-10-25T14:46:05.015 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -467,7 +467,7 @@ F src/auth.c a3d5bfdba83d25abed1013a8c7a5f204e2e29b0c25242a56bc02bb0c07bf1e06 F src/backup.c f70077d40c08b7787bfe934e4d1da8030cb0cc57d46b345fba2294b7d1be23ab F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c a8a9c2ce62bdf54c8cf9795143d7cb10b7473a1230a0572f702d061ffcceefe5 +F src/btree.c 12e251f8c3eaad05e6d0db94772bf779b3a644e18d884025da6bcbc98cad1d22 F src/btree.h f27a33c49280209a93385e218306c4ee5f46ba8d7649d2f81a7166b282232484 F src/btreeInt.h 91806f01fd1145a9a86ba3042f25c38d8faf6002701bf5e780742cf88bcff437 F src/build.c 0e558ef847ccc4b6aa38dee44cde9d9df46e953b0a66e4fa4376265824955fe3 @@ -1848,7 +1848,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 521f1d36282549488a47a434484a24924ee970d29f05a8ae499b7d536bcd692b -R 0e068e9d9a1f90654b1d1392ec7133b9 -U dan -Z de4cd0a7404bbb9013415658a762354d +P 8d964e1c21d4cea699023e02b0616a75c5859dd083c9365cdcbc0676ebbdaae4 +R 8536c2fabd9f7098038221269ecc3472 +U drh +Z ac1675b2b1cf8ed8d7717d3ccad9b463 diff --git a/manifest.uuid b/manifest.uuid index 05a16eff55..9f2d452b24 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d964e1c21d4cea699023e02b0616a75c5859dd083c9365cdcbc0676ebbdaae4 \ No newline at end of file +ea068b099c96b8b9526114732d2a6be186cf381b7329d102778ad25b95510c9e \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 2150638aee..b4c787edbf 100644 --- a/src/btree.c +++ b/src/btree.c @@ -4379,9 +4379,13 @@ static int btreeCursor( allocateTempSpace(pBt); if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT; } - if( iTable==1 && btreePagecount(pBt)==0 ){ - assert( wrFlag==0 ); - iTable = 0; + if( iTable<=1 ){ + if( iTable<1 ){ + return SQLITE_CORRUPT_BKPT; + }else if( btreePagecount(pBt)==0 ){ + assert( wrFlag==0 ); + iTable = 0; + } } /* Now that no other errors can occur, finish filling in the BtCursor @@ -4406,6 +4410,19 @@ static int btreeCursor( pCur->eState = CURSOR_INVALID; return SQLITE_OK; } +static int btreeCursorWithLock( + Btree *p, /* The btree */ + int iTable, /* Root page of table to open */ + int wrFlag, /* 1 to write. 0 read-only */ + struct KeyInfo *pKeyInfo, /* First arg to comparison function */ + BtCursor *pCur /* Space for new cursor */ +){ + int rc; + sqlite3BtreeEnter(p); + rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur); + sqlite3BtreeLeave(p); + return rc; +} int sqlite3BtreeCursor( Btree *p, /* The btree */ int iTable, /* Root page of table to open */ @@ -4413,15 +4430,11 @@ int sqlite3BtreeCursor( struct KeyInfo *pKeyInfo, /* First arg to xCompare() */ BtCursor *pCur /* Write new cursor here */ ){ - int rc; - if( iTable<1 ){ - rc = SQLITE_CORRUPT_BKPT; + if( p->sharable ){ + return btreeCursorWithLock(p, iTable, wrFlag, pKeyInfo, pCur); }else{ - sqlite3BtreeEnter(p); - rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur); - sqlite3BtreeLeave(p); + return btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur); } - return rc; } /*