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

Commit2df5d46

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 parent9ed74fd commit2df5d46

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
@@ -177,7 +177,12 @@ static intmaxSharedInvalidMessagesArray;
177177

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

183188
#defineMAX_SYSCACHE_CALLBACKS 64
@@ -186,10 +191,13 @@ static intmaxSharedInvalidMessagesArray;
186191
staticstructSYSCACHECALLBACK
187192
{
188193
int16id;/* cache number */
194+
int16link;/* next callback index+1 for same cache */
189195
SyscacheCallbackFunctionfunction;
190196
Datumarg;
191197
}syscache_callback_list[MAX_SYSCACHE_CALLBACKS];
192198

199+
staticint16syscache_callback_links[SysCacheSize];
200+
193201
staticintsyscache_callback_count=0;
194202

195203
staticstructRELCACHECALLBACK
@@ -1383,10 +1391,28 @@ CacheRegisterSyscacheCallback(int cacheid,
13831391
SyscacheCallbackFunctionfunc,
13841392
Datumarg)
13851393
{
1394+
if (cacheid<0||cacheid >=SysCacheSize)
1395+
elog(FATAL,"invalid cache ID: %d",cacheid);
13861396
if (syscache_callback_count >=MAX_SYSCACHE_CALLBACKS)
13871397
elog(FATAL,"out of syscache_callback_list slots");
13881398

1399+
if (syscache_callback_links[cacheid]==0)
1400+
{
1401+
/* first callback for this cache */
1402+
syscache_callback_links[cacheid]=syscache_callback_count+1;
1403+
}
1404+
else
1405+
{
1406+
/* add to end of chain, so that older callbacks are called first */
1407+
inti=syscache_callback_links[cacheid]-1;
1408+
1409+
while (syscache_callback_list[i].link>0)
1410+
i=syscache_callback_list[i].link-1;
1411+
syscache_callback_list[i].link=syscache_callback_count+1;
1412+
}
1413+
13891414
syscache_callback_list[syscache_callback_count].id=cacheid;
1415+
syscache_callback_list[syscache_callback_count].link=0;
13901416
syscache_callback_list[syscache_callback_count].function=func;
13911417
syscache_callback_list[syscache_callback_count].arg=arg;
13921418

@@ -1426,11 +1452,16 @@ CallSyscacheCallbacks(int cacheid, uint32 hashvalue)
14261452
{
14271453
inti;
14281454

1429-
for (i=0;i<syscache_callback_count;i++)
1455+
if (cacheid<0||cacheid >=SysCacheSize)
1456+
elog(ERROR,"invalid cache ID: %d",cacheid);
1457+
1458+
i=syscache_callback_links[cacheid]-1;
1459+
while (i >=0)
14301460
{
14311461
structSYSCACHECALLBACK*ccitem=syscache_callback_list+i;
14321462

1433-
if (ccitem->id==cacheid)
1434-
(*ccitem->function) (ccitem->arg,cacheid,hashvalue);
1463+
Assert(ccitem->id==cacheid);
1464+
(*ccitem->function) (ccitem->arg,cacheid,hashvalue);
1465+
i=ccitem->link-1;
14351466
}
14361467
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,6 @@ static const struct cachedesc cacheinfo[] = {
971971
}
972972
};
973973

974-
#defineSysCacheSize((int) lengthof(cacheinfo))
975-
976974
staticCatCache*SysCache[SysCacheSize];
977975

978976
staticboolCacheInitialized= false;
@@ -1003,6 +1001,9 @@ InitCatalogCache(void)
10031001
inti,
10041002
j;
10051003

1004+
StaticAssertStmt(SysCacheSize== (int)lengthof(cacheinfo),
1005+
"SysCacheSize does not match syscache.c's array");
1006+
10061007
Assert(!CacheInitialized);
10071008

10081009
SysCacheRelationOidSize=SysCacheSupportingRelOidSize=0;

‎src/include/utils/syscache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ enum SysCacheIdentifier
108108
TYPEOID,
109109
USERMAPPINGOID,
110110
USERMAPPINGUSERSERVER
111+
112+
#defineSysCacheSize (USERMAPPINGUSERSERVER+1)
111113
};
112114

113115
externvoidInitCatalogCache(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp