PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2025, 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 */
29typedef enum relopt_type
30{
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 {
84 double real_val;
86 char *string_val; /* allocated separately */
89
90/* reloptions records for specific variable types */
91typedef struct relopt_bool
92{
96
97typedef struct relopt_int
98{
101 int min;
102 int max;
104
105typedef struct relopt_real
106{
109 double min;
110 double max;
112
113/*
114 * relopt_enum_elt_def -- One member of the array of acceptable values
115 * of an enum reloption.
116 */
118{
119 const char *string_val;
122
123typedef struct relopt_enum
124{
128 const char *detailmsg;
129 /* null-terminated array of members */
131
132/* validation routines for strings */
133typedef void (*validate_string_relopt) (const char *value);
134typedef Size (*fill_string_relopt) (const char *value, void *ptr);
135
136/* validation routine for the whole option set */
137typedef void (*relopts_validator) (void *parsed_options, relopt_value *vals, int nvals);
138
139typedef struct relopt_string
140{
148
149/* This is the table datatype for build_reloptions() */
150typedef struct
151{
152 const char *optname; /* option's name */
153 relopt_type opttype; /* option's datatype */
154 int offset; /* offset of field in result struct */
155
156 /*
157 * isset_offset is an optional offset of a field in the result struct that
158 * stores whether the option is explicitly set for the relation or if it
159 * just picked up the default value. In most cases, this can be
160 * accomplished by giving the reloption a special out-of-range default
161 * value (e.g., some integer reloptions use -2), but this isn't always
162 * possible. For example, a Boolean reloption cannot be given an
163 * out-of-range default, so we need another way to discover the source of
164 * its value. This offset is only used if given a value greater than
165 * zero.
166 */
169
170/* Local reloption definition */
171typedef struct local_relopt
172{
173 relopt_gen *option; /* option definition */
174 int offset; /* offset of parsed value in bytea structure */
176
177/* Structure to hold local reloption data for build_local_reloptions() */
178typedef struct local_relopts
179{
180 List *options; /* list of local_relopt definitions */
181 List *validators; /* list of relopts_validator callbacks */
182 Size relopt_struct_size; /* size of parsed bytea structure */
184
185/*
186 * Utility macro to get a value for a string reloption once the options
187 * are parsed. This gets a pointer to the string value itself. "optstruct"
188 * is the StdRdOptions struct or equivalent, "member" is the struct member
189 * corresponding to the string option.
190 */
191#define GET_STRING_RELOPTION(optstruct, member) \
192 ((optstruct)->member == 0 ? NULL : \
193 (char *)(optstruct) + (optstruct)->member)
194
196extern void add_bool_reloption(bits32 kinds, const char *name, const char *desc,
197 bool default_val, LOCKMODE lockmode);
198extern void add_int_reloption(bits32 kinds, const char *name, const char *desc,
199 int default_val, int min_val, int max_val,
200 LOCKMODE lockmode);
201extern void add_real_reloption(bits32 kinds, const char *name, const char *desc,
202 double default_val, double min_val, double max_val,
203 LOCKMODE lockmode);
204extern void add_enum_reloption(bits32 kinds, const char *name, const char *desc,
205 relopt_enum_elt_def *members, int default_val,
206 const char *detailmsg, LOCKMODE lockmode);
207extern void add_string_reloption(bits32 kinds, const char *name, const char *desc,
208 const char *default_val, validate_string_relopt validator,
209 LOCKMODE lockmode);
210
211extern void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size);
213 relopts_validator validator);
214extern void add_local_bool_reloption(local_relopts *relopts, const char *name,
215 const char *desc, bool default_val,
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);
224extern void add_local_enum_reloption(local_relopts *relopts,
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,
232 validate_string_relopt validator,
233 fill_string_relopt filler, int offset);
234
235extern Datum transformRelOptions(Datum oldOptions, List *defList,
236 const char *namspace, 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,
244 const relopt_parse_elt *relopt_elems,
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:163
static bool validate(Port *port, const char *auth)
Definition: auth-oauth.c:638
uint32 bits32
Definition: c.h:511
size_t Size
Definition: c.h:576
static struct @165 value
int LOCKMODE
Definition: lockdefs.h:26
uintptr_t Datum
Definition: postgres.h:69
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)
Definition: reloptions.c:1129
void add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:912
struct relopt_gen relopt_gen
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1860
bytea * tablespace_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2113
void add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
Definition: reloptions.c:1109
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:1167
struct relopt_real relopt_real
List * untransformRelOptions(Datum options)
Definition: reloptions.c:1342
Size(* fill_string_relopt)(const char *value, void *ptr)
Definition: reloptions.h:134
struct relopt_bool relopt_bool
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2025
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
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:2081
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)
Definition: reloptions.c:1029
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1934
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2011
void add_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:965
struct relopt_string relopt_string
void add_local_bool_reloption(local_relopts *relopts, const char *name, const char *desc, bool default_val, int offset)
Definition: reloptions.c:876
void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)
Definition: reloptions.c:745
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)
Definition: reloptions.c:983
void(* validate_string_relopt)(const char *value)
Definition: reloptions.h:133
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:860
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)
Definition: reloptions.c:1047
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
Definition: reloptions.c:1390
struct local_relopts local_relopts
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:694
struct relopt_enum relopt_enum
void * build_local_reloptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1971
void register_reloptions_validator(local_relopts *relopts, relopts_validator validator)
Definition: reloptions.c:758
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
Definition: reloptions.c:2135
bytea * attribute_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2096
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)
Definition: reloptions.c:929
struct relopt_value relopt_value
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition: reloptions.h:137
struct relopt_enum_elt_def relopt_enum_elt_def
struct relopt_int relopt_int
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:2046
relopt_type
Definition: reloptions.h:30
@ RELOPT_TYPE_ENUM
Definition: reloptions.h:34
@ RELOPT_TYPE_INT
Definition: reloptions.h:32
@ RELOPT_TYPE_BOOL
Definition: reloptions.h:31
@ RELOPT_TYPE_REAL
Definition: reloptions.h:33
@ RELOPT_TYPE_STRING
Definition: reloptions.h:35
struct local_relopt local_relopt
Definition: pg_list.h:54
relopt_gen * option
Definition: reloptions.h:173
List * validators
Definition: reloptions.h:181
List * options
Definition: reloptions.h:180
Size relopt_struct_size
Definition: reloptions.h:182
bool default_val
Definition: reloptions.h:94
relopt_gen gen
Definition: reloptions.h:93
const char * string_val
Definition: reloptions.h:119
int default_val
Definition: reloptions.h:127
const char * detailmsg
Definition: reloptions.h:128
relopt_gen gen
Definition: reloptions.h:125
relopt_enum_elt_def * members
Definition: reloptions.h:126
const char * desc
Definition: reloptions.h:68
bits32 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 namelen
Definition: reloptions.h:71
int default_val
Definition: reloptions.h:100
relopt_gen gen
Definition: reloptions.h:99
const char * optname
Definition: reloptions.h:152
relopt_type opttype
Definition: reloptions.h:153
relopt_gen gen
Definition: reloptions.h:107
double min
Definition: reloptions.h:109
double max
Definition: reloptions.h:110
double default_val
Definition: reloptions.h:108
char * default_val
Definition: reloptions.h:146
validate_string_relopt validate_cb
Definition: reloptions.h:144
fill_string_relopt fill_cb
Definition: reloptions.h:145
bool default_isnull
Definition: reloptions.h:143
relopt_gen gen
Definition: reloptions.h:141
relopt_gen * gen
Definition: reloptions.h:78
bool bool_val
Definition: reloptions.h:82
double real_val
Definition: reloptions.h:84
char * string_val
Definition: reloptions.h:86
union relopt_value::@48 values
Definition: c.h:658
const char * name