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