PostgreSQL Source Code git master
Loading...
Searching...
No Matches
attoptcache.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AttributeOpts
 

Typedefs

typedef struct AttributeOpts AttributeOpts
 

Functions

AttributeOptsget_attribute_options (Oid attrelid, int attnum)
 

Typedef Documentation

◆ AttributeOpts

Function Documentation

◆ get_attribute_options()

AttributeOpts * get_attribute_options ( Oid  attrelid,
int  attnum 
)
extern

Definition at line 131 of file attoptcache.c.

132{
135 AttributeOpts *result;
136 HeapTuple tp;
137
138 /* Find existing cache entry, if any. */
139 if (!AttoptCacheHash)
141 memset(&key, 0, sizeof(key)); /* make sure any padding bits are unset */
142 key.attrelid = attrelid;
143 key.attnum = attnum;
144 attopt =
146 &key,
147 HASH_FIND,
148 NULL);
149
150 /* Not found in Attopt cache. Construct new cache entry. */
151 if (!attopt)
152 {
154
156 ObjectIdGetDatum(attrelid),
158
159 /*
160 * If we don't find a valid HeapTuple, it must mean someone has
161 * managed to request attribute details for a non-existent attribute.
162 * We treat that case as if no options were specified.
163 */
164 if (!HeapTupleIsValid(tp))
165 opts = NULL;
166 else
167 {
168 Datum datum;
169 bool isNull;
170
171 datum = SysCacheGetAttr(ATTNUM,
172 tp,
174 &isNull);
175 if (isNull)
176 opts = NULL;
177 else
178 {
179 bytea *bytea_opts = attribute_reloptions(datum, false);
180
184 }
185 ReleaseSysCache(tp);
186 }
187
188 /*
189 * It's important to create the actual cache entry only after reading
190 * pg_attribute, since the read could cause a cache flush.
191 */
193 &key,
195 NULL);
196 attopt->opts = opts;
197 }
198
199 /* Return results in caller's memory context. */
200 if (attopt->opts == NULL)
201 return NULL;
202 result = palloc(VARSIZE(attopt->opts));
203 memcpy(result, attopt->opts, VARSIZE(attopt->opts));
204 return result;
205}
static HTAB * AttoptCacheHash
Definition attoptcache.c:29
static void InitializeAttoptCache(void)
Definition attoptcache.c:97
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:952
@ HASH_FIND
Definition hsearch.h:113
@ HASH_ENTER
Definition hsearch.h:114
#define HeapTupleIsValid(tuple)
Definition htup.h:78
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
void * palloc(Size size)
Definition mcxt.c:1387
MemoryContext CacheMemoryContext
Definition mcxt.c:169
static AmcheckOptions opts
Definition pg_amcheck.c:112
int16 attnum
static Datum Int16GetDatum(int16 X)
Definition postgres.h:182
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
bytea * attribute_reloptions(Datum reloptions, bool validate)
Definition c.h:706
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition syscache.c:230
static Size VARSIZE(const void *PTR)
Definition varatt.h:298

References attnum, AttoptCacheHash, attribute_reloptions(), CacheMemoryContext, fb(), HASH_ENTER, HASH_FIND, hash_search(), HeapTupleIsValid, InitializeAttoptCache(), Int16GetDatum(), MemoryContextAlloc(), ObjectIdGetDatum(), opts, palloc(), ReleaseSysCache(), SearchSysCache2(), SysCacheGetAttr(), and VARSIZE().

Referenced by compute_expr_stats(), and do_analyze_rel().