PostgreSQL Source Code git master
Loading...
Searching...
No Matches
reloptions.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * reloptions.h
4 * Core support for relation and tablespace options (pg_class.reloptions
5 * and pg_tablespace.spcoptions)
6 *
7 * Note: the functions dealing with text-array reloptions values declare
8 * them as Datum, not ArrayType *, to avoid needing to include array.h
9 * into a lot of low-level code.
10 *
11 *
12 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
13 * Portions Copyright (c) 1994, Regents of the University of California
14 *
15 * src/include/access/reloptions.h
16 *
17 *-------------------------------------------------------------------------
18 */
19#ifndef RELOPTIONS_H
20#define RELOPTIONS_H
21
22#include "access/amapi.h"
23#include "access/htup.h"
24#include "access/tupdesc.h"
25#include "nodes/pg_list.h"
26
27/* types supported by reloptions */
37
38/* kinds supported by reloptions */
39typedef enum relopt_kind
40{
42 RELOPT_KIND_HEAP = (1 << 0),
45 RELOPT_KIND_HASH = (1 << 3),
46 RELOPT_KIND_GIN = (1 << 4),
47 RELOPT_KIND_GIST = (1 << 5),
51 RELOPT_KIND_VIEW = (1 << 9),
52 RELOPT_KIND_BRIN = (1 << 10),
54 /* if you add a new kind, make sure you update "last_default" too */
56 /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
57 RELOPT_KIND_MAX = (1 << 30)
59
60/* reloption namespaces allowed for heaps -- currently only TOAST */
61#define HEAP_RELOPT_NAMESPACES { "toast", NULL }
62
63/* generic struct to hold shared data */
64typedef struct relopt_gen
65{
66 const char *name; /* must be first (used as list termination
67 * marker) */
68 const char *desc;
74
75/* holds a parsed value */
76typedef struct relopt_value
77{
79 bool isset;
80 union
81 {
85 double real_val;
87 char *string_val; /* allocated separately */
88 };
90
91/* reloptions records for specific variable types */
97
98typedef struct relopt_ternary
99{
101 /* ternaries have no default_val: otherwise they'd just be bools */
103
111
112typedef struct relopt_real
113{
116 double min;
117 double max;
119
120/*
121 * relopt_enum_elt_def -- One member of the array of acceptable values
122 * of an enum reloption.
123 */
129
130typedef struct relopt_enum
131{
135 const char *detailmsg;
136 /* null-terminated array of members */
138
139/* validation routines for strings */
140typedef void (*validate_string_relopt) (const char *value);
141typedef Size (*fill_string_relopt) (const char *value, void *ptr);
142
143/* validation routine for the whole option set */
145
155
156/* This is the table datatype for build_reloptions() */
157typedef struct
158{
159 const char *optname; /* option's name */
160 relopt_type opttype; /* option's datatype */
161 int offset; /* offset of field in result struct */
163
164/* Local reloption definition */
165typedef struct local_relopt
166{
167 relopt_gen *option; /* option definition */
168 int offset; /* offset of parsed value in bytea structure */
170
171/* Structure to hold local reloption data for build_local_reloptions() */
172typedef struct local_relopts
173{
174 List *options; /* list of local_relopt definitions */
175 List *validators; /* list of relopts_validator callbacks */
176 Size relopt_struct_size; /* size of parsed bytea structure */
178
179/*
180 * Utility macro to get a value for a string reloption once the options
181 * are parsed. This gets a pointer to the string value itself. "optstruct"
182 * is the StdRdOptions struct or equivalent, "member" is the struct member
183 * corresponding to the string option.
184 */
185#define GET_STRING_RELOPTION(optstruct, member) \
186 ((optstruct)->member == 0 ? NULL : \
187 (char *)(optstruct) + (optstruct)->member)
188
190extern void add_bool_reloption(uint32 kinds, const char *name, const char *desc,
191 bool default_val, LOCKMODE lockmode);
192extern void add_ternary_reloption(uint32 kinds, const char *name,
193 const char *desc, LOCKMODE lockmode);
194extern void add_int_reloption(uint32 kinds, const char *name, const char *desc,
195 int default_val, int min_val, int max_val,
196 LOCKMODE lockmode);
197extern void add_real_reloption(uint32 kinds, const char *name, const char *desc,
198 double default_val, double min_val, double max_val,
199 LOCKMODE lockmode);
200extern void add_enum_reloption(uint32 kinds, const char *name, const char *desc,
201 relopt_enum_elt_def *members, int default_val,
202 const char *detailmsg, LOCKMODE lockmode);
203extern void add_string_reloption(uint32 kinds, const char *name, const char *desc,
204 const char *default_val, validate_string_relopt validator,
205 LOCKMODE lockmode);
206
207extern void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size);
210extern void add_local_bool_reloption(local_relopts *relopts, const char *name,
211 const char *desc, bool default_val,
212 int offset);
214 const char *name, const char *desc,
215 int offset);
216extern void add_local_int_reloption(local_relopts *relopts, const char *name,
217 const char *desc, int default_val,
218 int min_val, int max_val, int offset);
219extern void add_local_real_reloption(local_relopts *relopts, const char *name,
220 const char *desc, double default_val,
221 double min_val, double max_val,
222 int offset);
224 const char *name, const char *desc,
225 relopt_enum_elt_def *members,
226 int default_val, const char *detailmsg,
227 int offset);
228extern void add_local_string_reloption(local_relopts *relopts, const char *name,
229 const char *desc,
230 const char *default_val,
232 fill_string_relopt filler, int offset);
233
235 const char *nameSpace, const char *const validnsps[],
236 bool acceptOidsOff, bool isReset);
238extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
239 amoptions_function amoptions);
240extern void *build_reloptions(Datum reloptions, bool validate,
241 relopt_kind kind,
242 Size relopt_struct_size,
244 int num_relopt_elems);
246 bool validate);
247
248extern bytea *default_reloptions(Datum reloptions, bool validate,
249 relopt_kind kind);
250extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
251extern bytea *view_reloptions(Datum reloptions, bool validate);
252extern bytea *partitioned_table_reloptions(Datum reloptions, bool validate);
253extern bytea *index_reloptions(amoptions_function amoptions, Datum reloptions,
254 bool validate);
255extern bytea *attribute_reloptions(Datum reloptions, bool validate);
256extern bytea *tablespace_reloptions(Datum reloptions, bool validate);
258
259#endif /* RELOPTIONS_H */
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition amapi.h:165
static bool validate(Port *port, const char *auth, const char **logdetail)
Definition auth-oauth.c:672
uint32_t uint32
Definition c.h:624
size_t Size
Definition c.h:689
static struct @177 value
int LOCKMODE
Definition lockdefs.h:26
pg_ternary
Definition postgres.h:544
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
tree ctl max_val
Definition radixtree.h:1859
void add_local_string_reloption(local_relopts *relopts, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, int offset)
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
void add_ternary_reloption(uint32 kinds, const char *name, const char *desc, LOCKMODE lockmode)
Definition reloptions.c:957
void add_int_reloption(uint32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
bytea * tablespace_reloptions(Datum reloptions, bool validate)
List * untransformRelOptions(Datum options)
Size(* fill_string_relopt)(const char *value, void *ptr)
Definition reloptions.h:141
void add_bool_reloption(uint32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition reloptions.c:910
void add_enum_reloption(uint32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
bytea * view_reloptions(Datum reloptions, bool validate)
relopt_kind
Definition reloptions.h:40
@ RELOPT_KIND_LAST_DEFAULT
Definition reloptions.h:55
@ RELOPT_KIND_ATTRIBUTE
Definition reloptions.h:48
@ RELOPT_KIND_TOAST
Definition reloptions.h:43
@ RELOPT_KIND_LOCAL
Definition reloptions.h:41
@ RELOPT_KIND_SPGIST
Definition reloptions.h:50
@ RELOPT_KIND_MAX
Definition reloptions.h:57
@ RELOPT_KIND_GIST
Definition reloptions.h:47
@ RELOPT_KIND_VIEW
Definition reloptions.h:51
@ RELOPT_KIND_HEAP
Definition reloptions.h:42
@ RELOPT_KIND_TABLESPACE
Definition reloptions.h:49
@ RELOPT_KIND_GIN
Definition reloptions.h:46
@ RELOPT_KIND_HASH
Definition reloptions.h:45
@ RELOPT_KIND_PARTITIONED
Definition reloptions.h:53
@ RELOPT_KIND_BRIN
Definition reloptions.h:52
@ RELOPT_KIND_BTREE
Definition reloptions.h:44
void add_real_reloption(uint32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
void add_local_bool_reloption(local_relopts *relopts, const char *name, const char *desc, bool default_val, int offset)
Definition reloptions.c:926
void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)
Definition reloptions.c:792
void add_local_real_reloption(local_relopts *relopts, const char *name, const char *desc, double default_val, double min_val, double max_val, int offset)
void(* validate_string_relopt)(const char *value)
Definition reloptions.h:140
Datum transformRelOptions(Datum oldOptions, List *defList, const char *nameSpace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
void add_local_enum_reloption(local_relopts *relopts, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, int offset)
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
relopt_kind add_reloption_kind(void)
Definition reloptions.c:741
void * build_local_reloptions(local_relopts *relopts, Datum options, bool validate)
void register_reloptions_validator(local_relopts *relopts, relopts_validator validator)
Definition reloptions.c:805
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
bytea * attribute_reloptions(Datum reloptions, bool validate)
void add_local_ternary_reloption(local_relopts *relopts, const char *name, const char *desc, int offset)
Definition reloptions.c:975
void add_local_int_reloption(local_relopts *relopts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)
void add_string_reloption(uint32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition reloptions.h:144
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
relopt_type
Definition reloptions.h:29
@ RELOPT_TYPE_ENUM
Definition reloptions.h:34
@ RELOPT_TYPE_INT
Definition reloptions.h:32
@ RELOPT_TYPE_TERNARY
Definition reloptions.h:31
@ RELOPT_TYPE_BOOL
Definition reloptions.h:30
@ RELOPT_TYPE_REAL
Definition reloptions.h:33
@ RELOPT_TYPE_STRING
Definition reloptions.h:35
Definition pg_list.h:54
relopt_gen * option
Definition reloptions.h:167
List * validators
Definition reloptions.h:175
Size relopt_struct_size
Definition reloptions.h:176
bool default_val
Definition reloptions.h:95
relopt_gen gen
Definition reloptions.h:94
const char * string_val
Definition reloptions.h:126
const char * detailmsg
Definition reloptions.h:135
relopt_gen gen
Definition reloptions.h:132
relopt_enum_elt_def * members
Definition reloptions.h:133
const char * desc
Definition reloptions.h:68
uint32 kinds
Definition reloptions.h:69
const char * name
Definition reloptions.h:66
LOCKMODE lockmode
Definition reloptions.h:70
relopt_type type
Definition reloptions.h:72
int default_val
Definition reloptions.h:107
relopt_gen gen
Definition reloptions.h:106
const char * optname
Definition reloptions.h:159
relopt_type opttype
Definition reloptions.h:160
relopt_gen gen
Definition reloptions.h:114
double default_val
Definition reloptions.h:115
char * default_val
Definition reloptions.h:153
validate_string_relopt validate_cb
Definition reloptions.h:151
fill_string_relopt fill_cb
Definition reloptions.h:152
bool default_isnull
Definition reloptions.h:150
relopt_gen gen
Definition reloptions.h:148
relopt_gen gen
Definition reloptions.h:100
relopt_gen * gen
Definition reloptions.h:78
pg_ternary ternary_val
Definition reloptions.h:83
double real_val
Definition reloptions.h:85
char * string_val
Definition reloptions.h:87
Definition c.h:776
const char * name