7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
* Note - this code is real crufty...
13
13
*
18
18
#include "catalog/catalog.h"
19
19
#include "catalog/catname.h"
20
20
#include "catalog/heap.h"
21
+ #include "catalog/pg_class.h"
21
22
#include "miscadmin.h"
22
23
#include "storage/sinval.h"
23
24
#include "utils/catcache.h"
24
25
#include "utils/inval.h"
25
26
#include "utils/relcache.h"
26
27
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
-
33
28
34
29
/* ----------------
35
30
* private invalidation structures
36
31
* ----------------
37
32
*/
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
+
38
51
typedef struct CatalogInvalidationData
39
52
{
40
53
Index cacheId ;
@@ -66,15 +79,14 @@ typedef InvalidationMessageData *InvalidationMessage;
66
79
* variables and macros
67
80
* ----------------
68
81
*/
69
- static LocalInvalid Invalid = EmptyLocalInvalid ; /* XXX global */
82
+ static LocalInvalid Invalid = EmptyLocalInvalid ; /* head of linked list */
70
83
71
- Oid MyRelationRelationId = InvalidOid ;
72
- Oid MyAttributeRelationId = InvalidOid ;
73
- Oid MyAMRelationId = InvalidOid ;
74
- Oid MyAMOPRelationId = InvalidOid ;
75
84
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
+
78
90
79
91
/* ----------------------------------------------------------------
80
92
* "local" invalidation support functions
@@ -99,7 +111,8 @@ InvalidationEntryAllocate(uint16 size)
99
111
100
112
/* --------------------------------
101
113
* 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.
103
116
* --------------------------------
104
117
*/
105
118
static LocalInvalid
@@ -117,7 +130,7 @@ LocalInvalidRegister(LocalInvalid invalid,
117
130
/* --------------------------------
118
131
* LocalInvalidInvalidate
119
132
* Processes, then frees all entries in a local cache
120
- * invalidation state .
133
+ * invalidation list .
121
134
* --------------------------------
122
135
*/
123
136
static void
@@ -187,7 +200,7 @@ CacheIdRegisterLocalInvalid(Index cacheId,
187
200
ItemPointerCopy (pointer , & message -> any .catalog .pointerData );
188
201
189
202
/* ----------------
190
- * Note: Invalid is a global variable
203
+ * Add message to linked list of unprocessed messages.
191
204
* ----------------
192
205
*/
193
206
Invalid = LocalInvalidRegister (Invalid , (InvalidationEntry ) message );
@@ -224,32 +237,12 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
224
237
message -> any .relation .objectId = objectId ;
225
238
226
239
/* ----------------
227
- * Note: Invalid is a global variable
240
+ * Add message to linked list of unprocessed messages.
228
241
* ----------------
229
242
*/
230
243
Invalid = LocalInvalidRegister (Invalid , (InvalidationEntry ) message );
231
244
}
232
245
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
-
253
246
/* --------------------------------
254
247
* CacheIdInvalidate
255
248
*
@@ -284,38 +277,23 @@ CacheIdInvalidate(Index cacheId,
284
277
285
278
CacheIdInvalidate_DEBUG1 ;
286
279
287
- ValidateHacks (); /* XXX */
288
-
289
280
/* ----------------
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
293
283
* ----------------
294
284
*/
295
- if (cacheId == MyRelationRelationId )
285
+ if (cacheId == RelOid_pg_class )
296
286
{
297
287
RelationIdInvalidateRelationCacheByRelationId (hashIndex );
298
288
return ;
299
289
}
300
290
301
- if (cacheId == MyAttributeRelationId )
291
+ if (cacheId == RelOid_pg_attribute )
302
292
{
303
293
RelationIdInvalidateRelationCacheByRelationId (hashIndex );
304
294
return ;
305
295
}
306
296
307
- if (cacheId == MyAMRelationId )
308
- {
309
- RelationIdInvalidateRelationCacheByAccessMethodId (hashIndex );
310
- return ;
311
- }
312
-
313
- if (cacheId == MyAMOPRelationId )
314
- {
315
- RelationIdInvalidateRelationCacheByAccessMethodId (InvalidOid );
316
- return ;
317
- }
318
-
319
297
/* ----------------
320
298
* Yow! the caller asked us to invalidate something else.
321
299
* ----------------
@@ -446,29 +424,22 @@ RelationInvalidateRelationCache(Relation relation,
446
424
void (* function ) ())
447
425
{
448
426
Oid relationId ;
449
- Oid objectId = ( Oid ) 0 ;
427
+ Oid objectId ;
450
428
451
429
/* ----------------
452
430
* get the relation object id
453
431
* ----------------
454
432
*/
455
- ValidateHacks (); /* XXX */
456
433
relationId = RelationGetRelid (relation );
457
434
458
435
/* ----------------
459
- *
436
+ * is it one of the ones we need to send an SI message for?
460
437
* ----------------
461
438
*/
462
- if (relationId == MyRelationRelationId )
439
+ if (relationId == RelOid_pg_class )
463
440
objectId = tuple -> t_data -> t_oid ;
464
- else if (relationId == MyAttributeRelationId )
441
+ else if (relationId == RelOid_pg_attribute )
465
442
objectId = ((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
- }
472
443
else
473
444
return ;
474
445
@@ -482,19 +453,6 @@ RelationInvalidateRelationCache(Relation relation,
482
453
}
483
454
484
455
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
-
498
456
/*
499
457
* DiscardInvalid
500
458
* Causes the invalidated cache state to be discarded.
@@ -528,6 +486,8 @@ DiscardInvalid()
528
486
void
529
487
RegisterInvalid (bool send )
530
488
{
489
+ LocalInvalid invalid ;
490
+
531
491
/* ----------------
532
492
* debugging stuff
533
493
* ----------------
@@ -537,17 +497,19 @@ RegisterInvalid(bool send)
537
497
#endif /* defined(INVALIDDEBUG) */
538
498
539
499
/* ----------------
540
- * Note: Invalid is a global variable
500
+ * Process and free the current list of inval messages.
541
501
* ----------------
542
502
*/
503
+ invalid = Invalid ;
504
+ Invalid = EmptyLocalInvalid ; /* anything added now is part of a new list */
505
+
543
506
if (send )
544
- LocalInvalidInvalidate (Invalid ,
507
+ LocalInvalidInvalidate (invalid ,
545
508
InvalidationMessageRegisterSharedInvalid );
546
509
else
547
- LocalInvalidInvalidate (Invalid ,
510
+ LocalInvalidInvalidate (invalid ,
548
511
InvalidationMessageCacheInvalidate );
549
512
550
- Invalid = EmptyLocalInvalid ;
551
513
}
552
514
553
515
/*
0 commit comments