PostgreSQL Source Code: src/backend/utils/cache/syscache.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
22
24#include "catalog/pg_db_role_setting_d.h"
25#include "catalog/pg_depend_d.h"
26#include "catalog/pg_description_d.h"
27#include "catalog/pg_seclabel_d.h"
28#include "catalog/pg_shdepend_d.h"
29#include "catalog/pg_shdescription_d.h"
30#include "catalog/pg_shseclabel_d.h"
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
70{
76};
77
78
79#define KEY(...) VA_ARGS_NARGS(__VA_ARGS__), { __VA_ARGS__ }
80
81#include "catalog/syscache_info.h"
82
84 "SysCacheSize does not match syscache.c's array");
85
87
89
90
93
94
97
98static int oid_compare(const void *a, const void *b);
99
100
101
102
103
104
105
106
107
108
109void
111{
112 int cacheId;
113
115
117
118 for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
119 {
120
121
122
123
126
127
129 cacheinfo[cacheId].reloid,
130 cacheinfo[cacheId].indoid,
131 cacheinfo[cacheId].nkeys,
132 cacheinfo[cacheId].key,
133 cacheinfo[cacheId].nbuckets);
135 elog(ERROR, "could not initialize cache %u (%d)",
136 cacheinfo[cacheId].reloid, cacheId);
137
139 cacheinfo[cacheId].reloid;
141 cacheinfo[cacheId].reloid;
143 cacheinfo[cacheId].indoid;
144
146 }
147
150
151
157
163
165}
166
167
168
169
170
171
172
173
174
175
176
177
178
179void
181{
182 int cacheId;
183
185
186 for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
188}
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
213{
214 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
216
218}
219
223{
224 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
227
229}
230
234{
235 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
238
240}
241
245{
246 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
249
251}
252
256{
257 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
260
262}
263
264
265
266
267
268void
270{
272}
273
274
275
276
277
278
279
280
281
282
283
284
285
289{
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
322 for (;;)
323 {
326
329 {
331 {
333 return tuple;
334 }
336 return tuple;
338 }
340 return tuple;
341
344
345
346
347
348
349
355 (void) LockAcquire(&tag, lockmode, false, false);
356
357
358
359
360
361
362
363
364
365
367 }
368}
369
370
371
372
373
374
375
376
377
384{
386 newtuple;
387
388 tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
390 return tuple;
393 return newtuple;
394}
395
396
397
398
399
400
401
402
406{
408 newtuple;
409
412 return tuple;
415 return newtuple;
416}
417
418
419
420
421
422
423
424bool
430{
432
433 tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
435 return false;
437 return true;
438}
439
440
441
442
443
444
445
446
454{
456 bool isNull;
457 Oid result;
458
459 tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
463 SysCache[cacheId]->cc_tupdesc,
464 &isNull);
465 Assert(!isNull);
467 return result;
468}
469
470
471
472
473
474
475
476
477
478
481{
483
488 return NULL;
490 {
492 return NULL;
493 }
494 return tuple;
495}
496
497
498
499
500
501
504{
506 newtuple;
507
510 return tuple;
513 return newtuple;
514}
515
516
517
518
519
520
521bool
523{
525
528 return false;
530 return true;
531}
532
533
534
535
536
537
538
539
540
541
544{
546
551 return NULL;
553 {
555 return NULL;
556 }
557 return tuple;
558}
559
560
561
562
563
564
567{
569 newtuple;
570
573 return NULL;
576 return newtuple;
577}
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
602 bool *isNull)
603{
604
605
606
607
608
609
610 if (cacheId < 0 || cacheId >= SysCacheSize ||
612 elog(ERROR, "invalid cache ID: %d", cacheId);
614 {
617 }
618
620 SysCache[cacheId]->cc_tupdesc,
621 isNull);
622}
623
624
625
626
627
628
629
633{
634 bool isnull;
636
637 attr = SysCacheGetAttr(cacheId, tup, attributeNumber, &isnull);
638
639 if (isnull)
640 {
642 "unexpected null value in cached tuple for catalog %s column %s",
645 }
646
647 return attr;
648}
649
650
651
652
653
654
655
656
657
658
659
666{
667 if (cacheId < 0 || cacheId >= SysCacheSize ||
669 elog(ERROR, "invalid cache ID: %d", cacheId);
670
672}
673
674
675
676
680{
681 if (cacheId < 0 || cacheId >= SysCacheSize ||
683 elog(ERROR, "invalid cache ID: %d", cacheId);
684
686 key1, key2, key3);
687}
688
689
690
691
692
693
694
695
696
697void
699{
700 if (cacheId < 0 || cacheId >= SysCacheSize)
701 elog(ERROR, "invalid cache ID: %d", cacheId);
702
703
705 return;
706
708}
709
710
711
712
713
714
715
716
717
718
719
720
721bool
723{
724 switch (relid)
725 {
726 case DbRoleSettingRelationId:
727 case DependRelationId:
728 case SharedDependRelationId:
729 case DescriptionRelationId:
730 case SharedDescriptionRelationId:
731 case SecLabelRelationId:
732 case SharedSecLabelRelationId:
733 return true;
734 default:
735 break;
736 }
737
738 return false;
739}
740
741
742
743
744bool
746{
747 int low = 0,
749
750 while (low <= high)
751 {
752 int middle = low + (high - low) / 2;
753
755 return true;
757 low = middle + 1;
758 else
759 high = middle - 1;
760 }
761
762 return false;
763}
764
765
766
767
768
769bool
771{
772 int low = 0,
774
775 while (low <= high)
776 {
777 int middle = low + (high - low) / 2;
778
780 return true;
782 low = middle + 1;
783 else
784 high = middle - 1;
785 }
786
787 return false;
788}
789
790
791
792
793
794static int
796{
797 Oid oa = *((const Oid *) a);
798 Oid ob = *((const Oid *) b);
799
801}
#define PointerIsValid(pointer)
#define OidIsValid(objectId)
CatCache * InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int *key, int nbuckets)
HeapTuple SearchCatCache2(CatCache *cache, Datum v1, Datum v2)
HeapTuple SearchCatCache3(CatCache *cache, Datum v1, Datum v2, Datum v3)
void InitCatCachePhase2(CatCache *cache, bool touch_index)
CatCList * SearchCatCacheList(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3)
uint32 GetCatCacheHashValue(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
HeapTuple SearchCatCache4(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
void CatCacheInvalidate(CatCache *cache, uint32 hashValue)
HeapTuple SearchCatCache1(CatCache *cache, Datum v1)
void ReleaseCatCache(HeapTuple tuple)
HeapTuple SearchCatCache(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_copytuple(HeapTuple tuple)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static void * GETSTRUCT(const HeapTupleData *tuple)
static int pg_cmp_u32(uint32 a, uint32 b)
void AcceptInvalidationMessages(void)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
static bool ItemPointerIsValid(const ItemPointerData *pointer)
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
#define InplaceUpdateTupleLock
char * get_rel_name(Oid relid)
FormData_pg_attribute * Form_pg_attribute
#define qsort(a, b, c, d)
static Datum Int16GetDatum(int16 X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname)
void SysCacheInvalidate(int cacheId, uint32 hashValue)
struct catclist * SearchSysCacheList(int cacheId, int nkeys, Datum key1, Datum key2, Datum key3)
bool RelationHasSysCache(Oid relid)
HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum)
void InitCatalogCache(void)
void ReleaseSysCache(HeapTuple tuple)
static bool CacheInitialized
HeapTuple SearchSysCacheLocked1(int cacheId, Datum key1)
HeapTuple SearchSysCacheLockedCopy1(int cacheId, Datum key1)
static int oid_compare(const void *a, const void *b)
HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
uint32 GetSysCacheHashValue(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
StaticAssertDecl(lengthof(cacheinfo)==SysCacheSize, "SysCacheSize does not match syscache.c's array")
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
static int SysCacheSupportingRelOidSize
HeapTuple SearchSysCacheAttNum(Oid relid, int16 attnum)
bool RelationSupportsSysCache(Oid relid)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
bool SearchSysCacheExistsAttName(Oid relid, const char *attname)
void InitCatalogCachePhase2(void)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
bool SearchSysCacheExists(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
HeapTuple SearchSysCacheCopy(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
static Oid SysCacheRelationOid[SysCacheSize]
static CatCache * SysCache[SysCacheSize]
static Oid SysCacheSupportingRelOid[SysCacheSize *2]
static int SysCacheRelationOidSize
bool RelationInvalidatesSnapshotsOnly(Oid relid)
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Oid GetSysCacheOid(int cacheId, AttrNumber oidcol, Datum key1, Datum key2, Datum key3, Datum key4)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)