Header And Logo

PostgreSQL
| The world's most advanced open source database.

typcache.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * typcache.h
00004  *    Type cache definitions.
00005  *
00006  * The type cache exists to speed lookup of certain information about data
00007  * types that is not directly available from a type's pg_type row.
00008  *
00009  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00010  * Portions Copyright (c) 1994, Regents of the University of California
00011  *
00012  * src/include/utils/typcache.h
00013  *
00014  *-------------------------------------------------------------------------
00015  */
00016 #ifndef TYPCACHE_H
00017 #define TYPCACHE_H
00018 
00019 #include "access/tupdesc.h"
00020 #include "fmgr.h"
00021 
00022 
00023 /* TypeCacheEnumData is an opaque struct known only within typcache.c */
00024 struct TypeCacheEnumData;
00025 
00026 typedef struct TypeCacheEntry
00027 {
00028     /* typeId is the hash lookup key and MUST BE FIRST */
00029     Oid         type_id;        /* OID of the data type */
00030 
00031     /* some subsidiary information copied from the pg_type row */
00032     int16       typlen;
00033     bool        typbyval;
00034     char        typalign;
00035     char        typstorage;
00036     char        typtype;
00037     Oid         typrelid;
00038 
00039     /*
00040      * Information obtained from opfamily entries
00041      *
00042      * These will be InvalidOid if no match could be found, or if the
00043      * information hasn't yet been requested.  Also note that for array and
00044      * composite types, typcache.c checks that the contained types are
00045      * comparable or hashable before allowing eq_opr etc to become set.
00046      */
00047     Oid         btree_opf;      /* the default btree opclass' family */
00048     Oid         btree_opintype; /* the default btree opclass' opcintype */
00049     Oid         hash_opf;       /* the default hash opclass' family */
00050     Oid         hash_opintype;  /* the default hash opclass' opcintype */
00051     Oid         eq_opr;         /* the equality operator */
00052     Oid         lt_opr;         /* the less-than operator */
00053     Oid         gt_opr;         /* the greater-than operator */
00054     Oid         cmp_proc;       /* the btree comparison function */
00055     Oid         hash_proc;      /* the hash calculation function */
00056 
00057     /*
00058      * Pre-set-up fmgr call info for the equality operator, the btree
00059      * comparison function, and the hash calculation function.  These are kept
00060      * in the type cache to avoid problems with memory leaks in repeated calls
00061      * to functions such as array_eq, array_cmp, hash_array.  There is not
00062      * currently a need to maintain call info for the lt_opr or gt_opr.
00063      */
00064     FmgrInfo    eq_opr_finfo;
00065     FmgrInfo    cmp_proc_finfo;
00066     FmgrInfo    hash_proc_finfo;
00067 
00068     /*
00069      * Tuple descriptor if it's a composite type (row type).  NULL if not
00070      * composite or information hasn't yet been requested.  (NOTE: this is a
00071      * reference-counted tupledesc.)
00072      */
00073     TupleDesc   tupDesc;
00074 
00075     /*
00076      * Fields computed when TYPECACHE_RANGE_INFO is requested.  Zeroes if not
00077      * a range type or information hasn't yet been requested.  Note that
00078      * rng_cmp_proc_finfo could be different from the element type's default
00079      * btree comparison function.
00080      */
00081     struct TypeCacheEntry *rngelemtype; /* range's element type */
00082     Oid         rng_collation;  /* collation for comparisons, if any */
00083     FmgrInfo    rng_cmp_proc_finfo;     /* comparison function */
00084     FmgrInfo    rng_canonical_finfo;    /* canonicalization function, if any */
00085     FmgrInfo    rng_subdiff_finfo;      /* difference function, if any */
00086 
00087     /* Private data, for internal use of typcache.c only */
00088     int         flags;          /* flags about what we've computed */
00089 
00090     /*
00091      * Private information about an enum type.  NULL if not enum or
00092      * information hasn't been requested.
00093      */
00094     struct TypeCacheEnumData *enumData;
00095 } TypeCacheEntry;
00096 
00097 /* Bit flags to indicate which fields a given caller needs to have set */
00098 #define TYPECACHE_EQ_OPR            0x0001
00099 #define TYPECACHE_LT_OPR            0x0002
00100 #define TYPECACHE_GT_OPR            0x0004
00101 #define TYPECACHE_CMP_PROC          0x0008
00102 #define TYPECACHE_HASH_PROC         0x0010
00103 #define TYPECACHE_EQ_OPR_FINFO      0x0020
00104 #define TYPECACHE_CMP_PROC_FINFO    0x0040
00105 #define TYPECACHE_HASH_PROC_FINFO   0x0080
00106 #define TYPECACHE_TUPDESC           0x0100
00107 #define TYPECACHE_BTREE_OPFAMILY    0x0200
00108 #define TYPECACHE_HASH_OPFAMILY     0x0400
00109 #define TYPECACHE_RANGE_INFO        0x0800
00110 
00111 extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
00112 
00113 extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
00114 
00115 extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod,
00116                                bool noError);
00117 
00118 extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
00119 
00120 extern void assign_record_type_typmod(TupleDesc tupDesc);
00121 
00122 extern int  compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
00123 
00124 #endif   /* TYPCACHE_H */