77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.29 1999/11/17 23:51:21 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.30 1999/11/21 01:58:22 tgl Exp $
1111 *
1212 * Note - this code is real crufty...
1313 *
1818#include "catalog/catalog.h"
1919#include "catalog/catname.h"
2020#include "catalog/heap.h"
21+ #include "catalog/pg_class.h"
2122#include "miscadmin.h"
2223#include "storage/sinval.h"
2324#include "utils/catcache.h"
2425#include "utils/inval.h"
2526#include "utils/relcache.h"
2627
27- static InvalidationEntry InvalidationEntryAllocate (uint16 size );
28- static void LocalInvalidInvalidate (LocalInvalid invalid ,void (* function ) ());
29- static LocalInvalid LocalInvalidRegister (LocalInvalid invalid ,
30- InvalidationEntry entry );
31- static void getmyrelids (void );
32-
3328
3429/* ----------------
3530 *private invalidation structures
3631 * ----------------
3732 */
33+
34+ typedef struct InvalidationUserData
35+ {
36+ struct InvalidationUserData * dataP [1 ];/* VARIABLE LENGTH */
37+ }InvalidationUserData ;/* VARIABLE LENGTH STRUCTURE */
38+
39+ typedef struct InvalidationEntryData
40+ {
41+ InvalidationUserData * nextP ;
42+ InvalidationUserData userData ;/* VARIABLE LENGTH ARRAY */
43+ }InvalidationEntryData ;/* VARIABLE LENGTH STRUCTURE */
44+
45+ typedef Pointer InvalidationEntry ;
46+
47+ typedef InvalidationEntry LocalInvalid ;
48+
49+ #define EmptyLocalInvalid NULL
50+
3851typedef struct CatalogInvalidationData
3952{
4053Index cacheId ;
@@ -66,15 +79,14 @@ typedef InvalidationMessageData *InvalidationMessage;
6679 *variables and macros
6780 * ----------------
6881 */
69- static LocalInvalid Invalid = EmptyLocalInvalid ;/*XXX global */
82+ static LocalInvalid Invalid = EmptyLocalInvalid ;/*head of linked list */
7083
71- Oid MyRelationRelationId = InvalidOid ;
72- Oid MyAttributeRelationId = InvalidOid ;
73- Oid MyAMRelationId = InvalidOid ;
74- Oid MyAMOPRelationId = InvalidOid ;
7584
76- #define ValidateHacks () \
77- if (!OidIsValid(MyRelationRelationId)) getmyrelids()
85+ static InvalidationEntry InvalidationEntryAllocate (uint16 size );
86+ static void LocalInvalidInvalidate (LocalInvalid invalid ,void (* function ) ());
87+ static LocalInvalid LocalInvalidRegister (LocalInvalid invalid ,
88+ InvalidationEntry entry );
89+
7890
7991/* ----------------------------------------------------------------
8092 *"local" invalidation support functions
@@ -99,7 +111,8 @@ InvalidationEntryAllocate(uint16 size)
99111
100112/* --------------------------------
101113 *LocalInvalidRegister
102- * Returns a new local cache invalidation state containing a new entry.
114+ * Link an invalidation entry into a chain of them. Really ugly
115+ * coding here.
103116 * --------------------------------
104117 */
105118static LocalInvalid
@@ -117,7 +130,7 @@ LocalInvalidRegister(LocalInvalid invalid,
117130/* --------------------------------
118131 *LocalInvalidInvalidate
119132 *Processes, then frees all entries in a local cache
120- *invalidationstate .
133+ *invalidationlist .
121134 * --------------------------------
122135 */
123136static void
@@ -187,7 +200,7 @@ CacheIdRegisterLocalInvalid(Index cacheId,
187200ItemPointerCopy (pointer ,& message -> any .catalog .pointerData );
188201
189202/* ----------------
190- *Note: Invalid is a global variable
203+ *Add message to linked list of unprocessed messages.
191204 * ----------------
192205 */
193206Invalid = LocalInvalidRegister (Invalid , (InvalidationEntry )message );
@@ -224,32 +237,12 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
224237message -> any .relation .objectId = objectId ;
225238
226239/* ----------------
227- *Note: Invalid is a global variable
240+ *Add message to linked list of unprocessed messages.
228241 * ----------------
229242 */
230243Invalid = LocalInvalidRegister (Invalid , (InvalidationEntry )message );
231244}
232245
233- /* --------------------------------
234- *getmyrelids
235- * --------------------------------
236- */
237- static void
238- getmyrelids ()
239- {
240- MyRelationRelationId = RelnameFindRelid (RelationRelationName );
241- Assert (RelationRelationName != InvalidOid );
242-
243- MyAttributeRelationId = RelnameFindRelid (AttributeRelationName );
244- Assert (AttributeRelationName != InvalidOid );
245-
246- MyAMRelationId = RelnameFindRelid (AccessMethodRelationName );
247- Assert (MyAMRelationId != InvalidOid );
248-
249- MyAMOPRelationId = RelnameFindRelid (AccessMethodOperatorRelationName );
250- Assert (MyAMOPRelationId != InvalidOid );
251- }
252-
253246/* --------------------------------
254247 *CacheIdInvalidate
255248 *
@@ -284,38 +277,23 @@ CacheIdInvalidate(Index cacheId,
284277
285278CacheIdInvalidate_DEBUG1 ;
286279
287- ValidateHacks ();/* XXX */
288-
289280/* ----------------
290- *if the cacheId is the oid of any of the tuples in the
291- *following system relations, then assume we are invalidating
292- *a relation descriptor
281+ *if the cacheId is the oid of any of the following system relations,
282+ *then assume we are invalidating a relation descriptor
293283 * ----------------
294284 */
295- if (cacheId == MyRelationRelationId )
285+ if (cacheId == RelOid_pg_class )
296286{
297287RelationIdInvalidateRelationCacheByRelationId (hashIndex );
298288return ;
299289}
300290
301- if (cacheId == MyAttributeRelationId )
291+ if (cacheId == RelOid_pg_attribute )
302292{
303293RelationIdInvalidateRelationCacheByRelationId (hashIndex );
304294return ;
305295}
306296
307- if (cacheId == MyAMRelationId )
308- {
309- RelationIdInvalidateRelationCacheByAccessMethodId (hashIndex );
310- return ;
311- }
312-
313- if (cacheId == MyAMOPRelationId )
314- {
315- RelationIdInvalidateRelationCacheByAccessMethodId (InvalidOid );
316- return ;
317- }
318-
319297/* ----------------
320298 *Yow! the caller asked us to invalidate something else.
321299 * ----------------
@@ -446,29 +424,22 @@ RelationInvalidateRelationCache(Relation relation,
446424void (* function ) ())
447425{
448426Oid relationId ;
449- Oid objectId = ( Oid ) 0 ;
427+ Oid objectId ;
450428
451429/* ----------------
452430 *get the relation object id
453431 * ----------------
454432 */
455- ValidateHacks ();/* XXX */
456433relationId = RelationGetRelid (relation );
457434
458435/* ----------------
459- *
436+ *is it one of the ones we need to send an SI message for?
460437 * ----------------
461438 */
462- if (relationId == MyRelationRelationId )
439+ if (relationId == RelOid_pg_class )
463440objectId = tuple -> t_data -> t_oid ;
464- else if (relationId == MyAttributeRelationId )
441+ else if (relationId == RelOid_pg_attribute )
465442objectId = ((Form_pg_attribute )GETSTRUCT (tuple ))-> attrelid ;
466- else if (relationId == MyAMRelationId )
467- objectId = tuple -> t_data -> t_oid ;
468- else if (relationId == MyAMOPRelationId )
469- {
470- ;/* objectId is unused */
471- }
472443else
473444return ;
474445
@@ -482,19 +453,6 @@ RelationInvalidateRelationCache(Relation relation,
482453}
483454
484455
485- /*
486- *InitLocalInvalidateData
487- *
488- *Setup this before anything could ever get invalid!
489- *Called by InitPostgres();
490- */
491- void
492- InitLocalInvalidateData ()
493- {
494- ValidateHacks ();
495- }
496-
497-
498456/*
499457 * DiscardInvalid
500458 *Causes the invalidated cache state to be discarded.
@@ -528,6 +486,8 @@ DiscardInvalid()
528486void
529487RegisterInvalid (bool send )
530488{
489+ LocalInvalid invalid ;
490+
531491/* ----------------
532492 *debugging stuff
533493 * ----------------
@@ -537,17 +497,19 @@ RegisterInvalid(bool send)
537497#endif /* defined(INVALIDDEBUG) */
538498
539499/* ----------------
540- *Note: Invalid is a global variable
500+ *Process and free the current list of inval messages.
541501 * ----------------
542502 */
503+ invalid = Invalid ;
504+ Invalid = EmptyLocalInvalid ;/* anything added now is part of a new list */
505+
543506if (send )
544- LocalInvalidInvalidate (Invalid ,
507+ LocalInvalidInvalidate (invalid ,
545508InvalidationMessageRegisterSharedInvalid );
546509else
547- LocalInvalidInvalidate (Invalid ,
510+ LocalInvalidInvalidate (invalid ,
548511InvalidationMessageCacheInvalidate );
549512
550- Invalid = EmptyLocalInvalid ;
551513}
552514
553515/*