PostgreSQL Source Code  git master
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * lsyscache.h
4  * Convenience routines for common queries in the system catalog cache.
5  *
6  * Portions Copyright (c) 1996-2024, 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
16 #include "access/attnum.h"
17 #include "access/htup.h"
18 #include "nodes/pg_list.h"
20 /* avoid including subscripting.h here */
21 struct SubscriptRoutines;
23 /* Result list element for get_op_btree_interpretation */
24 typedef struct OpBtreeInterpretation
25 {
26  Oid opfamily_id; /* btree opfamily containing operator */
27  int strategy; /* its strategy number */
28  Oid oplefttype; /* declared left input datatype */
29  Oid oprighttype; /* declared right input datatype */
32 /* I/O function selector for get_type_io_data */
33 typedef enum IOFuncSelector
34 {
41 /* Flag bits for get_attstatsslot */
45 /* Result struct for get_attstatsslot */
46 typedef struct AttStatsSlot
47 {
48  /* Always filled: */
49  Oid staop; /* Actual staop for the found slot */
50  Oid stacoll; /* Actual collation for the found slot */
51  /* Filled if ATTSTATSSLOT_VALUES is specified: */
52  Oid valuetype; /* Actual datatype of the values */
53  Datum *values; /* slot's "values" array, or NULL if none */
54  int nvalues; /* length of values[], or 0 */
55  /* Filled if ATTSTATSSLOT_NUMBERS is specified: */
56  float4 *numbers; /* slot's "numbers" array, or NULL if none */
57  int nnumbers; /* length of numbers[], or 0 */
59  /* Remaining fields are private to get_attstatsslot/free_attstatsslot */
60  void *values_arr; /* palloc'd values array, if any */
61  void *numbers_arr; /* palloc'd numbers array, if any */
64 /* Hook for plugins to get control in get_attavgwidth() */
68 extern bool op_in_opfamily(Oid opno, Oid opfamily);
69 extern int get_op_opfamily_strategy(Oid opno, Oid opfamily);
70 extern Oid get_op_opfamily_sortfamily(Oid opno, Oid opfamily);
71 extern void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op,
72  int *strategy,
73  Oid *lefttype,
74  Oid *righttype);
75 extern Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype,
76  int16 strategy);
77 extern bool get_ordering_op_properties(Oid opno,
78  Oid *opfamily, Oid *opcintype, int16 *strategy);
79 extern Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse);
80 extern Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type);
81 extern List *get_mergejoin_opfamilies(Oid opno);
82 extern bool get_compatible_hash_operators(Oid opno,
83  Oid *lhs_opno, Oid *rhs_opno);
84 extern bool get_op_hash_functions(Oid opno,
85  RegProcedure *lhs_procno, RegProcedure *rhs_procno);
87 extern bool equality_ops_are_compatible(Oid opno1, Oid opno2);
88 extern bool comparison_ops_are_compatible(Oid opno1, Oid opno2);
89 extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype,
90  int16 procnum);
91 extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok);
92 extern AttrNumber get_attnum(Oid relid, const char *attname);
93 extern char get_attgenerated(Oid relid, AttrNumber attnum);
94 extern Oid get_atttype(Oid relid, AttrNumber attnum);
95 extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
96  Oid *typid, int32 *typmod, Oid *collid);
97 extern Datum get_attoptions(Oid relid, int16 attnum);
98 extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
99 extern char *get_collation_name(Oid colloid);
100 extern bool get_collation_isdeterministic(Oid colloid);
101 extern char *get_constraint_name(Oid conoid);
102 extern Oid get_constraint_index(Oid conoid);
103 extern char get_constraint_type(Oid conoid);
105 extern char *get_language_name(Oid langoid, bool missing_ok);
106 extern Oid get_opclass_family(Oid opclass);
107 extern Oid get_opclass_input_type(Oid opclass);
108 extern bool get_opclass_opfamily_and_input_type(Oid opclass,
109  Oid *opfamily, Oid *opcintype);
110 extern Oid get_opclass_method(Oid opclass);
111 extern RegProcedure get_opcode(Oid opno);
112 extern char *get_opname(Oid opno);
113 extern Oid get_op_rettype(Oid opno);
114 extern void op_input_types(Oid opno, Oid *lefttype, Oid *righttype);
115 extern bool op_mergejoinable(Oid opno, Oid inputtype);
116 extern bool op_hashjoinable(Oid opno, Oid inputtype);
117 extern bool op_strict(Oid opno);
118 extern char op_volatile(Oid opno);
119 extern Oid get_commutator(Oid opno);
120 extern Oid get_negator(Oid opno);
121 extern RegProcedure get_oprrest(Oid opno);
122 extern RegProcedure get_oprjoin(Oid opno);
123 extern char *get_func_name(Oid funcid);
124 extern Oid get_func_namespace(Oid funcid);
125 extern Oid get_func_rettype(Oid funcid);
126 extern int get_func_nargs(Oid funcid);
127 extern Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs);
128 extern Oid get_func_variadictype(Oid funcid);
129 extern bool get_func_retset(Oid funcid);
130 extern bool func_strict(Oid funcid);
131 extern char func_volatile(Oid funcid);
132 extern char func_parallel(Oid funcid);
133 extern char get_func_prokind(Oid funcid);
134 extern bool get_func_leakproof(Oid funcid);
135 extern RegProcedure get_func_support(Oid funcid);
136 extern Oid get_relname_relid(const char *relname, Oid relnamespace);
137 extern char *get_rel_name(Oid relid);
138 extern Oid get_rel_namespace(Oid relid);
139 extern Oid get_rel_type_id(Oid relid);
140 extern char get_rel_relkind(Oid relid);
141 extern bool get_rel_relispartition(Oid relid);
142 extern Oid get_rel_tablespace(Oid relid);
143 extern char get_rel_persistence(Oid relid);
144 extern Oid get_rel_relam(Oid relid);
145 extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes);
146 extern Oid get_transform_tosql(Oid typid, Oid langid, List *trftypes);
147 extern bool get_typisdefined(Oid typid);
148 extern int16 get_typlen(Oid typid);
149 extern bool get_typbyval(Oid typid);
150 extern void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval);
151 extern void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,
152  char *typalign);
153 extern Oid getTypeIOParam(HeapTuple typeTuple);
154 extern void get_type_io_data(Oid typid,
155  IOFuncSelector which_func,
156  int16 *typlen,
157  bool *typbyval,
158  char *typalign,
159  char *typdelim,
160  Oid *typioparam,
161  Oid *func);
162 extern char get_typstorage(Oid typid);
163 extern Node *get_typdefault(Oid typid);
164 extern char get_typtype(Oid typid);
165 extern bool type_is_rowtype(Oid typid);
166 extern bool type_is_enum(Oid typid);
167 extern bool type_is_range(Oid typid);
168 extern bool type_is_multirange(Oid typid);
169 extern void get_type_category_preferred(Oid typid,
170  char *typcategory,
171  bool *typispreferred);
172 extern Oid get_typ_typrelid(Oid typid);
173 extern Oid get_element_type(Oid typid);
174 extern Oid get_array_type(Oid typid);
175 extern Oid get_promoted_array_type(Oid typid);
176 extern Oid get_base_element_type(Oid typid);
177 extern void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam);
178 extern void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena);
179 extern void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam);
180 extern void getTypeBinaryOutputInfo(Oid type, Oid *typSend, bool *typIsVarlena);
181 extern Oid get_typmodin(Oid typid);
182 extern Oid get_typcollation(Oid typid);
183 extern bool type_is_collatable(Oid typid);
184 extern RegProcedure get_typsubscript(Oid typid, Oid *typelemp);
185 extern const struct SubscriptRoutines *getSubscriptingRoutines(Oid typid,
186  Oid *typelemp);
187 extern Oid getBaseType(Oid typid);
188 extern Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod);
189 extern int32 get_typavgwidth(Oid typid, int32 typmod);
190 extern int32 get_attavgwidth(Oid relid, AttrNumber attnum);
191 extern bool get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple,
192  int reqkind, Oid reqop, int flags);
193 extern void free_attstatsslot(AttStatsSlot *sslot);
194 extern char *get_namespace_name(Oid nspid);
195 extern char *get_namespace_name_or_temp(Oid nspid);
196 extern Oid get_range_subtype(Oid rangeOid);
197 extern Oid get_range_collation(Oid rangeOid);
198 extern Oid get_range_multirange(Oid rangeOid);
199 extern Oid get_multirange_range(Oid multirangeOid);
200 extern Oid get_index_column_opclass(Oid index_oid, int attno);
201 extern bool get_index_isreplident(Oid index_oid);
202 extern bool get_index_isvalid(Oid index_oid);
203 extern bool get_index_isclustered(Oid index_oid);
204 extern Oid get_publication_oid(const char *pubname, bool missing_ok);
205 extern char *get_publication_name(Oid pubid, bool missing_ok);
206 extern Oid get_subscription_oid(const char *subname, bool missing_ok);
207 extern char *get_subscription_name(Oid subid, bool missing_ok);
209 #define type_is_array(typid) (get_element_type(typid) != InvalidOid)
210 /* type_is_array_domain accepts both plain arrays and domains over arrays */
211 #define type_is_array_domain(typid) (get_base_element_type(typid) != InvalidOid)
213 #define TypeIsToastable(typid) (get_typstorage(typid) != TYPSTORAGE_PLAIN)
215 #endif /* LSYSCACHE_H */
int16 AttrNumber
Definition: attnum.h:21
Definition: c.h:1316
signed short int16
Definition: c.h:493
signed int int32
Definition: c.h:494
regproc RegProcedure
Definition: c.h:650
float float4
Definition: c.h:629
int nspid
Oid collid
Oid get_range_subtype(Oid rangeOid)
Definition: lsyscache.c:3407
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
Definition: lsyscache.c:136
Oid get_func_variadictype(Oid funcid)
Definition: lsyscache.c:1723
Oid get_opclass_method(Oid opclass)
Definition: lsyscache.c:1260
bool get_compatible_hash_operators(Oid opno, Oid *lhs_opno, Oid *rhs_opno)
Definition: lsyscache.c:410
bool get_rel_relispartition(Oid relid)
Definition: lsyscache.c:2027
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1161
Oid get_op_opfamily_sortfamily(Oid opno, Oid opfamily)
Definition: lsyscache.c:108
char get_rel_persistence(Oid relid)
Definition: lsyscache.c:2078
char get_func_prokind(Oid funcid)
Definition: lsyscache.c:1818
char * get_opname(Oid opno)
Definition: lsyscache.c:1310
bool get_index_isvalid(Oid index_oid)
Definition: lsyscache.c:3578
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition: lsyscache.c:1007
void getTypeBinaryOutputInfo(Oid type, Oid *typSend, bool *typIsVarlena)
Definition: lsyscache.c:2973
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:858
RegProcedure get_oprrest(Oid opno)
Definition: lsyscache.c:1557
void free_attstatsslot(AttStatsSlot *sslot)
Definition: lsyscache.c:3344
List * get_mergejoin_opfamilies(Oid opno)
Definition: lsyscache.c:366
bool comparison_ops_are_compatible(Oid opno1, Oid opno2)
Definition: lsyscache.c:749
Oid get_constraint_index(Oid conoid)
Definition: lsyscache.c:1113
bool get_func_retset(Oid funcid)
Definition: lsyscache.c:1742
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2759
Oid get_opclass_input_type(Oid opclass)
Definition: lsyscache.c:1212
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3390
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2655
bool type_is_range(Oid typid)
Definition: lsyscache.c:2688
char func_parallel(Oid funcid)
Definition: lsyscache.c:1799
Oid get_opclass_family(Oid opclass)
Definition: lsyscache.c:1190
char get_attgenerated(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:888
bool type_is_enum(Oid typid)
Definition: lsyscache.c:2678
Oid get_multirange_range(Oid multirangeOid)
Definition: lsyscache.c:3483
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
Oid get_typmodin(Oid typid)
Definition: lsyscache.c:3006
char get_typstorage(Oid typid)
Definition: lsyscache.c:2419
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
Definition: lsyscache.c:1235
RegProcedure get_func_support(Oid funcid)
Definition: lsyscache.c:1858
PGDLLIMPORT get_attavgwidth_hook_type get_attavgwidth_hook
Definition: lsyscache.c:53
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2907
struct OpBtreeInterpretation OpBtreeInterpretation
bool get_typisdefined(Oid typid)
Definition: lsyscache.c:2173
Datum get_attoptions(Oid relid, int16 attnum)
Definition: lsyscache.c:970
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2271
int32 get_attavgwidth(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:3158
bool get_index_isreplident(Oid index_oid)
Definition: lsyscache.c:3555
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition: lsyscache.c:796
RegProcedure get_oprjoin(Oid opno)
Definition: lsyscache.c:1581
Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse)
Definition: lsyscache.c:267
bool op_strict(Oid opno)
Definition: lsyscache.c:1477
bool op_hashjoinable(Oid opno, Oid inputtype)
Definition: lsyscache.c:1437
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:2003
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2251
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
Definition: lsyscache.c:1696
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition: lsyscache.c:3625
char * get_publication_name(Oid pubid, bool missing_ok)
Definition: lsyscache.c:3645
Oid get_rel_namespace(Oid relid)
Definition: lsyscache.c:1952
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1285
Oid get_typcollation(Oid typid)
Definition: lsyscache.c:3056
Oid get_op_rettype(Oid opno)
Definition: lsyscache.c:1333
int get_op_opfamily_strategy(Oid opno, Oid opfamily)
Definition: lsyscache.c:83
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1979
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1928
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition: lsyscache.c:2874
char func_volatile(Oid funcid)
Definition: lsyscache.c:1780
bool equality_ops_are_compatible(Oid opno1, Oid opno2)
Definition: lsyscache.c:698
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1608
bool get_index_isclustered(Oid index_oid)
Definition: lsyscache.c:3601
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition: lsyscache.c:166
char * get_collation_name(Oid colloid)
Definition: lsyscache.c:1035
Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type)
Definition: lsyscache.c:305
Oid get_transform_tosql(Oid typid, Oid langid, List *trftypes)
Definition: lsyscache.c:2142
bool func_strict(Oid funcid)
Definition: lsyscache.c:1761
Oid get_index_column_opclass(Oid index_oid, int attno)
Definition: lsyscache.c:3512
bool get_ordering_op_properties(Oid opno, Oid *opfamily, Oid *opcintype, int16 *strategy)
Definition: lsyscache.c:207
bool get_func_leakproof(Oid funcid)
Definition: lsyscache.c:1837
List * get_op_btree_interpretation(Oid opno)
Definition: lsyscache.c:601
char * get_constraint_name(Oid conoid)
Definition: lsyscache.c:1081
bool get_collation_isdeterministic(Oid colloid)
Definition: lsyscache.c:1054
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition: lsyscache.c:3675
Oid get_range_collation(Oid rangeOid)
Definition: lsyscache.c:3433
Oid get_range_multirange(Oid rangeOid)
Definition: lsyscache.c:3458
Oid get_rel_relam(Oid relid)
Definition: lsyscache.c:2100
char op_volatile(Oid opno)
Definition: lsyscache.c:1493
Oid get_func_namespace(Oid funcid)
Definition: lsyscache.c:1632
bool type_is_collatable(Oid typid)
Definition: lsyscache.c:3081
Oid get_rel_tablespace(Oid relid)
Definition: lsyscache.c:2054
Definition: lsyscache.h:34
@ IOFunc_output
Definition: lsyscache.h:36
@ IOFunc_input
Definition: lsyscache.h:35
@ IOFunc_send
Definition: lsyscache.h:38
@ IOFunc_receive
Definition: lsyscache.h:37
int get_func_nargs(Oid funcid)
Definition: lsyscache.c:1674
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
Definition: lsyscache.c:2325
int16 get_typlen(Oid typid)
Definition: lsyscache.c:2197
Oid get_typ_typrelid(Oid typid)
Definition: lsyscache.c:2731
Node * get_typdefault(Oid typid)
Definition: lsyscache.c:2448
char get_typtype(Oid typid)
Definition: lsyscache.c:2629
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2832
Oid getTypeIOParam(HeapTuple typeTuple)
Definition: lsyscache.c:2303
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2538
Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes)
Definition: lsyscache.c:2120
const struct SubscriptRoutines * getSubscriptingRoutines(Oid typid, Oid *typelemp)
Definition: lsyscache.c:3130
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2521
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
Definition: lsyscache.c:510
bool get_typbyval(Oid typid)
Definition: lsyscache.c:2222
struct AttStatsSlot AttStatsSlot
bool op_mergejoinable(Oid opno, Oid inputtype)
Definition: lsyscache.c:1386
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2787
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1655
char * get_subscription_name(Oid subid, bool missing_ok)
Definition: lsyscache.c:3695
Oid get_promoted_array_type(Oid typid)
Definition: lsyscache.c:2811
Oid get_atttype(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:913
int32(* get_attavgwidth_hook_type)(Oid relid, AttrNumber attnum)
Definition: lsyscache.h:65
char get_constraint_type(Oid conoid)
Definition: lsyscache.c:1143
int32 get_typavgwidth(Oid typid, int32 typmod)
Definition: lsyscache.c:2578
bool op_in_opfamily(Oid opno, Oid opfamily)
Definition: lsyscache.c:66
RegProcedure get_typsubscript(Oid typid, Oid *typelemp)
Definition: lsyscache.c:3097
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
Definition: lsyscache.c:2710
bool get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple, int reqkind, Oid reqop, int flags)
Definition: lsyscache.c:3234
Oid get_relname_relid(const char *relname, Oid relnamespace)
Definition: lsyscache.c:1885
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:827
Oid get_negator(Oid opno)
Definition: lsyscache.c:1533
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1509
void op_input_types(Oid opno, Oid *lefttype, Oid *righttype)
Definition: lsyscache.c:1358
bool type_is_multirange(Oid typid)
Definition: lsyscache.c:2698
void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam)
Definition: lsyscache.c:2940
void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, Oid *typid, int32 *typmod, Oid *collid)
Definition: lsyscache.c:943
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:74
NameData relname
Definition: pg_class.h:38
NameData subname
char typalign
Definition: pg_type.h:176
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
Oid valuetype
Definition: lsyscache.h:52
Datum * values
Definition: lsyscache.h:53
void * numbers_arr
Definition: lsyscache.h:61
float4 * numbers
Definition: lsyscache.h:56
int nnumbers
Definition: lsyscache.h:57
void * values_arr
Definition: lsyscache.h:60
Definition: pg_list.h:54
Definition: nodes.h:129
const char * type