* Load (or re-load) the enumData member of the typcache entry. */
| 2626 | * Load (or re-load) the enumData member of the typcache entry. |
| 2627 | */ |
| 2628 | static void |
| 2629 | load_enum_cache_data(TypeCacheEntry *tcache) |
| 2630 | { |
| 2631 | TypeCacheEnumData *enumdata; |
| 2632 | Relation enum_rel; |
| 2633 | SysScanDesc enum_scan; |
| 2634 | HeapTuple enum_tuple; |
| 2635 | ScanKeyData skey; |
| 2636 | EnumItem *items; |
| 2637 | int numitems; |
| 2638 | int maxitems; |
| 2639 | Oid bitmap_base; |
| 2640 | Bitmapset *bitmap; |
| 2641 | MemoryContext oldcxt; |
| 2642 | int bm_size, |
| 2643 | start_pos; |
| 2644 | |
| 2645 | /* Check that this is actually an enum */ |
| 2646 | if (tcache->typtype != TYPTYPE_ENUM) |
| 2647 | ereport(ERROR, |
| 2648 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 2649 | errmsg("%s is not an enum", |
| 2650 | format_type_be(tcache->type_id)))); |
| 2651 | |
| 2652 | /* |
| 2653 | * Read all the information for members of the enum type. We collect the |
| 2654 | * info in working memory in the caller's context, and then transfer it to |
| 2655 | * permanent memory in CacheMemoryContext. This minimizes the risk of |
| 2656 | * leaking memory from CacheMemoryContext in the event of an error partway |
| 2657 | * through. |
| 2658 | */ |
| 2659 | maxitems = 64; |
| 2660 | items = (EnumItem *) palloc(sizeof(EnumItem) * maxitems); |
| 2661 | numitems = 0; |
| 2662 | |
| 2663 | /* Scan pg_enum for the members of the target enum type. */ |
| 2664 | ScanKeyInit(&skey, |
| 2665 | Anum_pg_enum_enumtypid, |
| 2666 | BTEqualStrategyNumber, F_OIDEQ, |
| 2667 | ObjectIdGetDatum(tcache->type_id)); |
| 2668 | |
| 2669 | enum_rel = table_open(EnumRelationId, AccessShareLock); |
| 2670 | enum_scan = systable_beginscan(enum_rel, |
| 2671 | EnumTypIdLabelIndexId, |
| 2672 | true, NULL, |
| 2673 | 1, &skey); |
| 2674 | |
| 2675 | while (HeapTupleIsValid(enum_tuple = systable_getnext(enum_scan))) |
| 2676 | { |
| 2677 | Form_pg_enum en = (Form_pg_enum) GETSTRUCT(enum_tuple); |
| 2678 | |
| 2679 | if (numitems >= maxitems) |
| 2680 | { |
| 2681 | maxitems *= 2; |
| 2682 | items = (EnumItem *) repalloc(items, sizeof(EnumItem) * maxitems); |
| 2683 | } |
| 2684 | items[numitems].enum_oid = en->oid; |
| 2685 | items[numitems].sort_order = en->enumsortorder; |
no test coverage detected