1 /*-------------------------------------------------------------------------
4 * Type cache definitions.
6 * The type cache exists to speed lookup of certain information about data
7 * types that is not directly available from a type's pg_type row.
9 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
12 * src/include/utils/typcache.h
14 *-------------------------------------------------------------------------
19 #include "access/tupdesc.h"
23 /* TypeCacheEnumData is an opaque struct known only within typcache.c */
24 struct TypeCacheEnumData;
26 typedef struct TypeCacheEntry
28 /* typeId is the hash lookup key and MUST BE FIRST */
29 Oid type_id; /* OID of the data type */
31 /* some subsidiary information copied from the pg_type row */
40 * Information obtained from opfamily entries
42 * These will be InvalidOid if no match could be found, or if the
43 * information hasn't yet been requested. Also note that for array and
44 * composite types, typcache.c checks that the contained types are
45 * comparable or hashable before allowing eq_opr etc to become set.
47 Oid btree_opf; /* the default btree opclass' family */
48 Oid btree_opintype; /* the default btree opclass' opcintype */
49 Oid hash_opf; /* the default hash opclass' family */
50 Oid hash_opintype; /* the default hash opclass' opcintype */
51 Oid eq_opr; /* the equality operator */
52 Oid lt_opr; /* the less-than operator */
53 Oid gt_opr; /* the greater-than operator */
54 Oid cmp_proc; /* the btree comparison function */
55 Oid hash_proc; /* the hash calculation function */
58 * Pre-set-up fmgr call info for the equality operator, the btree
59 * comparison function, and the hash calculation function. These are kept
60 * in the type cache to avoid problems with memory leaks in repeated calls
61 * to functions such as array_eq, array_cmp, hash_array. There is not
62 * currently a need to maintain call info for the lt_opr or gt_opr.
64 FmgrInfo eq_opr_finfo;
65 FmgrInfo cmp_proc_finfo;
66 FmgrInfo hash_proc_finfo;
69 * Tuple descriptor if it's a composite type (row type). NULL if not
70 * composite or information hasn't yet been requested. (NOTE: this is a
71 * reference-counted tupledesc.)
76 * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not
77 * a range type or information hasn't yet been requested. Note that
78 * rng_cmp_proc_finfo could be different from the element type's default
79 * btree comparison function.
81 struct TypeCacheEntry *rngelemtype; /* range's element type */
82 Oid rng_collation; /* collation for comparisons, if any */
83 FmgrInfo rng_cmp_proc_finfo; /* comparison function */
84 FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */
85 FmgrInfo rng_subdiff_finfo; /* difference function, if any */
87 /* Private data, for internal use of typcache.c only */
88 int flags; /* flags about what we've computed */
91 * Private information about an enum type. NULL if not enum or
92 * information hasn't been requested.
94 struct TypeCacheEnumData *enumData;
97 /* Bit flags to indicate which fields a given caller needs to have set */
98 #define TYPECACHE_EQ_OPR 0x0001
99 #define TYPECACHE_LT_OPR 0x0002
100 #define TYPECACHE_GT_OPR 0x0004
101 #define TYPECACHE_CMP_PROC 0x0008
102 #define TYPECACHE_HASH_PROC 0x0010
103 #define TYPECACHE_EQ_OPR_FINFO 0x0020
104 #define TYPECACHE_CMP_PROC_FINFO 0x0040
105 #define TYPECACHE_HASH_PROC_FINFO 0x0080
106 #define TYPECACHE_TUPDESC 0x0100
107 #define TYPECACHE_BTREE_OPFAMILY 0x0200
108 #define TYPECACHE_HASH_OPFAMILY 0x0400
109 #define TYPECACHE_RANGE_INFO 0x0800
111 extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
113 extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
115 extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod,
118 extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
120 extern void assign_record_type_typmod(TupleDesc tupDesc);
122 extern int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
124 #endif /* TYPCACHE_H */