typcache.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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-2016, 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. #include "access/tupdesc.h"
  19. #include "fmgr.h"
  20. /* DomainConstraintCache is an opaque struct known only within typcache.c */
  21. typedef struct DomainConstraintCache DomainConstraintCache;
  22. /* TypeCacheEnumData is an opaque struct known only within typcache.c */
  23. struct TypeCacheEnumData;
  24. typedef struct TypeCacheEntry
  25. {
  26. /* typeId is the hash lookup key and MUST BE FIRST */
  27. Oid type_id; /* OID of the data type */
  28. /* some subsidiary information copied from the pg_type row */
  29. int16 typlen;
  30. bool typbyval;
  31. char typalign;
  32. char typstorage;
  33. char typtype;
  34. Oid typrelid;
  35. /*
  36. * Information obtained from opfamily entries
  37. *
  38. * These will be InvalidOid if no match could be found, or if the
  39. * information hasn't yet been requested. Also note that for array and
  40. * composite types, typcache.c checks that the contained types are
  41. * comparable or hashable before allowing eq_opr etc to become set.
  42. */
  43. Oid btree_opf; /* the default btree opclass' family */
  44. Oid btree_opintype; /* the default btree opclass' opcintype */
  45. Oid hash_opf; /* the default hash opclass' family */
  46. Oid hash_opintype; /* the default hash opclass' opcintype */
  47. Oid eq_opr; /* the equality operator */
  48. Oid lt_opr; /* the less-than operator */
  49. Oid gt_opr; /* the greater-than operator */
  50. Oid cmp_proc; /* the btree comparison function */
  51. Oid hash_proc; /* the hash calculation function */
  52. /*
  53. * Pre-set-up fmgr call info for the equality operator, the btree
  54. * comparison function, and the hash calculation function. These are kept
  55. * in the type cache to avoid problems with memory leaks in repeated calls
  56. * to functions such as array_eq, array_cmp, hash_array. There is not
  57. * currently a need to maintain call info for the lt_opr or gt_opr.
  58. */
  59. FmgrInfo eq_opr_finfo;
  60. FmgrInfo cmp_proc_finfo;
  61. FmgrInfo hash_proc_finfo;
  62. /*
  63. * Tuple descriptor if it's a composite type (row type). NULL if not
  64. * composite or information hasn't yet been requested. (NOTE: this is a
  65. * reference-counted tupledesc.)
  66. */
  67. TupleDesc tupDesc;
  68. /*
  69. * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not
  70. * a range type or information hasn't yet been requested. Note that
  71. * rng_cmp_proc_finfo could be different from the element type's default
  72. * btree comparison function.
  73. */
  74. struct TypeCacheEntry *rngelemtype; /* range's element type */
  75. Oid rng_collation; /* collation for comparisons, if any */
  76. FmgrInfo rng_cmp_proc_finfo; /* comparison function */
  77. FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */
  78. FmgrInfo rng_subdiff_finfo; /* difference function, if any */
  79. /*
  80. * Domain constraint data if it's a domain type. NULL if not domain, or
  81. * if domain has no constraints, or if information hasn't been requested.
  82. */
  83. DomainConstraintCache *domainData;
  84. /* Private data, for internal use of typcache.c only */
  85. int flags; /* flags about what we've computed */
  86. /*
  87. * Private information about an enum type. NULL if not enum or
  88. * information hasn't been requested.
  89. */
  90. struct TypeCacheEnumData *enumData;
  91. /* We also maintain a list of all known domain-type cache entries */
  92. struct TypeCacheEntry *nextDomain;
  93. } TypeCacheEntry;
  94. /* Bit flags to indicate which fields a given caller needs to have set */
  95. #define TYPECACHE_EQ_OPR 0x0001
  96. #define TYPECACHE_LT_OPR 0x0002
  97. #define TYPECACHE_GT_OPR 0x0004
  98. #define TYPECACHE_CMP_PROC 0x0008
  99. #define TYPECACHE_HASH_PROC 0x0010
  100. #define TYPECACHE_EQ_OPR_FINFO 0x0020
  101. #define TYPECACHE_CMP_PROC_FINFO 0x0040
  102. #define TYPECACHE_HASH_PROC_FINFO 0x0080
  103. #define TYPECACHE_TUPDESC 0x0100
  104. #define TYPECACHE_BTREE_OPFAMILY 0x0200
  105. #define TYPECACHE_HASH_OPFAMILY 0x0400
  106. #define TYPECACHE_RANGE_INFO 0x0800
  107. #define TYPECACHE_DOMAIN_INFO 0x1000
  108. /*
  109. * Callers wishing to maintain a long-lived reference to a domain's constraint
  110. * set must store it in one of these. Use InitDomainConstraintRef() and
  111. * UpdateDomainConstraintRef() to manage it. Note: DomainConstraintState is
  112. * considered an executable expression type, so it's defined in execnodes.h.
  113. */
  114. typedef struct DomainConstraintRef
  115. {
  116. List *constraints; /* list of DomainConstraintState nodes */
  117. MemoryContext refctx; /* context holding DomainConstraintRef */
  118. TypeCacheEntry *tcache; /* typcache entry for domain type */
  119. /* Management data --- treat these fields as private to typcache.c */
  120. DomainConstraintCache *dcc; /* current constraints, or NULL if none */
  121. MemoryContextCallback callback; /* used to release refcount when done */
  122. } DomainConstraintRef;
  123. extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
  124. extern void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref,
  125. MemoryContext refctx);
  126. extern void UpdateDomainConstraintRef(DomainConstraintRef *ref);
  127. extern bool DomainHasConstraints(Oid type_id);
  128. extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
  129. extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod,
  130. bool noError);
  131. extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
  132. extern void assign_record_type_typmod(TupleDesc tupDesc);
  133. extern int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
  134. #endif /* TYPCACHE_H */