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

Function compare_values_of_enum

src/backend/utils/cache/typcache.c:2555–2623  ·  view source on GitHub ↗

* compare_values_of_enum * Compare two members of an enum type. * Return <0, 0, or >0 according as arg1 <, =, or > arg2. * * Note: currently, the enumData cache is refreshed only if we are asked * to compare an enum value that is not already in the cache. This is okay * because there is no support for re-ordering existing values, so comparisons * of previously cached values will return t

Source from the content-addressed store, hash-verified

2553 * routine shouldn't even get called when that rule applies.
2554 */
2555int
2556compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2)
2557{
2558 TypeCacheEnumData *enumdata;
2559 EnumItem *item1;
2560 EnumItem *item2;
2561
2562 /*
2563 * Equal OIDs are certainly equal --- this case was probably handled by
2564 * our caller, but we may as well check.
2565 */
2566 if (arg1 == arg2)
2567 return 0;
2568
2569 /* Load up the cache if first time through */
2570 if (tcache->enumData == NULL)
2571 load_enum_cache_data(tcache);
2572 enumdata = tcache->enumData;
2573
2574 /*
2575 * If both OIDs are known-sorted, we can just compare them directly.
2576 */
2577 if (enum_known_sorted(enumdata, arg1) &&
2578 enum_known_sorted(enumdata, arg2))
2579 {
2580 if (arg1 < arg2)
2581 return -1;
2582 else
2583 return 1;
2584 }
2585
2586 /*
2587 * Slow path: we have to identify their actual sort-order positions.
2588 */
2589 item1 = find_enumitem(enumdata, arg1);
2590 item2 = find_enumitem(enumdata, arg2);
2591
2592 if (item1 == NULL || item2 == NULL)
2593 {
2594 /*
2595 * We couldn't find one or both values. That means the enum has
2596 * changed under us, so re-initialize the cache and try again. We
2597 * don't bother retrying the known-sorted case in this path.
2598 */
2599 load_enum_cache_data(tcache);
2600 enumdata = tcache->enumData;
2601
2602 item1 = find_enumitem(enumdata, arg1);
2603 item2 = find_enumitem(enumdata, arg2);
2604
2605 /*
2606 * If we still can't find the values, complain: we must have corrupt
2607 * data.
2608 */
2609 if (item1 == NULL)
2610 elog(ERROR, "enum value %u not found in cache for enum %s",
2611 arg1, format_type_be(tcache->type_id));
2612 if (item2 == NULL)

Callers 1

enum_cmp_internalFunction · 0.85

Calls 4

load_enum_cache_dataFunction · 0.85
enum_known_sortedFunction · 0.85
find_enumitemFunction · 0.85
format_type_beFunction · 0.85

Tested by

no test coverage detected