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#include "storage/lock.h"
27
28/* types supported by reloptions */
38
39/* kinds supported by reloptions */
40typedef enum relopt_kind
41{
43 RELOPT_KIND_HEAP = (1 << 0),
46 RELOPT_KIND_HASH = (1 << 3),
47 RELOPT_KIND_GIN = (1 << 4),
48 RELOPT_KIND_GIST = (1 << 5),
52 RELOPT_KIND_VIEW = (1 << 9),
53 RELOPT_KIND_BRIN = (1 << 10),
55 /* if you add a new kind, make sure you update "last_default" too */
57 /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
58 RELOPT_KIND_MAX = (1 << 30)
60
61/* reloption namespaces allowed for heaps -- currently only TOAST */
62#define HEAP_RELOPT_NAMESPACES { "toast", NULL }
63
64/* generic struct to hold shared data */
65typedef struct relopt_gen
66{
67 const char *name; /* must be first (used as list termination
68 * marker) */
69 const char *desc;
75
76/* holds a parsed value */
77typedef struct relopt_value
78{
80 bool isset;
81 union
82 {
86 double real_val;
88 char *string_val; /* allocated separately */
89 };
91
92/* reloptions records for specific variable types */
98
99typedef struct relopt_ternary
100{
102 /* ternaries have no default_val: otherwise they'd just be bools */
104
112
113typedef struct relopt_real
114{
117 double min;
118 double max;
120
121/*
122 * relopt_enum_elt_def -- One member of the array of acceptable values
123 * of an enum reloption.
124 */
130
131typedef struct relopt_enum
132{
136 const char *detailmsg;
137 /* null-terminated array of members */
139
140/* validation routines for strings */
141typedef void (*validate_string_relopt) (const char *value);
142typedef Size (*fill_string_relopt) (const char *value, void *ptr);
143
144/* validation routine for the whole option set */
146
156
157/* This is the table datatype for build_reloptions() */
158typedef struct
159{
160 const char *optname; /* option's name */
161 relopt_type opttype; /* option's datatype */
162 int offset; /* offset of field in result struct */
164
165/* Local reloption definition */
166typedef struct local_relopt
167{
168 relopt_gen *option; /* option definition */
169 int offset; /* offset of parsed value in bytea structure */
171
172/* Structure to hold local reloption data for build_local_reloptions() */
173typedef struct local_relopts
174{
175 List *options; /* list of local_relopt definitions */
176 List *validators; /* list of relopts_validator callbacks */
177 Size relopt_struct_size; /* size of parsed bytea structure */
179
180/*
181 * Utility macro to get a value for a string reloption once the options
182 * are parsed. This gets a pointer to the string value itself. "optstruct"
183 * is the StdRdOptions struct or equivalent, "member" is the struct member
184 * corresponding to the string option.
185 */
186#define GET_STRING_RELOPTION(optstruct, member) \
187 ((optstruct)->member == 0 ? NULL : \
188 (char *)(optstruct) + (optstruct)->member)
189
191extern void add_bool_reloption(bits32 kinds, const char *name, const char *desc,
192 bool default_val, LOCKMODE lockmode);
193extern void add_ternary_reloption(bits32 kinds, const char *name,
194 const char *desc, LOCKMODE lockmode);
195extern void add_int_reloption(bits32 kinds, const char *name, const char *desc,
196 int default_val, int min_val, int max_val,
197 LOCKMODE lockmode);
198extern void add_real_reloption(bits32 kinds, const char *name, const char *desc,
199 double default_val, double min_val, double max_val,
200 LOCKMODE lockmode);
201extern void add_enum_reloption(bits32 kinds, const char *name, const char *desc,
202 relopt_enum_elt_def *members, int default_val,
203 const char *detailmsg, LOCKMODE lockmode);
204extern void add_string_reloption(bits32 kinds, const char *name, const char *desc,
205 const char *default_val, validate_string_relopt validator,
206 LOCKMODE lockmode);
207
208extern void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size);
211extern void add_local_bool_reloption(local_relopts *relopts, const char *name,
212 const char *desc, bool default_val,
213 int offset);
215 const char *name, const char *desc,
216 int offset);
217extern void add_local_int_reloption(local_relopts *relopts, const char *name,
218 const char *desc, int default_val,
219 int min_val, int max_val, int offset);
220extern void add_local_real_reloption(local_relopts *relopts, const char *name,
221 const char *desc, double default_val,
222 double min_val, double max_val,
223 int offset);
225 const char *name, const char *desc,
226 relopt_enum_elt_def *members,
227 int default_val, const char *detailmsg,
228 int offset);
229extern void add_local_string_reloption(local_relopts *relopts, const char *name,
230 const char *desc,
231 const char *default_val,
233 fill_string_relopt filler, int offset);
234
236 const char *nameSpace, const char *const validnsps[],
237 bool acceptOidsOff, bool isReset);
239extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
240 amoptions_function amoptions);
241extern void *build_reloptions(Datum reloptions, bool validate,
242 relopt_kind kind,
243 Size relopt_struct_size,
245 int num_relopt_elems);
247 bool validate);
248
249extern bytea *default_reloptions(Datum reloptions, bool validate,
250 relopt_kind kind);
251extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
252extern bytea *view_reloptions(Datum reloptions, bool validate);
253extern bytea *partitioned_table_reloptions(Datum reloptions, bool validate);
254extern bytea *index_reloptions(amoptions_function amoptions, Datum reloptions,
255 bool validate);
256extern bytea *attribute_reloptions(Datum reloptions, bool validate);
257extern bytea *tablespace_reloptions(Datum reloptions, bool validate);
259
260#endif /* RELOPTIONS_H */
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition amapi.h:165
static bool validate(Port *port, const char *auth)
Definition auth-oauth.c:638
uint32 bits32
Definition c.h:555
size_t Size
Definition c.h:619
static struct @172 value
int LOCKMODE
Definition lockdefs.h:26
pg_ternary
Definition postgres.h:554
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)
void add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
bytea * tablespace_reloptions(Datum reloptions, bool validate)
void add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
List * untransformRelOptions(Datum options)
Size(* fill_string_relopt)(const char *value, void *ptr)
Definition reloptions.h:142
bytea * view_reloptions(Datum reloptions, bool validate)
relopt_kind
Definition reloptions.h:41
@ RELOPT_KIND_LAST_DEFAULT
Definition reloptions.h:56
@ RELOPT_KIND_ATTRIBUTE
Definition reloptions.h:49
@ RELOPT_KIND_TOAST
Definition reloptions.h:44
@ RELOPT_KIND_LOCAL
Definition reloptions.h:42
@ RELOPT_KIND_SPGIST
Definition reloptions.h:51
@ RELOPT_KIND_MAX
Definition reloptions.h:58
@ RELOPT_KIND_GIST
Definition reloptions.h:48
@ RELOPT_KIND_VIEW
Definition reloptions.h:52
@ RELOPT_KIND_HEAP
Definition reloptions.h:43
@ RELOPT_KIND_TABLESPACE
Definition reloptions.h:50
@ RELOPT_KIND_GIN
Definition reloptions.h:47
@ RELOPT_KIND_HASH
Definition reloptions.h:46
@ RELOPT_KIND_PARTITIONED
Definition reloptions.h:54
@ RELOPT_KIND_BRIN
Definition reloptions.h:53
@ RELOPT_KIND_BTREE
Definition reloptions.h:45
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
void add_enum_reloption(bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
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_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
void add_local_bool_reloption(local_relopts *relopts, const char *name, const char *desc, bool default_val, int offset)
Definition reloptions.c:916
void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)
Definition reloptions.c:782
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:141
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition reloptions.c:900
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:731
void * build_local_reloptions(local_relopts *relopts, Datum options, bool validate)
void add_ternary_reloption(bits32 kinds, const char *name, const char *desc, LOCKMODE lockmode)
Definition reloptions.c:947
void register_reloptions_validator(local_relopts *relopts, relopts_validator validator)
Definition reloptions.c:795
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:965
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(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition reloptions.h:145
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
relopt_type
Definition reloptions.h:30
@ RELOPT_TYPE_ENUM
Definition reloptions.h:35
@ RELOPT_TYPE_INT
Definition reloptions.h:33
@ RELOPT_TYPE_TERNARY
Definition reloptions.h:32
@ RELOPT_TYPE_BOOL
Definition reloptions.h:31
@ RELOPT_TYPE_REAL
Definition reloptions.h:34
@ RELOPT_TYPE_STRING
Definition reloptions.h:36
Definition pg_list.h:54
relopt_gen * option
Definition reloptions.h:168
List * validators
Definition reloptions.h:176
Size relopt_struct_size
Definition reloptions.h:177
bool default_val
Definition reloptions.h:96
relopt_gen gen
Definition reloptions.h:95
const char * string_val
Definition reloptions.h:127
const char * detailmsg
Definition reloptions.h:136
relopt_gen gen
Definition reloptions.h:133
relopt_enum_elt_def * members
Definition reloptions.h:134
const char * desc
Definition reloptions.h:69
bits32 kinds
Definition reloptions.h:70
const char * name
Definition reloptions.h:67
LOCKMODE lockmode
Definition reloptions.h:71
relopt_type type
Definition reloptions.h:73
int default_val
Definition reloptions.h:108
relopt_gen gen
Definition reloptions.h:107
const char * optname
Definition reloptions.h:160
relopt_type opttype
Definition reloptions.h:161
relopt_gen gen
Definition reloptions.h:115
double default_val
Definition reloptions.h:116
char * default_val
Definition reloptions.h:154
validate_string_relopt validate_cb
Definition reloptions.h:152
fill_string_relopt fill_cb
Definition reloptions.h:153
bool default_isnull
Definition reloptions.h:151
relopt_gen gen
Definition reloptions.h:149
relopt_gen gen
Definition reloptions.h:101
relopt_gen * gen
Definition reloptions.h:79
pg_ternary ternary_val
Definition reloptions.h:84
double real_val
Definition reloptions.h:86
char * string_val
Definition reloptions.h:88
Definition c.h:706
const char * name