From f54a80fe5c4afa61f17ec3380a4201b1fda630d7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 29 Jan 2021 13:47:36 +0000 Subject: [PATCH] Performance optimization (and size reduction) in sqlite3TriggerList() for the common case where there are no TEMP triggers. FossilOrigin-Name: 0defaf730bdc82212a5d3feeb2e16f16423b1691b0aaa7da1787eb82ea39ae9e --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/trigger.c | 22 +++++++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index df58f37956..7045fd7798 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sissue\swith\sIN\soperator\soptimization\sintroduced\sby\ncheck-in\s[4a43430fd23f8835]\sand\sdescribed\sby\sticket\s[ee51301f316c09e9]. -D 2021-01-27T19:15:06.983 +C Performance\soptimization\s(and\ssize\sreduction)\sin\ssqlite3TriggerList()\sfor\sthe\ncommon\scase\swhere\sthere\sare\sno\sTEMP\striggers. +D 2021-01-29T13:47:36.426 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -607,7 +607,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c c64c49d7c2ec4490c2fef1f24350167ba16b03b0c6cee58ad1a1d70a4325d4e9 F src/treeview.c 4b92992176fb2caefbe06ba5bd06e0e0ebcde3d5564758da672631f17aa51cda -F src/trigger.c 29680c54c1aa088fa1b4d50137d75669a40d5ef814394e321fab1e547868e3d3 +F src/trigger.c 731ea5ed6b308574b7dc2a5d2a9187ef5510a3692cc1ea06a34608a084b8f376 F src/update.c 9f126204a6acb96bbe47391ae48e0fc579105d8e76a6d9c4fab3271367476580 F src/upsert.c df8f1727d62b5987c4fd302cd4d7c0c84ae57cd65683c5a34a740dfe24039235 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 @@ -1898,8 +1898,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 0571c24177d77ac966bcf42cb8ab00fdf541ce84af1468c8ef0b60c48c45a22f 390cf60a286b13f454429f4652a133f95a7891a75c1ec6d16cd39990590fd3fb -R 4574041b82ab28e377188abbe28af4d5 -T +closed 390cf60a286b13f454429f4652a133f95a7891a75c1ec6d16cd39990590fd3fb +P 9dc7fc9f04d5c14fc436e5ff5b4c06c1969ddde5857ebeb5dccd59b7c748c339 +R 0b7a0544b0d15fb4a458f0ab87fbb410 U drh -Z 071fbdee3969843efb30cf74f43578ee +Z 6a477571c6e856bdd183f551e55df63b diff --git a/manifest.uuid b/manifest.uuid index 29b10f4d3b..6f87f82bcf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9dc7fc9f04d5c14fc436e5ff5b4c06c1969ddde5857ebeb5dccd59b7c748c339 \ No newline at end of file +0defaf730bdc82212a5d3feeb2e16f16423b1691b0aaa7da1787eb82ea39ae9e \ No newline at end of file diff --git a/src/trigger.c b/src/trigger.c index 0c8cf5334f..a9378fd3a3 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -48,28 +48,32 @@ void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){ ** pTab as well as the triggers lised in pTab->pTrigger. */ Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){ - Schema * const pTmpSchema = pParse->db->aDb[1].pSchema; - Trigger *pList = 0; /* List of triggers to return */ + Schema *pTmpSchema; /* Schema of the pTab table */ + Trigger *pList; /* List of triggers to return */ + HashElem *p; /* Loop variable for TEMP triggers */ if( pParse->disableTriggers ){ return 0; } - + pTmpSchema = pParse->db->aDb[1].pSchema; + p = sqliteHashFirst(&pTmpSchema->trigHash); + if( p==0 ){ + return pTab->pTrigger; + } + pList = pTab->pTrigger; if( pTmpSchema!=pTab->pSchema ){ - HashElem *p; - assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) ); - for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){ + while( p ){ Trigger *pTrig = (Trigger *)sqliteHashData(p); if( pTrig->pTabSchema==pTab->pSchema && 0==sqlite3StrICmp(pTrig->table, pTab->zName) ){ - pTrig->pNext = (pList ? pList : pTab->pTrigger); + pTrig->pNext = pList; pList = pTrig; } + p = sqliteHashNext(p); } } - - return (pList ? pList : pTab->pTrigger); + return pList; } /*