MCPcopy Create free account
hub / github.com/apache/cloudberry / get_attribute_options

Function get_attribute_options

src/backend/utils/cache/attoptcache.c:102–177  ·  view source on GitHub ↗

* get_attribute_options * Fetch attribute options for a specified table OID. */

Source from the content-addressed store, hash-verified

100 * Fetch attribute options for a specified table OID.
101 */
102AttributeOpts *
103get_attribute_options(Oid attrelid, int attnum)
104{
105 AttoptCacheKey key;
106 AttoptCacheEntry *attopt;
107 AttributeOpts *result;
108 HeapTuple tp;
109
110 /* Find existing cache entry, if any. */
111 if (!AttoptCacheHash)
112 InitializeAttoptCache();
113 memset(&key, 0, sizeof(key)); /* make sure any padding bits are unset */
114 key.attrelid = attrelid;
115 key.attnum = attnum;
116 attopt =
117 (AttoptCacheEntry *) hash_search(AttoptCacheHash,
118 (void *) &key,
119 HASH_FIND,
120 NULL);
121
122 /* Not found in Attopt cache. Construct new cache entry. */
123 if (!attopt)
124 {
125 AttributeOpts *opts;
126
127 tp = SearchSysCache2(ATTNUM,
128 ObjectIdGetDatum(attrelid),
129 Int16GetDatum(attnum));
130
131 /*
132 * If we don't find a valid HeapTuple, it must mean someone has
133 * managed to request attribute details for a non-existent attribute.
134 * We treat that case as if no options were specified.
135 */
136 if (!HeapTupleIsValid(tp))
137 opts = NULL;
138 else
139 {
140 Datum datum;
141 bool isNull;
142
143 datum = SysCacheGetAttr(ATTNUM,
144 tp,
145 Anum_pg_attribute_attoptions,
146 &isNull);
147 if (isNull)
148 opts = NULL;
149 else
150 {
151 bytea *bytea_opts = attribute_reloptions(datum, false);
152
153 opts = MemoryContextAlloc(CacheMemoryContext,
154 VARSIZE(bytea_opts));
155 memcpy(opts, bytea_opts, VARSIZE(bytea_opts));
156 }
157 ReleaseSysCache(tp);
158 }
159

Callers 2

compute_expr_statsFunction · 0.85
do_analyze_relFunction · 0.85

Calls 10

InitializeAttoptCacheFunction · 0.85
hash_searchFunction · 0.85
SearchSysCache2Function · 0.85
ObjectIdGetDatumFunction · 0.85
Int16GetDatumFunction · 0.85
SysCacheGetAttrFunction · 0.85
attribute_reloptionsFunction · 0.85
MemoryContextAllocFunction · 0.85
ReleaseSysCacheFunction · 0.85
pallocFunction · 0.50

Tested by

no test coverage detected