1/*-------------------------------------------------------------------------
4 * Tablespace cache management.
6 * We cache the parsed version of spcoptions for each tablespace to avoid
7 * needing to reparse on every lookup. Right now, there doesn't appear to
8 * be a measurable performance gain from doing this, but that might change
9 * in the future as we add more options.
11 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
15 * src/backend/utils/cache/spccache.c
17 *-------------------------------------------------------------------------
35/* Hash table for information about each tablespace */
40 Oid oid;
/* lookup key - must be first */
46 * InvalidateTableSpaceCacheCallback
47 * Flush all cache entries when pg_tablespace is updated.
49 * When pg_tablespace is updated, we must flush the cache entry at least
50 * for that tablespace. Currently, we just flush them all. This is quick
51 * and easy and doesn't cost much, since there shouldn't be terribly many
52 * tablespaces, nor do we expect them to be frequently modified.
74 * InitializeTableSpaceCache
75 * Initialize the tablespace cache.
82 /* Initialize the hash table. */
89 /* Make sure we've initialized CacheMemoryContext. */
93 /* Watch for invalidation events. */
101 * Fetch TableSpaceCacheEntry structure for a specified table OID.
103 * Pointers returned by this function should not be stored, since a cache
104 * flush will invalidate them.
114 * Since spcid is always from a pg_class tuple, InvalidOid implies the
120 /* Find existing cache entry, if any. */
131 * Not found in TableSpace cache. Check catcache. If we don't find a
132 * valid HeapTuple, it must mean someone has managed to request tablespace
133 * details for a non-existent tablespace. We'll just treat that case as
134 * if no options were specified.
146 Anum_pg_tablespace_spcoptions,
161 * Now create the cache entry. It's important to do this only after
162 * reading the pg_tablespace entry, since doing so could cause a cache
174 * get_tablespace_page_costs
175 * Return random and/or sequential page costs for a given tablespace.
177 * This value is not locked by the transaction, so this value may
178 * be changed while a SELECT that has used these values for planning
179 * is still executing.
183 double *spc_random_page_cost,
184 double *spc_seq_page_cost)
190 if (spc_random_page_cost)
198 if (spc_seq_page_cost)
208 * get_tablespace_io_concurrency
210 * This value is not locked by the transaction, so this value may
211 * be changed while a SELECT that has used these values for planning
212 * is still executing.
226 * get_tablespace_maintenance_io_concurrency
int maintenance_io_concurrency
int effective_io_concurrency
void CreateCacheMemoryContext(void)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
MemoryContext CacheMemoryContext
static AmcheckOptions opts
static Datum ObjectIdGetDatum(Oid X)
bytea * tablespace_reloptions(Datum reloptions, bool validate)
static TableSpaceCacheEntry * get_tablespace(Oid spcid)
static void InvalidateTableSpaceCacheCallback(Datum arg, int cacheid, uint32 hashvalue)
int get_tablespace_io_concurrency(Oid spcid)
static void InitializeTableSpaceCache(void)
void get_tablespace_page_costs(Oid spcid, double *spc_random_page_cost, double *spc_seq_page_cost)
static HTAB * TableSpaceCacheHash
int get_tablespace_maintenance_io_concurrency(Oid spcid)
int maintenance_io_concurrency
int effective_io_concurrency
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
static Size VARSIZE(const void *PTR)