From a03be7987bf314f88be2a6ba1a8d4a82e1fb542b Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 17 May 2023 19:23:24 +0000 Subject: [PATCH] Fast-path the btree transaction start for the common case where a transaction is already active. FossilOrigin-Name: 798c3ff20c606b5f9fde16dc67781f238370a7c450bc239c3a98d0f4ca370399 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 28 +++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 8559206bb7..3560420998 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplification,\sperformance\simprovement,\sand\ssize\sreduction\sin\sthe\ncodeAllEqualityTerms()\sfunction\sof\sthe\scode\sgenerator. -D 2023-05-17T16:13:48.064 +C Fast-path\sthe\sbtree\stransaction\sstart\sfor\sthe\scommon\scase\swhere\sa\ntransaction\sis\salready\sactive. +D 2023-05-17T19:23:24.667 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -575,7 +575,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca -F src/btree.c ecaaf8d57cd8b5f4e3167bd59cf61cef031b4b2ee606e6afa11b96a60a14f9ef +F src/btree.c ecfb015125daff2fe69cc663c9a07f3c43259cbf0fbdf13f3305f88f14a4a262 F src/btree.h aa354b9bad4120af71e214666b35132712b8f2ec11869cb2315c52c81fad45cc F src/btreeInt.h b900603c8956bdeb313841f9b67bdeceef32c64d962d35477c07ec25e8cf0f9b F src/build.c 5512d5a335334b48d116f1ecd051edef96a60add18ae48e0ea302a395f00f3d9 @@ -2070,8 +2070,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6084c5fb6d3fcedf35cd6c597a44ec7bf8b4a2576c7b277e5342d2a7905318e7 -R 6485d1d144054894bb806b033900eb87 +P 4fbe02651e877e442d62308d7f607e503695104cd71c5565132fcd1398c120df +R 1d4ea27d6db6a9e62f6f4b03683e08b9 U drh -Z 8a0864d2f033378cf6e10cbbd0a26acb +Z c7ab7659bb2e2f13db3dbd0d4bde5a0c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ebc3507eb4..d418224d53 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4fbe02651e877e442d62308d7f607e503695104cd71c5565132fcd1398c120df \ No newline at end of file +798c3ff20c606b5f9fde16dc67781f238370a7c450bc239c3a98d0f4ca370399 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 87bc0058bb..c32fc79439 100644 --- a/src/btree.c +++ b/src/btree.c @@ -3555,7 +3555,11 @@ int sqlite3BtreeNewDb(Btree *p){ ** when A already has a read lock, we encourage A to give up and let B ** proceed. */ -int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ +static SQLITE_NOINLINE int btreeBeginTrans( + Btree *p, /* The btree in which to start the transactino */ + int wrflag, /* True to start a write transaction */ + int *pSchemaVersion /* Put schema version number here, if not NULL */ +){ BtShared *pBt = p->pBt; Pager *pPager = pBt->pPager; int rc = SQLITE_OK; @@ -3727,6 +3731,28 @@ trans_begun: sqlite3BtreeLeave(p); return rc; } +int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ + BtShared *pBt; + if( p->sharable + || p->inTrans==TRANS_NONE + || (p->inTrans==TRANS_READ && wrflag!=0) + ){ + return btreeBeginTrans(p,wrflag,pSchemaVersion); + } + pBt = p->pBt; + if( pSchemaVersion ){ + *pSchemaVersion = get4byte(&pBt->pPage1->aData[40]); + } + if( wrflag ){ + /* This call makes sure that the pager has the correct number of + ** open savepoints. If the second parameter is greater than 0 and + ** the sub-journal is not already open, then it will be opened here. + */ + return sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint); + }else{ + return SQLITE_OK; + } +} #ifndef SQLITE_OMIT_AUTOVACUUM