PostgreSQL Source Code git master
typcache.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * typcache.h
4 * Type cache definitions.
5 *
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.
8 *
9 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
11 *
12 * src/include/utils/typcache.h
13 *
14 *-------------------------------------------------------------------------
15 */
16#ifndef TYPCACHE_H
17#define TYPCACHE_H
18
19#include "access/tupdesc.h"
20#include "fmgr.h"
21#include "storage/dsm.h"
22#include "utils/dsa.h"
23
24
25/* DomainConstraintCache is an opaque struct known only within typcache.c */
27
28/* TypeCacheEnumData is an opaque struct known only within typcache.c */
30
31typedef struct TypeCacheEntry
32{
33 /* typeId is the hash lookup key and MUST BE FIRST */
34 Oid type_id; /* OID of the data type */
35
36 uint32 type_id_hash; /* hashed value of the OID */
37
38 /* some subsidiary information copied from the pg_type row */
43 char typtype;
48
49 /*
50 * Information obtained from opfamily entries
51 *
52 * These will be InvalidOid if no match could be found, or if the
53 * information hasn't yet been requested. Also note that for array and
54 * composite types, typcache.c checks that the contained types are
55 * comparable or hashable before allowing eq_opr etc to become set.
56 */
57 Oid btree_opf; /* the default btree opclass' family */
58 Oid btree_opintype; /* the default btree opclass' opcintype */
59 Oid hash_opf; /* the default hash opclass' family */
60 Oid hash_opintype; /* the default hash opclass' opcintype */
61 Oid eq_opr; /* the equality operator */
62 Oid lt_opr; /* the less-than operator */
63 Oid gt_opr; /* the greater-than operator */
64 Oid cmp_proc; /* the btree comparison function */
65 Oid hash_proc; /* the hash calculation function */
66 Oid hash_extended_proc; /* the extended hash calculation function */
67
68 /*
69 * Pre-set-up fmgr call info for the equality operator, the btree
70 * comparison function, and the hash calculation function. These are kept
71 * in the type cache to avoid problems with memory leaks in repeated calls
72 * to functions such as array_eq, array_cmp, hash_array. There is not
73 * currently a need to maintain call info for the lt_opr or gt_opr.
74 */
79
80 /*
81 * Tuple descriptor if it's a composite type (row type). NULL if not
82 * composite or information hasn't yet been requested. (NOTE: this is a
83 * reference-counted tupledesc.)
84 *
85 * To simplify caching dependent info, tupDesc_identifier is an identifier
86 * for this tupledesc that is unique for the life of the process, and
87 * changes anytime the tupledesc does. Zero if not yet determined.
88 */
91
92 /*
93 * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not
94 * a range type or information hasn't yet been requested. Note that
95 * rng_cmp_proc_finfo could be different from the element type's default
96 * btree comparison function.
97 */
98 struct TypeCacheEntry *rngelemtype; /* range's element type */
99 Oid rng_opfamily; /* opfamily to use for range comparisons */
100 Oid rng_collation; /* collation for comparisons, if any */
101 FmgrInfo rng_cmp_proc_finfo; /* comparison function */
102 FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */
103 FmgrInfo rng_subdiff_finfo; /* difference function, if any */
104
105 /*
106 * Fields computed when TYPECACHE_MULTIRANGE_INFO is required.
107 */
108 struct TypeCacheEntry *rngtype; /* multirange's range underlying type */
109
110 /*
111 * Domain's base type and typmod if it's a domain type. Zeroes if not
112 * domain, or if information hasn't been requested.
113 */
116
117 /*
118 * Domain constraint data if it's a domain type. NULL if not domain, or
119 * if domain has no constraints, or if information hasn't been requested.
120 */
122
123 /* Private data, for internal use of typcache.c only */
124 int flags; /* flags about what we've computed */
125
126 /*
127 * Private information about an enum type. NULL if not enum or
128 * information hasn't been requested.
129 */
131
132 /* We also maintain a list of all known domain-type cache entries */
135
136/* Bit flags to indicate which fields a given caller needs to have set */
137#define TYPECACHE_EQ_OPR 0x00001
138#define TYPECACHE_LT_OPR 0x00002
139#define TYPECACHE_GT_OPR 0x00004
140#define TYPECACHE_CMP_PROC 0x00008
141#define TYPECACHE_HASH_PROC 0x00010
142#define TYPECACHE_EQ_OPR_FINFO 0x00020
143#define TYPECACHE_CMP_PROC_FINFO 0x00040
144#define TYPECACHE_HASH_PROC_FINFO 0x00080
145#define TYPECACHE_TUPDESC 0x00100
146#define TYPECACHE_BTREE_OPFAMILY 0x00200
147#define TYPECACHE_HASH_OPFAMILY 0x00400
148#define TYPECACHE_RANGE_INFO 0x00800
149#define TYPECACHE_DOMAIN_BASE_INFO 0x01000
150#define TYPECACHE_DOMAIN_CONSTR_INFO 0x02000
151#define TYPECACHE_HASH_EXTENDED_PROC 0x04000
152#define TYPECACHE_HASH_EXTENDED_PROC_FINFO 0x08000
153#define TYPECACHE_MULTIRANGE_INFO 0x10000
154
155/* This value will not equal any valid tupledesc identifier, nor 0 */
156#define INVALID_TUPLEDESC_IDENTIFIER ((uint64) 1)
157
158/*
159 * Callers wishing to maintain a long-lived reference to a domain's constraint
160 * set must store it in one of these. Use InitDomainConstraintRef() and
161 * UpdateDomainConstraintRef() to manage it. Note: DomainConstraintState is
162 * considered an executable expression type, so it's defined in execnodes.h.
163 */
165{
166 List *constraints; /* list of DomainConstraintState nodes */
167 MemoryContext refctx; /* context holding DomainConstraintRef */
168 TypeCacheEntry *tcache; /* typcache entry for domain type */
169 bool need_exprstate; /* does caller need check_exprstate? */
170
171 /* Management data --- treat these fields as private to typcache.c */
172 DomainConstraintCache *dcc; /* current constraints, or NULL if none */
173 MemoryContextCallback callback; /* used to release refcount when done */
175
177
178extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
179
180extern void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref,
181 MemoryContext refctx, bool need_exprstate);
182
184
185extern bool DomainHasConstraints(Oid type_id);
186
187extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
188
190 bool noError);
191
192extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
193
194extern TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod,
195 bool noError);
196
197extern void assign_record_type_typmod(TupleDesc tupDesc);
198
199extern uint64 assign_record_type_identifier(Oid type_id, int32 typmod);
200
201extern int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
202
203extern size_t SharedRecordTypmodRegistryEstimate(void);
204
206 dsm_segment *segment, dsa_area *area);
207
209
210extern void AtEOXact_TypeCache(void);
211
212extern void AtEOSubXact_TypeCache(void);
213
214#endif /* TYPCACHE_H */
int16_t int16
Definition: c.h:483
int32_t int32
Definition: c.h:484
uint64_t uint64
Definition: c.h:489
uint32_t uint32
Definition: c.h:488
unsigned int Oid
Definition: postgres_ext.h:32
DomainConstraintCache * dcc
Definition: typcache.h:172
MemoryContext refctx
Definition: typcache.h:167
MemoryContextCallback callback
Definition: typcache.h:173
TypeCacheEntry * tcache
Definition: typcache.h:168
Definition: fmgr.h:57
Definition: pg_list.h:54
uint32 type_id_hash
Definition: typcache.h:36
uint64 tupDesc_identifier
Definition: typcache.h:90
FmgrInfo hash_proc_finfo
Definition: typcache.h:77
int32 domainBaseTypmod
Definition: typcache.h:115
Oid hash_extended_proc
Definition: typcache.h:66
Oid typsubscript
Definition: typcache.h:45
FmgrInfo rng_cmp_proc_finfo
Definition: typcache.h:101
FmgrInfo cmp_proc_finfo
Definition: typcache.h:76
Oid rng_collation
Definition: typcache.h:100
char typalign
Definition: typcache.h:41
struct TypeCacheEntry * rngelemtype
Definition: typcache.h:98
char typtype
Definition: typcache.h:43
TupleDesc tupDesc
Definition: typcache.h:89
FmgrInfo hash_extended_proc_finfo
Definition: typcache.h:78
DomainConstraintCache * domainData
Definition: typcache.h:121
struct TypeCacheEntry * rngtype
Definition: typcache.h:108
FmgrInfo rng_subdiff_finfo
Definition: typcache.h:103
FmgrInfo eq_opr_finfo
Definition: typcache.h:75
Oid btree_opintype
Definition: typcache.h:58
struct TypeCacheEnumData * enumData
Definition: typcache.h:130
struct TypeCacheEntry * nextDomain
Definition: typcache.h:133
bool typbyval
Definition: typcache.h:40
FmgrInfo rng_canonical_finfo
Definition: typcache.h:102
int16 typlen
Definition: typcache.h:39
Oid hash_opintype
Definition: typcache.h:60
Oid typcollation
Definition: typcache.h:47
Oid domainBaseType
Definition: typcache.h:114
char typstorage
Definition: typcache.h:42
Oid rng_opfamily
Definition: typcache.h:99
Definition: dsa.c:348
void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref, MemoryContext refctx, bool need_exprstate)
Definition: typcache.c:1400
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1920
void AtEOXact_TypeCache(void)
Definition: typcache.c:3178
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1976
TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1937
void SharedRecordTypmodRegistryInit(SharedRecordTypmodRegistry *, dsm_segment *segment, dsa_area *area)
Definition: typcache.c:2195
void SharedRecordTypmodRegistryAttach(SharedRecordTypmodRegistry *)
Definition: typcache.c:2294
uint64 assign_record_type_identifier(Oid type_id, int32 typmod)
Definition: typcache.c:2132
void AtEOSubXact_TypeCache(void)
Definition: typcache.c:3184
bool DomainHasConstraints(Oid type_id)
Definition: typcache.c:1487
size_t SharedRecordTypmodRegistryEstimate(void)
Definition: typcache.c:2173
int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2)
Definition: typcache.c:2650
struct TypeCacheEntry TypeCacheEntry
void assign_record_type_typmod(TupleDesc tupDesc)
Definition: typcache.c:2040
struct DomainConstraintRef DomainConstraintRef
TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod)
Definition: typcache.c:1954
void UpdateDomainConstraintRef(DomainConstraintRef *ref)
Definition: typcache.c:1438
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:386