|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -1133,9 +1133,13 @@ IndexSupportInitialize(oidvector *indclass,
|
1133 | 1133 | * numbers is passed in, rather than being looked up, mainly because the
|
1134 | 1134 | * caller will have it already.
|
1135 | 1135 | *
|
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. |
1139 | 1143 | */
|
1140 | 1144 | staticOpClassCacheEnt*
|
1141 | 1145 | LookupOpclassInfo(OidoperatorClassOid,
|
@@ -1170,34 +1174,50 @@ LookupOpclassInfo(Oid operatorClassOid,
|
1170 | 1174 | (void*)&operatorClassOid,
|
1171 | 1175 | HASH_ENTER,&found);
|
1172 | 1176 |
|
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 |
1174 | 1199 | {
|
1175 |
| -/* Already made an entry for it */ |
1176 | 1200 | Assert(numStrats==opcentry->numStrats);
|
1177 | 1201 | Assert(numSupport==opcentry->numSupport);
|
1178 |
| -returnopcentry; |
1179 | 1202 | }
|
1180 | 1203 |
|
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 |
1192 | 1214 |
|
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; |
1199 | 1217 |
|
1200 | 1218 | /*
|
| 1219 | + * Need to fill in new entry. |
| 1220 | + * |
1201 | 1221 | * To avoid infinite recursion during startup, force heap scans if we're
|
1202 | 1222 | * looking up info for the opclasses used by the indexes we would like to
|
1203 | 1223 | * reference here.
|
|