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-2020, 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 */
29 struct TypeCacheEnumData;
30 
31 typedef 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 */
40  bool typbyval;
41  char typalign;
42  char typstorage;
43  char typtype;
47 
48  /*
49  * Information obtained from opfamily entries
50  *
51  * These will be InvalidOid if no match could be found, or if the
52  * information hasn't yet been requested. Also note that for array and
53  * composite types, typcache.c checks that the contained types are
54  * comparable or hashable before allowing eq_opr etc to become set.
55  */
56  Oid btree_opf; /* the default btree opclass' family */
57  Oid btree_opintype; /* the default btree opclass' opcintype */
58  Oid hash_opf; /* the default hash opclass' family */
59  Oid hash_opintype; /* the default hash opclass' opcintype */
60  Oid eq_opr; /* the equality operator */
61  Oid lt_opr; /* the less-than operator */
62  Oid gt_opr; /* the greater-than operator */
63  Oid cmp_proc; /* the btree comparison function */
64  Oid hash_proc; /* the hash calculation function */
65  Oid hash_extended_proc; /* the extended hash calculation function */
66 
67  /*
68  * Pre-set-up fmgr call info for the equality operator, the btree
69  * comparison function, and the hash calculation function. These are kept
70  * in the type cache to avoid problems with memory leaks in repeated calls
71  * to functions such as array_eq, array_cmp, hash_array. There is not
72  * currently a need to maintain call info for the lt_opr or gt_opr.
73  */
78 
79  /*
80  * Tuple descriptor if it's a composite type (row type). NULL if not
81  * composite or information hasn't yet been requested. (NOTE: this is a
82  * reference-counted tupledesc.)
83  *
84  * To simplify caching dependent info, tupDesc_identifier is an identifier
85  * for this tupledesc that is unique for the life of the process, and
86  * changes anytime the tupledesc does. Zero if not yet determined.
87  */
90 
91  /*
92  * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not
93  * a range type or information hasn't yet been requested. Note that
94  * rng_cmp_proc_finfo could be different from the element type's default
95  * btree comparison function.
96  */
97  struct TypeCacheEntry *rngelemtype; /* range's element type */
98  Oid rng_collation; /* collation for comparisons, if any */
99  FmgrInfo rng_cmp_proc_finfo; /* comparison function */
100  FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */
101  FmgrInfo rng_subdiff_finfo; /* difference function, if any */
102 
103  /*
104  * Domain's base type and typmod if it's a domain type. Zeroes if not
105  * domain, or if information hasn't been requested.
106  */
109 
110  /*
111  * Domain constraint data if it's a domain type. NULL if not domain, or
112  * if domain has no constraints, or if information hasn't been requested.
113  */
115 
116  /* Private data, for internal use of typcache.c only */
117  int flags; /* flags about what we've computed */
118 
119  /*
120  * Private information about an enum type. NULL if not enum or
121  * information hasn't been requested.
122  */
124 
125  /* We also maintain a list of all known domain-type cache entries */
128 
129 /* Bit flags to indicate which fields a given caller needs to have set */
130 #define TYPECACHE_EQ_OPR 0x0001
131 #define TYPECACHE_LT_OPR 0x0002
132 #define TYPECACHE_GT_OPR 0x0004
133 #define TYPECACHE_CMP_PROC 0x0008
134 #define TYPECACHE_HASH_PROC 0x0010
135 #define TYPECACHE_EQ_OPR_FINFO 0x0020
136 #define TYPECACHE_CMP_PROC_FINFO 0x0040
137 #define TYPECACHE_HASH_PROC_FINFO 0x0080
138 #define TYPECACHE_TUPDESC 0x0100
139 #define TYPECACHE_BTREE_OPFAMILY 0x0200
140 #define TYPECACHE_HASH_OPFAMILY 0x0400
141 #define TYPECACHE_RANGE_INFO 0x0800
142 #define TYPECACHE_DOMAIN_BASE_INFO 0x1000
143 #define TYPECACHE_DOMAIN_CONSTR_INFO 0x2000
144 #define TYPECACHE_HASH_EXTENDED_PROC 0x4000
145 #define TYPECACHE_HASH_EXTENDED_PROC_FINFO 0x8000
146 
147 /* This value will not equal any valid tupledesc identifier, nor 0 */
148 #define INVALID_TUPLEDESC_IDENTIFIER ((uint64) 1)
149 
150 /*
151  * Callers wishing to maintain a long-lived reference to a domain's constraint
152  * set must store it in one of these. Use InitDomainConstraintRef() and
153  * UpdateDomainConstraintRef() to manage it. Note: DomainConstraintState is
154  * considered an executable expression type, so it's defined in execnodes.h.
155  */
156 typedef struct DomainConstraintRef
157 {
158  List *constraints; /* list of DomainConstraintState nodes */
159  MemoryContext refctx; /* context holding DomainConstraintRef */
160  TypeCacheEntry *tcache; /* typcache entry for domain type */
161  bool need_exprstate; /* does caller need check_exprstate? */
162 
163  /* Management data --- treat these fields as private to typcache.c */
164  DomainConstraintCache *dcc; /* current constraints, or NULL if none */
165  MemoryContextCallback callback; /* used to release refcount when done */
167 
169 
171 
173  MemoryContext refctx, bool need_exprstate);
174 
176 
177 extern bool DomainHasConstraints(Oid type_id);
178 
180 
182  bool noError);
183 
185 
187  bool noError);
188 
190 
191 extern uint64 assign_record_type_identifier(Oid type_id, int32 typmod);
192 
193 extern int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
194 
195 extern size_t SharedRecordTypmodRegistryEstimate(void);
196 
198  dsm_segment *segment, dsa_area *area);
199 
201 
202 #endif /* TYPCACHE_H */
int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2)
Definition: typcache.c:2368
MemoryContextCallback callback
Definition: typcache.h:165
signed short int16
Definition: c.h:416
struct TypeCacheEnumData * enumData
Definition: typcache.h:123
Definition: fmgr.h:56
uint64 assign_record_type_identifier(Oid type_id, int32 typmod)
Definition: typcache.c:1936
FmgrInfo rng_cmp_proc_finfo
Definition: typcache.h:99
DomainConstraintCache * dcc
Definition: typcache.h:164
TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod)
Definition: typcache.c:1775
Oid hash_opintype
Definition: typcache.h:59
uint32 type_id_hash
Definition: typcache.h:36
DomainConstraintCache * domainData
Definition: typcache.h:114
void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref, MemoryContext refctx, bool need_exprstate)
Definition: typcache.c:1259
struct TypeCacheEntry TypeCacheEntry
Oid typcollation
Definition: typcache.h:46
size_t SharedRecordTypmodRegistryEstimate(void)
Definition: typcache.c:1977
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1797
unsigned int Oid
Definition: postgres_ext.h:31
int16 typlen
Definition: typcache.h:39
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1741
bool typbyval
Definition: typcache.h:40
signed int int32
Definition: c.h:417
Oid domainBaseType
Definition: typcache.h:107
FmgrInfo rng_subdiff_finfo
Definition: typcache.h:101
FmgrInfo cmp_proc_finfo
Definition: typcache.h:75
struct TypeCacheEntry * nextDomain
Definition: typcache.h:126
void UpdateDomainConstraintRef(DomainConstraintRef *ref)
Definition: typcache.c:1297
void assign_record_type_typmod(TupleDesc tupDesc)
Definition: typcache.c:1861
char typstorage
Definition: typcache.h:42
int32 domainBaseTypmod
Definition: typcache.h:108
void SharedRecordTypmodRegistryAttach(SharedRecordTypmodRegistry *)
Definition: typcache.c:2098
Oid hash_extended_proc
Definition: typcache.h:65
unsigned int uint32
Definition: c.h:429
FmgrInfo hash_proc_finfo
Definition: typcache.h:76
FmgrInfo rng_canonical_finfo
Definition: typcache.h:100
MemoryContext refctx
Definition: typcache.h:159
struct TypeCacheEntry * rngelemtype
Definition: typcache.h:97
struct DomainConstraintRef DomainConstraintRef
FmgrInfo hash_extended_proc_finfo
Definition: typcache.h:77
Oid btree_opintype
Definition: typcache.h:57
FmgrInfo eq_opr_finfo
Definition: typcache.h:74
char typtype
Definition: typcache.h:43
bool DomainHasConstraints(Oid type_id)
Definition: typcache.c:1346
void SharedRecordTypmodRegistryInit(SharedRecordTypmodRegistry *, dsm_segment *segment, dsa_area *area)
Definition: typcache.c:1999
TypeCacheEntry * tcache
Definition: typcache.h:160
Oid rng_collation
Definition: typcache.h:98
uint64 tupDesc_identifier
Definition: typcache.h:89
Definition: dsa.c:354
char typalign
Definition: typcache.h:41
Definition: pg_list.h:50
TupleDesc tupDesc
Definition: typcache.h:88
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:334
TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1758