00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef RELOPTIONS_H
00020 #define RELOPTIONS_H
00021
00022 #include "access/htup.h"
00023 #include "access/tupdesc.h"
00024 #include "nodes/pg_list.h"
00025
00026
00027 typedef enum relopt_type
00028 {
00029 RELOPT_TYPE_BOOL,
00030 RELOPT_TYPE_INT,
00031 RELOPT_TYPE_REAL,
00032 RELOPT_TYPE_STRING
00033 } relopt_type;
00034
00035
00036 typedef enum relopt_kind
00037 {
00038 RELOPT_KIND_HEAP = (1 << 0),
00039 RELOPT_KIND_TOAST = (1 << 1),
00040 RELOPT_KIND_BTREE = (1 << 2),
00041 RELOPT_KIND_HASH = (1 << 3),
00042 RELOPT_KIND_GIN = (1 << 4),
00043 RELOPT_KIND_GIST = (1 << 5),
00044 RELOPT_KIND_ATTRIBUTE = (1 << 6),
00045 RELOPT_KIND_TABLESPACE = (1 << 7),
00046 RELOPT_KIND_SPGIST = (1 << 8),
00047 RELOPT_KIND_VIEW = (1 << 9),
00048
00049 RELOPT_KIND_LAST_DEFAULT = RELOPT_KIND_VIEW,
00050
00051 RELOPT_KIND_MAX = (1 << 30)
00052 } relopt_kind;
00053
00054
00055 #define HEAP_RELOPT_NAMESPACES { "toast", NULL }
00056
00057
00058 typedef struct relopt_gen
00059 {
00060 const char *name;
00061
00062 const char *desc;
00063 bits32 kinds;
00064 int namelen;
00065 relopt_type type;
00066 } relopt_gen;
00067
00068
00069 typedef struct relopt_value
00070 {
00071 relopt_gen *gen;
00072 bool isset;
00073 union
00074 {
00075 bool bool_val;
00076 int int_val;
00077 double real_val;
00078 char *string_val;
00079 } values;
00080 } relopt_value;
00081
00082
00083 typedef struct relopt_bool
00084 {
00085 relopt_gen gen;
00086 bool default_val;
00087 } relopt_bool;
00088
00089 typedef struct relopt_int
00090 {
00091 relopt_gen gen;
00092 int default_val;
00093 int min;
00094 int max;
00095 } relopt_int;
00096
00097 typedef struct relopt_real
00098 {
00099 relopt_gen gen;
00100 double default_val;
00101 double min;
00102 double max;
00103 } relopt_real;
00104
00105
00106 typedef void (*validate_string_relopt) (char *value);
00107
00108 typedef struct relopt_string
00109 {
00110 relopt_gen gen;
00111 int default_len;
00112 bool default_isnull;
00113 validate_string_relopt validate_cb;
00114 char *default_val;
00115 } relopt_string;
00116
00117
00118 typedef struct
00119 {
00120 const char *optname;
00121 relopt_type opttype;
00122 int offset;
00123 } relopt_parse_elt;
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 #define HAVE_RELOPTION(optname, option) \
00164 (pg_strncasecmp(option.gen->name, optname, option.gen->namelen + 1) == 0)
00165
00166 #define HANDLE_INT_RELOPTION(optname, var, option, wasset) \
00167 do { \
00168 if (option.isset) \
00169 var = option.values.int_val; \
00170 else \
00171 var = ((relopt_int *) option.gen)->default_val; \
00172 (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \
00173 } while (0)
00174
00175 #define HANDLE_BOOL_RELOPTION(optname, var, option, wasset) \
00176 do { \
00177 if (option.isset) \
00178 var = option.values.bool_val; \
00179 else \
00180 var = ((relopt_bool *) option.gen)->default_val; \
00181 (wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
00182 } while (0)
00183
00184 #define HANDLE_REAL_RELOPTION(optname, var, option, wasset) \
00185 do { \
00186 if (option.isset) \
00187 var = option.values.real_val; \
00188 else \
00189 var = ((relopt_real *) option.gen)->default_val; \
00190 (wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
00191 } while (0)
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 #define HANDLE_STRING_RELOPTION(optname, var, option, base, offset, wasset) \
00205 do { \
00206 relopt_string *optstring = (relopt_string *) option.gen;\
00207 char *string_val; \
00208 if (option.isset) \
00209 string_val = option.values.string_val; \
00210 else if (!optstring->default_isnull) \
00211 string_val = optstring->default_val; \
00212 else \
00213 string_val = NULL; \
00214 (wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
00215 if (string_val == NULL) \
00216 var = 0; \
00217 else \
00218 { \
00219 strcpy(((char *)(base)) + (offset), string_val); \
00220 var = (offset); \
00221 (offset) += strlen(string_val) + 1; \
00222 } \
00223 } while (0)
00224
00225
00226
00227
00228
00229 #define GET_STRING_RELOPTION_LEN(option) \
00230 ((option).isset ? strlen((option).values.string_val) : \
00231 ((relopt_string *) (option).gen)->default_len)
00232
00233
00234
00235
00236
00237
00238 #define GET_STRING_RELOPTION(optstruct, member) \
00239 ((optstruct)->member == 0 ? NULL : \
00240 (char *)(optstruct) + (optstruct)->member)
00241
00242
00243 extern relopt_kind add_reloption_kind(void);
00244 extern void add_bool_reloption(bits32 kinds, char *name, char *desc,
00245 bool default_val);
00246 extern void add_int_reloption(bits32 kinds, char *name, char *desc,
00247 int default_val, int min_val, int max_val);
00248 extern void add_real_reloption(bits32 kinds, char *name, char *desc,
00249 double default_val, double min_val, double max_val);
00250 extern void add_string_reloption(bits32 kinds, char *name, char *desc,
00251 char *default_val, validate_string_relopt validator);
00252
00253 extern Datum transformRelOptions(Datum oldOptions, List *defList,
00254 char *namspace, char *validnsps[],
00255 bool ignoreOids, bool isReset);
00256 extern List *untransformRelOptions(Datum options);
00257 extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
00258 Oid amoptions);
00259 extern relopt_value *parseRelOptions(Datum options, bool validate,
00260 relopt_kind kind, int *numrelopts);
00261 extern void *allocateReloptStruct(Size base, relopt_value *options,
00262 int numoptions);
00263 extern void fillRelOptions(void *rdopts, Size basesize,
00264 relopt_value *options, int numoptions,
00265 bool validate,
00266 const relopt_parse_elt *elems, int nelems);
00267
00268 extern bytea *default_reloptions(Datum reloptions, bool validate,
00269 relopt_kind kind);
00270 extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
00271 extern bytea *index_reloptions(RegProcedure amoptions, Datum reloptions,
00272 bool validate);
00273 extern bytea *attribute_reloptions(Datum reloptions, bool validate);
00274 extern bytea *tablespace_reloptions(Datum reloptions, bool validate);
00275
00276 #endif