PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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  /* some subsidiary information copied from the pg_type row */
38  bool typbyval;
39  char typalign;
40  char typstorage;
41  char typtype;
43 
44  /*
45  * Information obtained from opfamily entries
46  *
47  * These will be InvalidOid if no match could be found, or if the
48  * information hasn't yet been requested. Also note that for array and
49  * composite types, typcache.c checks that the contained types are
50  * comparable or hashable before allowing eq_opr etc to become set.
51  */
52  Oid btree_opf; /* the default btree opclass' family */
53  Oid btree_opintype; /* the default btree opclass' opcintype */
54  Oid hash_opf; /* the default hash opclass' family */
55  Oid hash_opintype; /* the default hash opclass' opcintype */
56  Oid eq_opr; /* the equality operator */
57  Oid lt_opr; /* the less-than operator */
58  Oid gt_opr; /* the greater-than operator */
59  Oid cmp_proc; /* the btree comparison function */
60  Oid hash_proc; /* the hash calculation function */
61  Oid hash_extended_proc; /* the extended hash calculation function */
62 
63  /*
64  * Pre-set-up fmgr call info for the equality operator, the btree
65  * comparison function, and the hash calculation function. These are kept
66  * in the type cache to avoid problems with memory leaks in repeated calls
67  * to functions such as array_eq, array_cmp, hash_array. There is not
68  * currently a need to maintain call info for the lt_opr or gt_opr.
69  */
74 
75  /*
76  * Tuple descriptor if it's a composite type (row type). NULL if not
77  * composite or information hasn't yet been requested. (NOTE: this is a
78  * reference-counted tupledesc.)
79  */
81 
82  /*
83  * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not
84  * a range type or information hasn't yet been requested. Note that
85  * rng_cmp_proc_finfo could be different from the element type's default
86  * btree comparison function.
87  */
88  struct TypeCacheEntry *rngelemtype; /* range's element type */
89  Oid rng_collation; /* collation for comparisons, if any */
90  FmgrInfo rng_cmp_proc_finfo; /* comparison function */
91  FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */
92  FmgrInfo rng_subdiff_finfo; /* difference function, if any */
93 
94  /*
95  * Domain constraint data if it's a domain type. NULL if not domain, or
96  * if domain has no constraints, or if information hasn't been requested.
97  */
99 
100  /* Private data, for internal use of typcache.c only */
101  int flags; /* flags about what we've computed */
102 
103  /*
104  * Private information about an enum type. NULL if not enum or
105  * information hasn't been requested.
106  */
108 
109  /* We also maintain a list of all known domain-type cache entries */
112 
113 /* Bit flags to indicate which fields a given caller needs to have set */
114 #define TYPECACHE_EQ_OPR 0x0001
115 #define TYPECACHE_LT_OPR 0x0002
116 #define TYPECACHE_GT_OPR 0x0004
117 #define TYPECACHE_CMP_PROC 0x0008
118 #define TYPECACHE_HASH_PROC 0x0010
119 #define TYPECACHE_EQ_OPR_FINFO 0x0020
120 #define TYPECACHE_CMP_PROC_FINFO 0x0040
121 #define TYPECACHE_HASH_PROC_FINFO 0x0080
122 #define TYPECACHE_TUPDESC 0x0100
123 #define TYPECACHE_BTREE_OPFAMILY 0x0200
124 #define TYPECACHE_HASH_OPFAMILY 0x0400
125 #define TYPECACHE_RANGE_INFO 0x0800
126 #define TYPECACHE_DOMAIN_INFO 0x1000
127 #define TYPECACHE_HASH_EXTENDED_PROC 0x2000
128 #define TYPECACHE_HASH_EXTENDED_PROC_FINFO 0x4000
129 
130 /*
131  * Callers wishing to maintain a long-lived reference to a domain's constraint
132  * set must store it in one of these. Use InitDomainConstraintRef() and
133  * UpdateDomainConstraintRef() to manage it. Note: DomainConstraintState is
134  * considered an executable expression type, so it's defined in execnodes.h.
135  */
136 typedef struct DomainConstraintRef
137 {
138  List *constraints; /* list of DomainConstraintState nodes */
139  MemoryContext refctx; /* context holding DomainConstraintRef */
140  TypeCacheEntry *tcache; /* typcache entry for domain type */
141  bool need_exprstate; /* does caller need check_exprstate? */
142 
143  /* Management data --- treat these fields as private to typcache.c */
144  DomainConstraintCache *dcc; /* current constraints, or NULL if none */
145  MemoryContextCallback callback; /* used to release refcount when done */
147 
149 
150 extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
151 
152 extern void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref,
153  MemoryContext refctx, bool need_exprstate);
154 
156 
157 extern bool DomainHasConstraints(Oid type_id);
158 
159 extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
160 
161 extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod,
162  bool noError);
163 
164 extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
165 
166 extern void assign_record_type_typmod(TupleDesc tupDesc);
167 
168 extern int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
169 
170 extern size_t SharedRecordTypmodRegistryEstimate(void);
171 
173  dsm_segment *segment, dsa_area *area);
174 
176 
177 #endif /* TYPCACHE_H */
int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2)
Definition: typcache.c:2057
MemoryContextCallback callback
Definition: typcache.h:145
signed short int16
Definition: c.h:245
struct TypeCacheEnumData * enumData
Definition: typcache.h:107
Definition: fmgr.h:56
FmgrInfo rng_cmp_proc_finfo
Definition: typcache.h:90
DomainConstraintCache * dcc
Definition: typcache.h:144
TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod)
Definition: typcache.c:1613
Oid hash_opintype
Definition: typcache.h:55
DomainConstraintCache * domainData
Definition: typcache.h:98
void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref, MemoryContext refctx, bool need_exprstate)
Definition: typcache.c:1165
struct TypeCacheEntry TypeCacheEntry
size_t SharedRecordTypmodRegistryEstimate(void)
Definition: typcache.c:1719
unsigned int Oid
Definition: postgres_ext.h:31
int16 typlen
Definition: typcache.h:37
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1579
bool typbyval
Definition: typcache.h:38
signed int int32
Definition: c.h:246
FmgrInfo rng_subdiff_finfo
Definition: typcache.h:92
FmgrInfo cmp_proc_finfo
Definition: typcache.h:71
struct TypeCacheEntry * nextDomain
Definition: typcache.h:110
void UpdateDomainConstraintRef(DomainConstraintRef *ref)
Definition: typcache.c:1203
void assign_record_type_typmod(TupleDesc tupDesc)
Definition: typcache.c:1652
char typstorage
Definition: typcache.h:40
void SharedRecordTypmodRegistryAttach(SharedRecordTypmodRegistry *)
Definition: typcache.c:1840
Oid hash_extended_proc
Definition: typcache.h:61
FmgrInfo hash_proc_finfo
Definition: typcache.h:72
FmgrInfo rng_canonical_finfo
Definition: typcache.h:91
MemoryContext refctx
Definition: typcache.h:139
struct TypeCacheEntry * rngelemtype
Definition: typcache.h:88
struct DomainConstraintRef DomainConstraintRef
FmgrInfo hash_extended_proc_finfo
Definition: typcache.h:73
Oid btree_opintype
Definition: typcache.h:53
FmgrInfo eq_opr_finfo
Definition: typcache.h:70
char typtype
Definition: typcache.h:41
bool DomainHasConstraints(Oid type_id)
Definition: typcache.c:1252
void SharedRecordTypmodRegistryInit(SharedRecordTypmodRegistry *, dsm_segment *segment, dsa_area *area)
Definition: typcache.c:1741
TypeCacheEntry * tcache
Definition: typcache.h:140
Oid rng_collation
Definition: typcache.h:89
Definition: dsa.c:354
char typalign
Definition: typcache.h:39
Definition: pg_list.h:45
TupleDesc tupDesc
Definition: typcache.h:80
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:310
TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1596