* get_attribute_options * Fetch attribute options for a specified table OID. */
| 100 | * Fetch attribute options for a specified table OID. |
| 101 | */ |
| 102 | AttributeOpts * |
| 103 | get_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 |
no test coverage detected