Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0755dc

Browse files
committed
Avoid searching for callback functions in CallSyscacheCallbacks().
We have now grown enough registerable syscache-invalidation callbackfunctions that the original assumption that there would be few of themis causing performance problems. In particular, let's fix things so thatCallSyscacheCallbacks doesn't have to search the whole array to findwhich callback(s) to invoke for a given cache ID. Preserve the originalbehavior that callbacks are called in order of registration, just incase there's someplace that depends on that (which I doubt).In support of this, export the number of syscaches from syscache.h.People could have found that out anyway from the enum, but adding a#define makes that much safer.This provides a useful additional speedup in Mathieu Fenniak'slogical-decoding test case, although we're reaching the point ofdiminishing returns there. I think any further improvement will haveto come from reducing the number of cache invalidations that aretriggered in the first place. Still, we can hope that this changegives some incremental benefit for all invalidation scenarios.Back-patch to 9.4 where logical decoding was introduced.Discussion:https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com
1 parent610926e commitd0755dc

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

‎src/backend/utils/cache/inval.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ static intmaxSharedInvalidMessagesArray;
175175

176176
/*
177177
* Dynamically-registered callback functions. Current implementation
178-
* assumes there won't be very many of these at once; could improve if needed.
178+
* assumes there won't be enough of these to justify a dynamically resizable
179+
* array; it'd be easy to improve that if needed.
180+
*
181+
* To avoid searching in CallSyscacheCallbacks, all callbacks for a given
182+
* syscache are linked into a list pointed to by syscache_callback_links[id].
183+
* The link values are syscache_callback_list[] index plus 1, or 0 for none.
179184
*/
180185

181186
#defineMAX_SYSCACHE_CALLBACKS 64
@@ -184,10 +189,13 @@ static intmaxSharedInvalidMessagesArray;
184189
staticstructSYSCACHECALLBACK
185190
{
186191
int16id;/* cache number */
192+
int16link;/* next callback index+1 for same cache */
187193
SyscacheCallbackFunctionfunction;
188194
Datumarg;
189195
}syscache_callback_list[MAX_SYSCACHE_CALLBACKS];
190196

197+
staticint16syscache_callback_links[SysCacheSize];
198+
191199
staticintsyscache_callback_count=0;
192200

193201
staticstructRELCACHECALLBACK
@@ -1355,10 +1363,28 @@ CacheRegisterSyscacheCallback(int cacheid,
13551363
SyscacheCallbackFunctionfunc,
13561364
Datumarg)
13571365
{
1366+
if (cacheid<0||cacheid >=SysCacheSize)
1367+
elog(FATAL,"invalid cache ID: %d",cacheid);
13581368
if (syscache_callback_count >=MAX_SYSCACHE_CALLBACKS)
13591369
elog(FATAL,"out of syscache_callback_list slots");
13601370

1371+
if (syscache_callback_links[cacheid]==0)
1372+
{
1373+
/* first callback for this cache */
1374+
syscache_callback_links[cacheid]=syscache_callback_count+1;
1375+
}
1376+
else
1377+
{
1378+
/* add to end of chain, so that older callbacks are called first */
1379+
inti=syscache_callback_links[cacheid]-1;
1380+
1381+
while (syscache_callback_list[i].link>0)
1382+
i=syscache_callback_list[i].link-1;
1383+
syscache_callback_list[i].link=syscache_callback_count+1;
1384+
}
1385+
13611386
syscache_callback_list[syscache_callback_count].id=cacheid;
1387+
syscache_callback_list[syscache_callback_count].link=0;
13621388
syscache_callback_list[syscache_callback_count].function=func;
13631389
syscache_callback_list[syscache_callback_count].arg=arg;
13641390

@@ -1398,11 +1424,16 @@ CallSyscacheCallbacks(int cacheid, uint32 hashvalue)
13981424
{
13991425
inti;
14001426

1401-
for (i=0;i<syscache_callback_count;i++)
1427+
if (cacheid<0||cacheid >=SysCacheSize)
1428+
elog(ERROR,"invalid cache ID: %d",cacheid);
1429+
1430+
i=syscache_callback_links[cacheid]-1;
1431+
while (i >=0)
14021432
{
14031433
structSYSCACHECALLBACK*ccitem=syscache_callback_list+i;
14041434

1405-
if (ccitem->id==cacheid)
1406-
(*ccitem->function) (ccitem->arg,cacheid,hashvalue);
1435+
Assert(ccitem->id==cacheid);
1436+
(*ccitem->function) (ccitem->arg,cacheid,hashvalue);
1437+
i=ccitem->link-1;
14071438
}
14081439
}

‎src/backend/utils/cache/syscache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,6 @@ static const struct cachedesc cacheinfo[] = {
845845
}
846846
};
847847

848-
#defineSysCacheSize((int) lengthof(cacheinfo))
849-
850848
staticCatCache*SysCache[SysCacheSize];
851849

852850
staticboolCacheInitialized= false;
@@ -877,6 +875,9 @@ InitCatalogCache(void)
877875
inti,
878876
j;
879877

878+
StaticAssertStmt(SysCacheSize== (int)lengthof(cacheinfo),
879+
"SysCacheSize does not match syscache.c's array");
880+
880881
Assert(!CacheInitialized);
881882

882883
SysCacheRelationOidSize=SysCacheSupportingRelOidSize=0;

‎src/include/utils/syscache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ enum SysCacheIdentifier
9797
TYPEOID,
9898
USERMAPPINGOID,
9999
USERMAPPINGUSERSERVER
100+
101+
#defineSysCacheSize (USERMAPPINGUSERSERVER+1)
100102
};
101103

102104
externvoidInitCatalogCache(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp