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

Function enum_cmp_internal

src/backend/utils/adt/enum.c:245–297  ·  view source on GitHub ↗

* enum_cmp_internal is the common engine for all the visible comparison * functions, except for enum_eq and enum_ne which can just check for OID * equality directly. */

Source from the content-addressed store, hash-verified

243 * equality directly.
244 */
245static int
246enum_cmp_internal(Oid arg1, Oid arg2, FunctionCallInfo fcinfo)
247{
248 TypeCacheEntry *tcache;
249
250 /*
251 * We don't need the typcache except in the hopefully-uncommon case that
252 * one or both Oids are odd. This means that cursory testing of code that
253 * fails to pass flinfo to an enum comparison function might not disclose
254 * the oversight. To make such errors more obvious, Assert that we have a
255 * place to cache even when we take a fast-path exit.
256 */
257 Assert(fcinfo->flinfo != NULL);
258
259 /* Equal OIDs are equal no matter what */
260 if (arg1 == arg2)
261 return 0;
262
263 /* Fast path: even-numbered Oids are known to compare correctly */
264 if ((arg1 & 1) == 0 && (arg2 & 1) == 0)
265 {
266 if (arg1 < arg2)
267 return -1;
268 else
269 return 1;
270 }
271
272 /* Locate the typcache entry for the enum type */
273 tcache = (TypeCacheEntry *) fcinfo->flinfo->fn_extra;
274 if (tcache == NULL)
275 {
276 HeapTuple enum_tup;
277 Form_pg_enum en;
278 Oid typeoid;
279
280 /* Get the OID of the enum type containing arg1 */
281 enum_tup = SearchSysCache1(ENUMOID, ObjectIdGetDatum(arg1));
282 if (!HeapTupleIsValid(enum_tup))
283 ereport(ERROR,
284 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
285 errmsg("invalid internal value for enum: %u",
286 arg1)));
287 en = (Form_pg_enum) GETSTRUCT(enum_tup);
288 typeoid = en->enumtypid;
289 ReleaseSysCache(enum_tup);
290 /* Now locate and remember the typcache entry */
291 tcache = lookup_type_cache(typeoid, 0);
292 fcinfo->flinfo->fn_extra = (void *) tcache;
293 }
294
295 /* The remaining comparison logic is in typcache.c */
296 return compare_values_of_enum(tcache, arg1, arg2);
297}
298
299Datum
300enum_lt(PG_FUNCTION_ARGS)

Callers 7

enum_ltFunction · 0.85
enum_leFunction · 0.85
enum_geFunction · 0.85
enum_gtFunction · 0.85
enum_smallerFunction · 0.85
enum_largerFunction · 0.85
enum_cmpFunction · 0.85

Calls 7

SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
ReleaseSysCacheFunction · 0.85
lookup_type_cacheFunction · 0.85
compare_values_of_enumFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected