PostgreSQL Source Code  git master
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-2019, 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 */
29 typedef enum relopt_type
30 {
36 } relopt_type;
37 
38 /* kinds supported by reloptions */
39 typedef enum relopt_kind
40 {
41  RELOPT_KIND_HEAP = (1 << 0),
42  RELOPT_KIND_TOAST = (1 << 1),
43  RELOPT_KIND_BTREE = (1 << 2),
44  RELOPT_KIND_HASH = (1 << 3),
45  RELOPT_KIND_GIN = (1 << 4),
46  RELOPT_KIND_GIST = (1 << 5),
49  RELOPT_KIND_SPGIST = (1 << 8),
50  RELOPT_KIND_VIEW = (1 << 9),
51  RELOPT_KIND_BRIN = (1 << 10),
53  /* if you add a new kind, make sure you update "last_default" too */
55  /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
56  RELOPT_KIND_MAX = (1 << 30)
57 } relopt_kind;
58 
59 /* reloption namespaces allowed for heaps -- currently only TOAST */
60 #define HEAP_RELOPT_NAMESPACES { "toast", NULL }
61 
62 /* generic struct to hold shared data */
63 typedef struct relopt_gen
64 {
65  const char *name; /* must be first (used as list termination
66  * marker) */
67  const char *desc;
70  int namelen;
72 } relopt_gen;
73 
74 /* holds a parsed value */
75 typedef struct relopt_value
76 {
78  bool isset;
79  union
80  {
81  bool bool_val;
82  int int_val;
83  double real_val;
84  int enum_val;
85  char *string_val; /* allocated separately */
86  } values;
87 } relopt_value;
88 
89 /* reloptions records for specific variable types */
90 typedef struct relopt_bool
91 {
94 } relopt_bool;
95 
96 typedef struct relopt_int
97 {
100  int min;
101  int max;
102 } relopt_int;
103 
104 typedef struct relopt_real
105 {
107  double default_val;
108  double min;
109  double max;
110 } relopt_real;
111 
112 /*
113  * relopt_enum_elt_def -- One member of the array of acceptable values
114  * of an enum reloption.
115  */
116 typedef struct relopt_enum_elt_def
117 {
118  const char *string_val;
121 
122 typedef struct relopt_enum
123 {
127  const char *detailmsg;
128  /* null-terminated array of members */
129 } relopt_enum;
130 
131 /* validation routines for strings */
132 typedef void (*validate_string_relopt) (const char *value);
133 
134 typedef struct relopt_string
135 {
140  char *default_val;
141 } relopt_string;
142 
143 /* This is the table datatype for build_reloptions() */
144 typedef struct
145 {
146  const char *optname; /* option's name */
147  relopt_type opttype; /* option's datatype */
148  int offset; /* offset of field in result struct */
150 
151 /*
152  * Utility macro to get a value for a string reloption once the options
153  * are parsed. This gets a pointer to the string value itself. "optstruct"
154  * is the StdRdOptions struct or equivalent, "member" is the struct member
155  * corresponding to the string option.
156  */
157 #define GET_STRING_RELOPTION(optstruct, member) \
158  ((optstruct)->member == 0 ? NULL : \
159  (char *)(optstruct) + (optstruct)->member)
160 
161 extern relopt_kind add_reloption_kind(void);
162 extern void add_bool_reloption(bits32 kinds, const char *name, const char *desc,
163  bool default_val, LOCKMODE lockmode);
164 extern void add_int_reloption(bits32 kinds, const char *name, const char *desc,
165  int default_val, int min_val, int max_val,
167 extern void add_real_reloption(bits32 kinds, const char *name, const char *desc,
168  double default_val, double min_val, double max_val,
170 extern void add_enum_reloption(bits32 kinds, const char *name, const char *desc,
171  relopt_enum_elt_def *members, int default_val,
172  const char *detailmsg, LOCKMODE lockmode);
173 extern void add_string_reloption(bits32 kinds, const char *name, const char *desc,
174  const char *default_val, validate_string_relopt validator,
176 
177 extern Datum transformRelOptions(Datum oldOptions, List *defList,
178  const char *namspace, char *validnsps[],
179  bool acceptOidsOff, bool isReset);
181 extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
182  amoptions_function amoptions);
183 extern void *build_reloptions(Datum reloptions, bool validate,
184  relopt_kind kind,
185  Size relopt_struct_size,
186  const relopt_parse_elt *relopt_elems,
187  int num_relopt_elems);
188 
189 extern bytea *default_reloptions(Datum reloptions, bool validate,
190  relopt_kind kind);
191 extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
192 extern bytea *view_reloptions(Datum reloptions, bool validate);
193 extern bytea *partitioned_table_reloptions(Datum reloptions, bool validate);
194 extern bytea *index_reloptions(amoptions_function amoptions, Datum reloptions,
195  bool validate);
196 extern bytea *attribute_reloptions(Datum reloptions, bool validate);
197 extern bytea *tablespace_reloptions(Datum reloptions, bool validate);
199 
200 #endif /* RELOPTIONS_H */
bool bool_val
Definition: reloptions.h:81
relopt_type opttype
Definition: reloptions.h:147
List * untransformRelOptions(Datum options)
Definition: reloptions.c:1039
relopt_gen gen
Definition: reloptions.h:124
char * string_val
Definition: reloptions.h:85
struct relopt_string relopt_string
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1602
const char * desc
Definition: reloptions.h:67
int LOCKMODE
Definition: lockdefs.h:26
struct relopt_enum relopt_enum
struct relopt_value relopt_value
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:739
LOCKMODE lockmode
Definition: reloptions.h:69
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:758
static struct @145 value
bool default_isnull
Definition: reloptions.h:138
bool default_val
Definition: reloptions.h:93
relopt_gen gen
Definition: reloptions.h:136
relopt_gen * gen
Definition: reloptions.h:77
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1656
struct relopt_bool relopt_bool
char relkind
Definition: pg_class.h:81
struct relopt_real relopt_real
double default_val
Definition: reloptions.h:107
const char * detailmsg
Definition: reloptions.h:127
relopt_gen gen
Definition: reloptions.h:92
int namelen
Definition: reloptions.h:70
relopt_enum_elt_def * members
Definition: reloptions.h:125
struct relopt_gen relopt_gen
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:722
double real_val
Definition: reloptions.h:83
bytea * attribute_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1671
validate_string_relopt validate_cb
Definition: reloptions.h:139
bits32 kinds
Definition: reloptions.h:68
int default_val
Definition: reloptions.h:126
uintptr_t Datum
Definition: postgres.h:367
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1587
relopt_gen gen
Definition: reloptions.h:98
const char * optname
Definition: reloptions.h:146
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
Definition: reloptions.c:1709
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:863
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:810
uint32 bits32
Definition: c.h:368
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
Definition: reloptions.c:1088
void(* validate_string_relopt)(const char *value)
Definition: reloptions.h:132
relopt_type type
Definition: reloptions.h:71
relopt_type
Definition: reloptions.h:29
struct relopt_int relopt_int
struct relopt_enum_elt_def relopt_enum_elt_def
size_t Size
Definition: c.h:467
const char * string_val
Definition: reloptions.h:118
relopt_gen gen
Definition: reloptions.h:106
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:785
int default_val
Definition: reloptions.h:99
static Datum values[MAXATTR]
Definition: bootstrap.c:167
const char * name
Definition: reloptions.h:65
relopt_kind
Definition: reloptions.h:39
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1486
Definition: c.h:556
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition: amapi.h:103
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:1552
char * default_val
Definition: reloptions.h:140
double max
Definition: reloptions.h:109
Definition: pg_list.h:50
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:618
double min
Definition: reloptions.h:108
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1621
bytea * tablespace_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1688