lsyscache.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*-------------------------------------------------------------------------
  2. *
  3. * lsyscache.h
  4. * Convenience routines for common queries in the system catalog cache.
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/utils/lsyscache.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef LSYSCACHE_H
  14. #define LSYSCACHE_H
  15. #include "access/attnum.h"
  16. #include "access/htup.h"
  17. #include "nodes/pg_list.h"
  18. /* avoid including subscripting.h here */
  19. struct SubscriptRoutines;
  20. /* Result list element for get_op_btree_interpretation */
  21. typedef struct OpBtreeInterpretation
  22. {
  23. Oid opfamily_id; /* btree opfamily containing operator */
  24. int strategy; /* its strategy number */
  25. Oid oplefttype; /* declared left input datatype */
  26. Oid oprighttype; /* declared right input datatype */
  27. } OpBtreeInterpretation;
  28. /* I/O function selector for get_type_io_data */
  29. typedef enum IOFuncSelector
  30. {
  31. IOFunc_input,
  32. IOFunc_output,
  33. IOFunc_receive,
  34. IOFunc_send
  35. } IOFuncSelector;
  36. /* Flag bits for get_attstatsslot */
  37. #define ATTSTATSSLOT_VALUES 0x01
  38. #define ATTSTATSSLOT_NUMBERS 0x02
  39. /* Result struct for get_attstatsslot */
  40. typedef struct AttStatsSlot
  41. {
  42. /* Always filled: */
  43. Oid staop; /* Actual staop for the found slot */
  44. Oid stacoll; /* Actual collation for the found slot */
  45. /* Filled if ATTSTATSSLOT_VALUES is specified: */
  46. Oid valuetype; /* Actual datatype of the values */
  47. Datum *values; /* slot's "values" array, or NULL if none */
  48. int nvalues; /* length of values[], or 0 */
  49. /* Filled if ATTSTATSSLOT_NUMBERS is specified: */
  50. float4 *numbers; /* slot's "numbers" array, or NULL if none */
  51. int nnumbers; /* length of numbers[], or 0 */
  52. /* Remaining fields are private to get_attstatsslot/free_attstatsslot */
  53. void *values_arr; /* palloc'd values array, if any */
  54. void *numbers_arr; /* palloc'd numbers array, if any */
  55. } AttStatsSlot;
  56. /* Hook for plugins to get control in get_attavgwidth() */
  57. typedef int32 (*get_attavgwidth_hook_type) (Oid relid, AttrNumber attnum);
  58. extern PGDLLIMPORT get_attavgwidth_hook_type get_attavgwidth_hook;
  59. extern bool op_in_opfamily(Oid opno, Oid opfamily);
  60. extern int get_op_opfamily_strategy(Oid opno, Oid opfamily);
  61. extern Oid get_op_opfamily_sortfamily(Oid opno, Oid opfamily);
  62. extern void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op,
  63. int *strategy,
  64. Oid *lefttype,
  65. Oid *righttype);
  66. extern Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype,
  67. int16 strategy);
  68. extern bool get_ordering_op_properties(Oid opno,
  69. Oid *opfamily, Oid *opcintype, int16 *strategy);
  70. extern Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse);
  71. extern Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type);
  72. extern List *get_mergejoin_opfamilies(Oid opno);
  73. extern bool get_compatible_hash_operators(Oid opno,
  74. Oid *lhs_opno, Oid *rhs_opno);
  75. extern bool get_op_hash_functions(Oid opno,
  76. RegProcedure *lhs_procno, RegProcedure *rhs_procno);
  77. extern List *get_op_btree_interpretation(Oid opno);
  78. extern bool equality_ops_are_compatible(Oid opno1, Oid opno2);
  79. extern bool comparison_ops_are_compatible(Oid opno1, Oid opno2);
  80. extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype,
  81. int16 procnum);
  82. extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok);
  83. extern AttrNumber get_attnum(Oid relid, const char *attname);
  84. extern int get_attstattarget(Oid relid, AttrNumber attnum);
  85. extern char get_attgenerated(Oid relid, AttrNumber attnum);
  86. extern Oid get_atttype(Oid relid, AttrNumber attnum);
  87. extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
  88. Oid *typid, int32 *typmod, Oid *collid);
  89. extern Datum get_attoptions(Oid relid, int16 attnum);
  90. extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
  91. extern char *get_collation_name(Oid colloid);
  92. extern bool get_collation_isdeterministic(Oid colloid);
  93. extern char *get_constraint_name(Oid conoid);
  94. extern Oid get_constraint_index(Oid conoid);
  95. extern char *get_language_name(Oid langoid, bool missing_ok);
  96. extern Oid get_opclass_family(Oid opclass);
  97. extern Oid get_opclass_input_type(Oid opclass);
  98. extern bool get_opclass_opfamily_and_input_type(Oid opclass,
  99. Oid *opfamily, Oid *opcintype);
  100. extern RegProcedure get_opcode(Oid opno);
  101. extern char *get_opname(Oid opno);
  102. extern Oid get_op_rettype(Oid opno);
  103. extern void op_input_types(Oid opno, Oid *lefttype, Oid *righttype);
  104. extern bool op_mergejoinable(Oid opno, Oid inputtype);
  105. extern bool op_hashjoinable(Oid opno, Oid inputtype);
  106. extern bool op_strict(Oid opno);
  107. extern char op_volatile(Oid opno);
  108. extern Oid get_commutator(Oid opno);
  109. extern Oid get_negator(Oid opno);
  110. extern RegProcedure get_oprrest(Oid opno);
  111. extern RegProcedure get_oprjoin(Oid opno);
  112. extern char *get_func_name(Oid funcid);
  113. extern Oid get_func_namespace(Oid funcid);
  114. extern Oid get_func_rettype(Oid funcid);
  115. extern int get_func_nargs(Oid funcid);
  116. extern Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs);
  117. extern Oid get_func_variadictype(Oid funcid);
  118. extern bool get_func_retset(Oid funcid);
  119. extern bool func_strict(Oid funcid);
  120. extern char func_volatile(Oid funcid);
  121. extern char func_parallel(Oid funcid);
  122. extern char get_func_prokind(Oid funcid);
  123. extern bool get_func_leakproof(Oid funcid);
  124. extern RegProcedure get_func_support(Oid funcid);
  125. extern Oid get_relname_relid(const char *relname, Oid relnamespace);
  126. extern char *get_rel_name(Oid relid);
  127. extern Oid get_rel_namespace(Oid relid);
  128. extern Oid get_rel_type_id(Oid relid);
  129. extern char get_rel_relkind(Oid relid);
  130. extern bool get_rel_relispartition(Oid relid);
  131. extern Oid get_rel_tablespace(Oid relid);
  132. extern char get_rel_persistence(Oid relid);
  133. extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes);
  134. extern Oid get_transform_tosql(Oid typid, Oid langid, List *trftypes);
  135. extern bool get_typisdefined(Oid typid);
  136. extern int16 get_typlen(Oid typid);
  137. extern bool get_typbyval(Oid typid);
  138. extern void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval);
  139. extern void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,
  140. char *typalign);
  141. extern Oid getTypeIOParam(HeapTuple typeTuple);
  142. extern void get_type_io_data(Oid typid,
  143. IOFuncSelector which_func,
  144. int16 *typlen,
  145. bool *typbyval,
  146. char *typalign,
  147. char *typdelim,
  148. Oid *typioparam,
  149. Oid *func);
  150. extern char get_typstorage(Oid typid);
  151. extern Node *get_typdefault(Oid typid);
  152. extern char get_typtype(Oid typid);
  153. extern bool type_is_rowtype(Oid typid);
  154. extern bool type_is_enum(Oid typid);
  155. extern bool type_is_range(Oid typid);
  156. extern bool type_is_multirange(Oid typid);
  157. extern void get_type_category_preferred(Oid typid,
  158. char *typcategory,
  159. bool *typispreferred);
  160. extern Oid get_typ_typrelid(Oid typid);
  161. extern Oid get_element_type(Oid typid);
  162. extern Oid get_array_type(Oid typid);
  163. extern Oid get_promoted_array_type(Oid typid);
  164. extern Oid get_base_element_type(Oid typid);
  165. extern void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam);
  166. extern void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena);
  167. extern void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam);
  168. extern void getTypeBinaryOutputInfo(Oid type, Oid *typSend, bool *typIsVarlena);
  169. extern Oid get_typmodin(Oid typid);
  170. extern Oid get_typcollation(Oid typid);
  171. extern bool type_is_collatable(Oid typid);
  172. extern RegProcedure get_typsubscript(Oid typid, Oid *typelemp);
  173. extern const struct SubscriptRoutines *getSubscriptingRoutines(Oid typid,
  174. Oid *typelemp);
  175. extern Oid getBaseType(Oid typid);
  176. extern Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod);
  177. extern int32 get_typavgwidth(Oid typid, int32 typmod);
  178. extern int32 get_attavgwidth(Oid relid, AttrNumber attnum);
  179. extern bool get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple,
  180. int reqkind, Oid reqop, int flags);
  181. extern void free_attstatsslot(AttStatsSlot *sslot);
  182. extern char *get_namespace_name(Oid nspid);
  183. extern char *get_namespace_name_or_temp(Oid nspid);
  184. extern Oid get_range_subtype(Oid rangeOid);
  185. extern Oid get_range_collation(Oid rangeOid);
  186. extern Oid get_range_multirange(Oid rangeOid);
  187. extern Oid get_multirange_range(Oid multirangeOid);
  188. extern Oid get_index_column_opclass(Oid index_oid, int attno);
  189. extern bool get_index_isreplident(Oid index_oid);
  190. extern bool get_index_isvalid(Oid index_oid);
  191. extern bool get_index_isclustered(Oid index_oid);
  192. #define type_is_array(typid) (get_element_type(typid) != InvalidOid)
  193. /* type_is_array_domain accepts both plain arrays and domains over arrays */
  194. #define type_is_array_domain(typid) (get_base_element_type(typid) != InvalidOid)
  195. #define TypeIsToastable(typid) (get_typstorage(typid) != TYPSTORAGE_PLAIN)
  196. #endif /* LSYSCACHE_H */