]> granicus.if.org Git - postgresql/blob - src/include/utils/typcache.h
Add 'ignore_nulls' option to row_to_json
[postgresql] / src / include / utils / typcache.h
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-2014, 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
22
23 /* TypeCacheEnumData is an opaque struct known only within typcache.c */
24 struct TypeCacheEnumData;
25
26 typedef struct TypeCacheEntry
27 {
28         /* typeId is the hash lookup key and MUST BE FIRST */
29         Oid                     type_id;                /* OID of the data type */
30
31         /* some subsidiary information copied from the pg_type row */
32         int16           typlen;
33         bool            typbyval;
34         char            typalign;
35         char            typstorage;
36         char            typtype;
37         Oid                     typrelid;
38
39         /*
40          * Information obtained from opfamily entries
41          *
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.
46          */
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 */
56
57         /*
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.
63          */
64         FmgrInfo        eq_opr_finfo;
65         FmgrInfo        cmp_proc_finfo;
66         FmgrInfo        hash_proc_finfo;
67
68         /*
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.)
72          */
73         TupleDesc       tupDesc;
74
75         /*
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.
80          */
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 */
86
87         /* Private data, for internal use of typcache.c only */
88         int                     flags;                  /* flags about what we've computed */
89
90         /*
91          * Private information about an enum type.  NULL if not enum or
92          * information hasn't been requested.
93          */
94         struct TypeCacheEnumData *enumData;
95 } TypeCacheEntry;
96
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
110
111 extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
112
113 extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
114
115 extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod,
116                                                            bool noError);
117
118 extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
119
120 extern void assign_record_type_typmod(TupleDesc tupDesc);
121
122 extern int      compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
123
124 #endif   /* TYPCACHE_H */