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

Commit03ffc4d

Browse files
committed
Improve test coverage of CLOBBER_CACHE_ALWAYS by having it also force
reloading of operator class information on each use of LookupOpclassInfo.Had this been in place a year ago, it would have helped me find a bugin the then-new 'operator family' code. Now that we have a build farmmember testing CLOBBER_CACHE_ALWAYS on a regular basis, it seems worthexpending a little bit of effort here.
1 parent62312ce commit03ffc4d

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

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

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.264 2007/11/15 21:14:40 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.265 2007/11/28 20:44:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1133,9 +1133,13 @@ IndexSupportInitialize(oidvector *indclass,
11331133
* numbers is passed in, rather than being looked up, mainly because the
11341134
* caller will have it already.
11351135
*
1136-
* XXX There isn't any provision for flushing the cache. However, there
1137-
* isn't any provision for flushing relcache entries when opclass info
1138-
* changes, either :-(
1136+
* Note there is no provision for flushing the cache. This is OK at the
1137+
* moment because there is no way to ALTER any interesting properties of an
1138+
* existing opclass --- all you can do is drop it, which will result in
1139+
* a useless but harmless dead entry in the cache. To support altering
1140+
* opclass membership (not the same as opfamily membership!), we'd need to
1141+
* be able to flush this cache as well as the contents of relcache entries
1142+
* for indexes.
11391143
*/
11401144
staticOpClassCacheEnt*
11411145
LookupOpclassInfo(OidoperatorClassOid,
@@ -1170,34 +1174,50 @@ LookupOpclassInfo(Oid operatorClassOid,
11701174
(void*)&operatorClassOid,
11711175
HASH_ENTER,&found);
11721176

1173-
if (found&&opcentry->valid)
1177+
if (!found)
1178+
{
1179+
/* Need to allocate memory for new entry */
1180+
opcentry->valid= false;/* until known OK */
1181+
opcentry->numStrats=numStrats;
1182+
opcentry->numSupport=numSupport;
1183+
1184+
if (numStrats>0)
1185+
opcentry->operatorOids= (Oid*)
1186+
MemoryContextAllocZero(CacheMemoryContext,
1187+
numStrats*sizeof(Oid));
1188+
else
1189+
opcentry->operatorOids=NULL;
1190+
1191+
if (numSupport>0)
1192+
opcentry->supportProcs= (RegProcedure*)
1193+
MemoryContextAllocZero(CacheMemoryContext,
1194+
numSupport*sizeof(RegProcedure));
1195+
else
1196+
opcentry->supportProcs=NULL;
1197+
}
1198+
else
11741199
{
1175-
/* Already made an entry for it */
11761200
Assert(numStrats==opcentry->numStrats);
11771201
Assert(numSupport==opcentry->numSupport);
1178-
returnopcentry;
11791202
}
11801203

1181-
/* Need to fill in new entry */
1182-
opcentry->valid= false;/* until known OK */
1183-
opcentry->numStrats=numStrats;
1184-
opcentry->numSupport=numSupport;
1185-
1186-
if (numStrats>0)
1187-
opcentry->operatorOids= (Oid*)
1188-
MemoryContextAllocZero(CacheMemoryContext,
1189-
numStrats*sizeof(Oid));
1190-
else
1191-
opcentry->operatorOids=NULL;
1204+
/*
1205+
* When testing for cache-flush hazards, we intentionally disable the
1206+
* operator class cache and force reloading of the info on each call.
1207+
* This is helpful because we want to test the case where a cache flush
1208+
* occurs while we are loading the info, and it's very hard to provoke
1209+
* that if this happens only once per opclass per backend.
1210+
*/
1211+
#if defined(CLOBBER_CACHE_ALWAYS)
1212+
opcentry->valid= false;
1213+
#endif
11921214

1193-
if (numSupport>0)
1194-
opcentry->supportProcs= (RegProcedure*)
1195-
MemoryContextAllocZero(CacheMemoryContext,
1196-
numSupport*sizeof(RegProcedure));
1197-
else
1198-
opcentry->supportProcs=NULL;
1215+
if (opcentry->valid)
1216+
returnopcentry;
11991217

12001218
/*
1219+
* Need to fill in new entry.
1220+
*
12011221
* To avoid infinite recursion during startup, force heap scans if we're
12021222
* looking up info for the opclasses used by the indexes we would like to
12031223
* reference here.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp