PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
reloptions.h File Reference
#include "access/amapi.h"
#include "access/htup.h"
#include "access/tupdesc.h"
#include "nodes/pg_list.h"
#include "storage/lock.h"
Include dependency graph for reloptions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  relopt_gen
 
struct  relopt_value
 
struct  relopt_bool
 
struct  relopt_int
 
struct  relopt_real
 
struct  relopt_enum_elt_def
 
struct  relopt_enum
 
struct  relopt_string
 
struct  relopt_parse_elt
 
struct  local_relopt
 
struct  local_relopts
 

Macros

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }
 
#define GET_STRING_RELOPTION(optstruct, member)
 

Typedefs

typedef enum relopt_type relopt_type
 
typedef enum relopt_kind relopt_kind
 
typedef struct relopt_gen relopt_gen
 
typedef struct relopt_value relopt_value
 
typedef struct relopt_bool relopt_bool
 
typedef struct relopt_int relopt_int
 
typedef struct relopt_real relopt_real
 
typedef struct relopt_enum_elt_def relopt_enum_elt_def
 
typedef struct relopt_enum relopt_enum
 
typedef void(* validate_string_relopt) (const char *value)
 
typedef Size(* fill_string_relopt) (const char *value, void *ptr)
 
typedef void(* relopts_validator) (void *parsed_options, relopt_value *vals, int nvals)
 
typedef struct relopt_string relopt_string
 
typedef struct local_relopt local_relopt
 
typedef struct local_relopts local_relopts
 

Enumerations

enum  relopt_type {
  RELOPT_TYPE_BOOL , RELOPT_TYPE_INT , RELOPT_TYPE_REAL , RELOPT_TYPE_ENUM ,
  RELOPT_TYPE_STRING
}
 
enum  relopt_kind {
  RELOPT_KIND_LOCAL = 0 , RELOPT_KIND_HEAP = (1 << 0) , RELOPT_KIND_TOAST = (1 << 1) , RELOPT_KIND_BTREE = (1 << 2) ,
  RELOPT_KIND_HASH = (1 << 3) , RELOPT_KIND_GIN = (1 << 4) , RELOPT_KIND_GIST = (1 << 5) , RELOPT_KIND_ATTRIBUTE = (1 << 6) ,
  RELOPT_KIND_TABLESPACE = (1 << 7) , RELOPT_KIND_SPGIST = (1 << 8) , RELOPT_KIND_VIEW = (1 << 9) , RELOPT_KIND_BRIN = (1 << 10) ,
  RELOPT_KIND_PARTITIONED = (1 << 11) , RELOPT_KIND_LAST_DEFAULT = RELOPT_KIND_PARTITIONED , RELOPT_KIND_MAX = (1 << 30)
}
 

Functions

relopt_kind add_reloption_kind (void)
 
void add_bool_reloption (bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
 
void add_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
 
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_enum_reloption (bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
 
void add_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
 
void init_local_reloptions (local_relopts *relopts, Size relopt_struct_size)
 
void register_reloptions_validator (local_relopts *relopts, relopts_validator validator)
 
void add_local_bool_reloption (local_relopts *relopts, const char *name, const char *desc, bool default_val, int offset)
 
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_local_real_reloption (local_relopts *relopts, const char *name, const char *desc, double default_val, double min_val, double max_val, int offset)
 
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)
 
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)
 
Datum transformRelOptions (Datum oldOptions, List *defList, const char *nameSpace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
 
ListuntransformRelOptions (Datum options)
 
byteaextractRelOptions (HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
 
void * build_reloptions (Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
 
void * build_local_reloptions (local_relopts *relopts, Datum options, bool validate)
 
byteadefault_reloptions (Datum reloptions, bool validate, relopt_kind kind)
 
byteaheap_reloptions (char relkind, Datum reloptions, bool validate)
 
byteaview_reloptions (Datum reloptions, bool validate)
 
byteapartitioned_table_reloptions (Datum reloptions, bool validate)
 
byteaindex_reloptions (amoptions_function amoptions, Datum reloptions, bool validate)
 
byteaattribute_reloptions (Datum reloptions, bool validate)
 
byteatablespace_reloptions (Datum reloptions, bool validate)
 
LOCKMODE AlterTableGetRelOptionsLockLevel (List *defList)
 

Macro Definition Documentation

◆ GET_STRING_RELOPTION

#define GET_STRING_RELOPTION (   optstruct,
  member 
)
Value:
((optstruct)->member == 0 ? NULL : \
(char *)(optstruct) + (optstruct)->member)

Definition at line 191 of file reloptions.h.

◆ HEAP_RELOPT_NAMESPACES

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

Definition at line 61 of file reloptions.h.

Typedef Documentation

◆ fill_string_relopt

typedef Size(* fill_string_relopt) (const char *value, void *ptr)

Definition at line 134 of file reloptions.h.

◆ local_relopt

typedef struct local_relopt local_relopt

◆ local_relopts

typedef struct local_relopts local_relopts

◆ relopt_bool

typedef struct relopt_bool relopt_bool

◆ relopt_enum

typedef struct relopt_enum relopt_enum

◆ relopt_enum_elt_def

◆ relopt_gen

typedef struct relopt_gen relopt_gen

◆ relopt_int

typedef struct relopt_int relopt_int

◆ relopt_kind

typedef enum relopt_kind relopt_kind

◆ relopt_real

typedef struct relopt_real relopt_real

◆ relopt_string

typedef struct relopt_string relopt_string

◆ relopt_type

typedef enum relopt_type relopt_type

◆ relopt_value

typedef struct relopt_value relopt_value

◆ relopts_validator

typedef void(* relopts_validator) (void *parsed_options, relopt_value *vals, int nvals)

Definition at line 137 of file reloptions.h.

◆ validate_string_relopt

typedef void(* validate_string_relopt) (const char *value)

Definition at line 133 of file reloptions.h.

Enumeration Type Documentation

◆ relopt_kind

Enumerator
RELOPT_KIND_LOCAL 
RELOPT_KIND_HEAP 
RELOPT_KIND_TOAST 
RELOPT_KIND_BTREE 
RELOPT_KIND_HASH 
RELOPT_KIND_GIN 
RELOPT_KIND_GIST 
RELOPT_KIND_ATTRIBUTE 
RELOPT_KIND_TABLESPACE 
RELOPT_KIND_SPGIST 
RELOPT_KIND_VIEW 
RELOPT_KIND_BRIN 
RELOPT_KIND_PARTITIONED 
RELOPT_KIND_LAST_DEFAULT 
RELOPT_KIND_MAX 

Definition at line 39 of file reloptions.h.

40{
42 RELOPT_KIND_HEAP = (1 << 0),
43 RELOPT_KIND_TOAST = (1 << 1),
44 RELOPT_KIND_BTREE = (1 << 2),
45 RELOPT_KIND_HASH = (1 << 3),
46 RELOPT_KIND_GIN = (1 << 4),
47 RELOPT_KIND_GIST = (1 << 5),
48 RELOPT_KIND_ATTRIBUTE = (1 << 6),
49 RELOPT_KIND_TABLESPACE = (1 << 7),
50 RELOPT_KIND_SPGIST = (1 << 8),
51 RELOPT_KIND_VIEW = (1 << 9),
52 RELOPT_KIND_BRIN = (1 << 10),
53 RELOPT_KIND_PARTITIONED = (1 << 11),
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)
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

◆ relopt_type

Enumerator
RELOPT_TYPE_BOOL 
RELOPT_TYPE_INT 
RELOPT_TYPE_REAL 
RELOPT_TYPE_ENUM 
RELOPT_TYPE_STRING 

Definition at line 29 of file reloptions.h.

30{
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

Function Documentation

◆ add_bool_reloption()

void add_bool_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
bool  default_val,
LOCKMODE  lockmode 
)

Definition at line 869 of file reloptions.c.

871{
872 relopt_bool *newoption = init_bool_reloption(kinds, name, desc,
873 default_val, lockmode);
874
875 add_reloption((relopt_gen *) newoption);
876}
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:720
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:852
const char * name

References add_reloption(), init_bool_reloption(), and name.

Referenced by create_reloptions_table().

◆ add_enum_reloption()

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 at line 1038 of file reloptions.c.

1041{
1042 relopt_enum *newoption = init_enum_reloption(kinds, name, desc,
1043 members, default_val,
1044 detailmsg, lockmode);
1045
1046 add_reloption((relopt_gen *) newoption);
1047}
static relopt_enum * init_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:1009

References add_reloption(), init_enum_reloption(), and name.

Referenced by create_reloptions_table().

◆ add_int_reloption()

void add_int_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
int  default_val,
int  min_val,
int  max_val,
LOCKMODE  lockmode 
)

Definition at line 921 of file reloptions.c.

923{
924 relopt_int *newoption = init_int_reloption(kinds, name, desc,
925 default_val, min_val,
926 max_val, lockmode);
927
928 add_reloption((relopt_gen *) newoption);
929}
tree ctl max_val
Definition: radixtree.h:1859
static relopt_int * init_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:901

References add_reloption(), init_int_reloption(), max_val, and name.

Referenced by _PG_init(), and create_reloptions_table().

◆ add_local_bool_reloption()

void add_local_bool_reloption ( local_relopts relopts,
const char *  name,
const char *  desc,
bool  default_val,
int  offset 
)

Definition at line 885 of file reloptions.c.

887{
889 name, desc,
890 default_val, 0);
891
892 add_local_reloption(relopts, (relopt_gen *) newoption, offset);
893}
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:777

References add_local_reloption(), init_bool_reloption(), name, and RELOPT_KIND_LOCAL.

◆ add_local_enum_reloption()

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 at line 1056 of file reloptions.c.

1059{
1061 name, desc,
1062 members, default_val,
1063 detailmsg, 0);
1064
1065 add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1066}

References add_local_reloption(), init_enum_reloption(), name, and RELOPT_KIND_LOCAL.

◆ add_local_int_reloption()

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 
)

◆ add_local_real_reloption()

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 at line 992 of file reloptions.c.

995{
997 name, desc,
998 default_val, min_val,
999 max_val, 0);
1000
1001 add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1002}
static relopt_real * init_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:954

References add_local_reloption(), init_real_reloption(), max_val, name, and RELOPT_KIND_LOCAL.

Referenced by brin_bloom_options().

◆ add_local_string_reloption()

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 at line 1138 of file reloptions.c.

1142{
1144 name, desc,
1145 default_val,
1146 validator, filler,
1147 0);
1148
1149 add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1150}
static relopt_string * init_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, LOCKMODE lockmode)
Definition: reloptions.c:1073

References add_local_reloption(), init_string_reloption(), name, and RELOPT_KIND_LOCAL.

◆ add_real_reloption()

void add_real_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
double  default_val,
double  min_val,
double  max_val,
LOCKMODE  lockmode 
)

Definition at line 974 of file reloptions.c.

977{
978 relopt_real *newoption = init_real_reloption(kinds, name, desc,
979 default_val, min_val,
980 max_val, lockmode);
981
982 add_reloption((relopt_gen *) newoption);
983}

References add_reloption(), init_real_reloption(), max_val, and name.

Referenced by create_reloptions_table().

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 703 of file reloptions.c.

704{
705 /* don't hand out the last bit so that the enum's behavior is portable */
708 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
709 errmsg("user-defined relation parameter types limit exceeded")));
710 last_assigned_kind <<= 1;
712}
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
static bits32 last_assigned_kind
Definition: reloptions.c:574

References ereport, errcode(), errmsg(), ERROR, last_assigned_kind, and RELOPT_KIND_MAX.

Referenced by _PG_init(), and create_reloptions_table().

◆ add_string_reloption()

void add_string_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
const char *  default_val,
validate_string_relopt  validator,
LOCKMODE  lockmode 
)

Definition at line 1118 of file reloptions.c.

1121{
1122 relopt_string *newoption = init_string_reloption(kinds, name, desc,
1123 default_val,
1124 validator, NULL,
1125 lockmode);
1126
1127 add_reloption((relopt_gen *) newoption);
1128}

References add_reloption(), init_string_reloption(), and name.

Referenced by create_reloptions_table().

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 2155 of file reloptions.c.

2156{
2157 LOCKMODE lockmode = NoLock;
2158 ListCell *cell;
2159
2160 if (defList == NIL)
2161 return AccessExclusiveLock;
2162
2165
2166 foreach(cell, defList)
2167 {
2168 DefElem *def = (DefElem *) lfirst(cell);
2169 int i;
2170
2171 for (i = 0; relOpts[i]; i++)
2172 {
2173 if (strncmp(relOpts[i]->name,
2174 def->defname,
2175 relOpts[i]->namelen + 1) == 0)
2176 {
2177 if (lockmode < relOpts[i]->lockmode)
2178 lockmode = relOpts[i]->lockmode;
2179 }
2180 }
2181 }
2182
2183 return lockmode;
2184}
int i
Definition: isn.c:77
int LOCKMODE
Definition: lockdefs.h:26
#define NoLock
Definition: lockdefs.h:34
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
static void initialize_reloptions(void)
Definition: reloptions.c:600
static bool need_initialization
Definition: reloptions.c:578
static relopt_gen ** relOpts
Definition: reloptions.c:573
char * defname
Definition: parsenodes.h:843
LOCKMODE lockmode
Definition: reloptions.h:70
int namelen
Definition: reloptions.h:71

References AccessExclusiveLock, DefElem::defname, i, initialize_reloptions(), lfirst, relopt_gen::lockmode, name, relopt_gen::namelen, need_initialization, NIL, NoLock, and relOpts.

Referenced by AlterTableGetLockLevel().

◆ attribute_reloptions()

bytea * attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2116 of file reloptions.c.

2117{
2118 static const relopt_parse_elt tab[] = {
2119 {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2120 {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2121 };
2122
2123 return (bytea *) build_reloptions(reloptions, validate,
2125 sizeof(AttributeOpts),
2126 tab, lengthof(tab));
2127}
static bool validate(Port *port, const char *auth)
Definition: auth-oauth.c:638
#define lengthof(array)
Definition: c.h:791
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:1954
Definition: c.h:696

References build_reloptions(), lengthof, RELOPT_KIND_ATTRIBUTE, RELOPT_TYPE_REAL, and validate().

Referenced by ATExecSetOptions(), and get_attribute_options().

◆ build_local_reloptions()

void * build_local_reloptions ( local_relopts relopts,
Datum  options,
bool  validate 
)

Definition at line 1991 of file reloptions.c.

1992{
1993 int noptions = list_length(relopts->options);
1994 relopt_parse_elt *elems = palloc(sizeof(*elems) * noptions);
1995 relopt_value *vals;
1996 void *opts;
1997 int i = 0;
1998 ListCell *lc;
1999
2000 foreach(lc, relopts->options)
2001 {
2002 local_relopt *opt = lfirst(lc);
2003
2004 elems[i].optname = opt->option->name;
2005 elems[i].opttype = opt->option->type;
2006 elems[i].offset = opt->offset;
2007 elems[i].isset_offset = 0; /* not supported for local relopts yet */
2008
2009 i++;
2010 }
2011
2012 vals = parseLocalRelOptions(relopts, options, validate);
2015 elems, noptions);
2016
2017 if (validate)
2018 foreach(lc, relopts->validators)
2019 ((relopts_validator) lfirst(lc)) (opts, vals, noptions);
2020
2021 if (elems)
2022 pfree(elems);
2023
2024 return opts;
2025}
void pfree(void *pointer)
Definition: mcxt.c:1594
void * palloc(Size size)
Definition: mcxt.c:1365
static AmcheckOptions opts
Definition: pg_amcheck.c:112
static int list_length(const List *l)
Definition: pg_list.h:152
static size_t noptions
static relopt_value * parseLocalRelOptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1570
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1771
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1731
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition: reloptions.h:137
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
const char * name
Definition: reloptions.h:66
relopt_type type
Definition: reloptions.h:72
const char * optname
Definition: reloptions.h:152
relopt_type opttype
Definition: reloptions.h:153

References allocateReloptStruct(), fillRelOptions(), i, relopt_parse_elt::isset_offset, lfirst, list_length(), relopt_gen::name, noptions, relopt_parse_elt::offset, local_relopt::offset, local_relopt::option, local_relopts::options, relopt_parse_elt::optname, opts, relopt_parse_elt::opttype, palloc(), parseLocalRelOptions(), pfree(), local_relopts::relopt_struct_size, relopt_gen::type, validate(), and local_relopts::validators.

Referenced by index_opclass_options().

◆ build_reloptions()

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 at line 1954 of file reloptions.c.

1959{
1960 int numoptions;
1962 void *rdopts;
1963
1964 /* parse options specific to given relation option kind */
1965 options = parseRelOptions(reloptions, validate, kind, &numoptions);
1966 Assert(numoptions <= num_relopt_elems);
1967
1968 /* if none set, we're done */
1969 if (numoptions == 0)
1970 {
1971 Assert(options == NULL);
1972 return NULL;
1973 }
1974
1975 /* allocate and fill the structure */
1976 rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1977 fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1978 validate, relopt_elems, num_relopt_elems);
1979
1980 pfree(options);
1981
1982 return rdopts;
1983}
Assert(PointerIsAligned(start, uint64))
static char ** options
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1528

References allocateReloptStruct(), Assert(), fillRelOptions(), options, parseRelOptions(), pfree(), and validate().

Referenced by attribute_reloptions(), bloptions(), brinoptions(), btoptions(), default_reloptions(), dioptions(), ginoptions(), gistoptions(), hashoptions(), spgoptions(), tablespace_reloptions(), and view_reloptions().

◆ default_reloptions()

bytea * default_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind 
)

Definition at line 1878 of file reloptions.c.

1879{
1880 static const relopt_parse_elt tab[] = {
1881 {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1882 {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1883 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1884 {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1885 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1886 {"autovacuum_vacuum_max_threshold", RELOPT_TYPE_INT,
1887 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_max_threshold)},
1888 {"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT,
1889 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)},
1890 {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1891 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1892 {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1893 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1894 {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1895 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1896 {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1897 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1898 {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1899 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1900 {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1901 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1902 {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1903 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1904 {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1905 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1906 {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1907 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_vacuum_min_duration)},
1908 {"log_autoanalyze_min_duration", RELOPT_TYPE_INT,
1909 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_analyze_min_duration)},
1910 {"toast_tuple_target", RELOPT_TYPE_INT,
1911 offsetof(StdRdOptions, toast_tuple_target)},
1912 {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1913 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1914 {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1915 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1916 {"autovacuum_vacuum_insert_scale_factor", RELOPT_TYPE_REAL,
1917 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
1918 {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1919 offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1920 {"user_catalog_table", RELOPT_TYPE_BOOL,
1921 offsetof(StdRdOptions, user_catalog_table)},
1922 {"parallel_workers", RELOPT_TYPE_INT,
1923 offsetof(StdRdOptions, parallel_workers)},
1924 {"vacuum_index_cleanup", RELOPT_TYPE_ENUM,
1925 offsetof(StdRdOptions, vacuum_index_cleanup)},
1926 {"vacuum_truncate", RELOPT_TYPE_BOOL,
1927 offsetof(StdRdOptions, vacuum_truncate), offsetof(StdRdOptions, vacuum_truncate_set)},
1928 {"vacuum_max_eager_freeze_failure_rate", RELOPT_TYPE_REAL,
1930 };
1931
1932 return (bytea *) build_reloptions(reloptions, validate, kind,
1933 sizeof(StdRdOptions),
1934 tab, lengthof(tab));
1935}
static int fillfactor
Definition: pgbench.c:188
double vacuum_max_eager_freeze_failure_rate
Definition: vacuum.c:81
double vacuum_cost_delay
Definition: vacuum.c:91
int vacuum_cost_limit
Definition: vacuum.c:92
bool vacuum_truncate
Definition: vacuum.c:83

References build_reloptions(), fillfactor, lengthof, RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, vacuum_cost_delay, vacuum_cost_limit, vacuum_max_eager_freeze_failure_rate, vacuum_truncate, and validate().

Referenced by heap_reloptions().

◆ extractRelOptions()

bytea * extractRelOptions ( HeapTuple  tuple,
TupleDesc  tupdesc,
amoptions_function  amoptions 
)

Definition at line 1408 of file reloptions.c.

1410{
1411 bytea *options;
1412 bool isnull;
1413 Datum datum;
1414 Form_pg_class classForm;
1415
1416 datum = fastgetattr(tuple,
1417 Anum_pg_class_reloptions,
1418 tupdesc,
1419 &isnull);
1420 if (isnull)
1421 return NULL;
1422
1423 classForm = (Form_pg_class) GETSTRUCT(tuple);
1424
1425 /* Parse into appropriate format; don't error out here */
1426 switch (classForm->relkind)
1427 {
1428 case RELKIND_RELATION:
1429 case RELKIND_TOASTVALUE:
1430 case RELKIND_MATVIEW:
1431 options = heap_reloptions(classForm->relkind, datum, false);
1432 break;
1433 case RELKIND_PARTITIONED_TABLE:
1434 options = partitioned_table_reloptions(datum, false);
1435 break;
1436 case RELKIND_VIEW:
1437 options = view_reloptions(datum, false);
1438 break;
1439 case RELKIND_INDEX:
1440 case RELKIND_PARTITIONED_INDEX:
1441 options = index_reloptions(amoptions, datum, false);
1442 break;
1443 case RELKIND_FOREIGN_TABLE:
1444 options = NULL;
1445 break;
1446 default:
1447 Assert(false); /* can't get here */
1448 options = NULL; /* keep compiler quiet */
1449 break;
1450 }
1451
1452 return options;
1453}
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:861
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156
uint64_t Datum
Definition: postgres.h:70
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2045
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:2101
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2031
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:2066

References Assert(), fastgetattr(), GETSTRUCT(), heap_reloptions(), index_reloptions(), options, partitioned_table_reloptions(), and view_reloptions().

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

◆ heap_reloptions()

bytea * heap_reloptions ( char  relkind,
Datum  reloptions,
bool  validate 
)

Definition at line 2066 of file reloptions.c.

2067{
2068 StdRdOptions *rdopts;
2069
2070 switch (relkind)
2071 {
2072 case RELKIND_TOASTVALUE:
2073 rdopts = (StdRdOptions *)
2075 if (rdopts != NULL)
2076 {
2077 /* adjust default-only parameters for TOAST relations */
2078 rdopts->fillfactor = 100;
2079 rdopts->autovacuum.analyze_threshold = -1;
2080 rdopts->autovacuum.analyze_scale_factor = -1;
2081 }
2082 return (bytea *) rdopts;
2083 case RELKIND_RELATION:
2084 case RELKIND_MATVIEW:
2085 return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
2086 default:
2087 /* other relkinds are not supported */
2088 return NULL;
2089 }
2090}
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1878
int analyze_threshold
Definition: rel.h:317
float8 analyze_scale_factor
Definition: rel.h:330
int fillfactor
Definition: rel.h:344
AutoVacOpts autovacuum
Definition: rel.h:346

References AutoVacOpts::analyze_scale_factor, AutoVacOpts::analyze_threshold, StdRdOptions::autovacuum, default_reloptions(), StdRdOptions::fillfactor, RELOPT_KIND_HEAP, RELOPT_KIND_TOAST, and validate().

Referenced by ATExecSetRelOptions(), create_ctas_internal(), DefineRelation(), extractRelOptions(), and ProcessUtilitySlow().

◆ index_reloptions()

bytea * index_reloptions ( amoptions_function  amoptions,
Datum  reloptions,
bool  validate 
)

Definition at line 2101 of file reloptions.c.

2102{
2103 Assert(amoptions != NULL);
2104
2105 /* Assume function is strict */
2106 if (DatumGetPointer(reloptions) == NULL)
2107 return NULL;
2108
2109 return amoptions(reloptions, validate);
2110}
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322

References Assert(), DatumGetPointer(), and validate().

Referenced by ATExecSetRelOptions(), DefineIndex(), and extractRelOptions().

◆ init_local_reloptions()

void init_local_reloptions ( local_relopts relopts,
Size  relopt_struct_size 
)

◆ partitioned_table_reloptions()

bytea * partitioned_table_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2031 of file reloptions.c.

2032{
2033 if (validate && reloptions)
2034 ereport(ERROR,
2035 errcode(ERRCODE_WRONG_OBJECT_TYPE),
2036 errmsg("cannot specify storage parameters for a partitioned table"),
2037 errhint("Specify storage parameters for its leaf partitions instead."));
2038 return NULL;
2039}
int errhint(const char *fmt,...)
Definition: elog.c:1330

References ereport, errcode(), errhint(), errmsg(), ERROR, and validate().

Referenced by ATExecSetRelOptions(), DefineRelation(), and extractRelOptions().

◆ register_reloptions_validator()

void register_reloptions_validator ( local_relopts relopts,
relopts_validator  validator 
)

Definition at line 767 of file reloptions.c.

768{
769 relopts->validators = lappend(relopts->validators, validator);
770}
List * lappend(List *list, void *datum)
Definition: list.c:339

References lappend(), and local_relopts::validators.

Referenced by ltree_gist_options().

◆ tablespace_reloptions()

bytea * tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2133 of file reloptions.c.

2134{
2135 static const relopt_parse_elt tab[] = {
2136 {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
2137 {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
2138 {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
2139 {"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
2140 };
2141
2142 return (bytea *) build_reloptions(reloptions, validate,
2144 sizeof(TableSpaceOpts),
2145 tab, lengthof(tab));
2146}
int maintenance_io_concurrency
Definition: bufmgr.c:162
int effective_io_concurrency
Definition: bufmgr.c:155
double random_page_cost
Definition: costsize.c:131
double seq_page_cost
Definition: costsize.c:130

References build_reloptions(), effective_io_concurrency, lengthof, maintenance_io_concurrency, random_page_cost, RELOPT_KIND_TABLESPACE, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, seq_page_cost, and validate().

Referenced by AlterTableSpaceOptions(), CreateTableSpace(), and get_tablespace().

◆ transformRelOptions()

Datum transformRelOptions ( Datum  oldOptions,
List defList,
const char *  nameSpace,
const char *const  validnsps[],
bool  acceptOidsOff,
bool  isReset 
)

Definition at line 1176 of file reloptions.c.

1178{
1179 Datum result;
1180 ArrayBuildState *astate;
1181 ListCell *cell;
1182
1183 /* no change if empty list */
1184 if (defList == NIL)
1185 return oldOptions;
1186
1187 /* We build new array using accumArrayResult */
1188 astate = NULL;
1189
1190 /* Copy any oldOptions that aren't to be replaced */
1191 if (DatumGetPointer(oldOptions) != NULL)
1192 {
1193 ArrayType *array = DatumGetArrayTypeP(oldOptions);
1194 Datum *oldoptions;
1195 int noldoptions;
1196 int i;
1197
1198 deconstruct_array_builtin(array, TEXTOID, &oldoptions, NULL, &noldoptions);
1199
1200 for (i = 0; i < noldoptions; i++)
1201 {
1202 char *text_str = VARDATA(DatumGetPointer(oldoptions[i]));
1203 int text_len = VARSIZE(DatumGetPointer(oldoptions[i])) - VARHDRSZ;
1204
1205 /* Search for a match in defList */
1206 foreach(cell, defList)
1207 {
1208 DefElem *def = (DefElem *) lfirst(cell);
1209 int kw_len;
1210
1211 /* ignore if not in the same namespace */
1212 if (nameSpace == NULL)
1213 {
1214 if (def->defnamespace != NULL)
1215 continue;
1216 }
1217 else if (def->defnamespace == NULL)
1218 continue;
1219 else if (strcmp(def->defnamespace, nameSpace) != 0)
1220 continue;
1221
1222 kw_len = strlen(def->defname);
1223 if (text_len > kw_len && text_str[kw_len] == '=' &&
1224 strncmp(text_str, def->defname, kw_len) == 0)
1225 break;
1226 }
1227 if (!cell)
1228 {
1229 /* No match, so keep old option */
1230 astate = accumArrayResult(astate, oldoptions[i],
1231 false, TEXTOID,
1233 }
1234 }
1235 }
1236
1237 /*
1238 * If CREATE/SET, add new options to array; if RESET, just check that the
1239 * user didn't say RESET (option=val). (Must do this because the grammar
1240 * doesn't enforce it.)
1241 */
1242 foreach(cell, defList)
1243 {
1244 DefElem *def = (DefElem *) lfirst(cell);
1245
1246 if (isReset)
1247 {
1248 if (def->arg != NULL)
1249 ereport(ERROR,
1250 (errcode(ERRCODE_SYNTAX_ERROR),
1251 errmsg("RESET must not include values for parameters")));
1252 }
1253 else
1254 {
1255 const char *name;
1256 const char *value;
1257 text *t;
1258 Size len;
1259
1260 /*
1261 * Error out if the namespace is not valid. A NULL namespace is
1262 * always valid.
1263 */
1264 if (def->defnamespace != NULL)
1265 {
1266 bool valid = false;
1267 int i;
1268
1269 if (validnsps)
1270 {
1271 for (i = 0; validnsps[i]; i++)
1272 {
1273 if (strcmp(def->defnamespace, validnsps[i]) == 0)
1274 {
1275 valid = true;
1276 break;
1277 }
1278 }
1279 }
1280
1281 if (!valid)
1282 ereport(ERROR,
1283 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1284 errmsg("unrecognized parameter namespace \"%s\"",
1285 def->defnamespace)));
1286 }
1287
1288 /* ignore if not in the same namespace */
1289 if (nameSpace == NULL)
1290 {
1291 if (def->defnamespace != NULL)
1292 continue;
1293 }
1294 else if (def->defnamespace == NULL)
1295 continue;
1296 else if (strcmp(def->defnamespace, nameSpace) != 0)
1297 continue;
1298
1299 /*
1300 * Flatten the DefElem into a text string like "name=arg". If we
1301 * have just "name", assume "name=true" is meant. Note: the
1302 * namespace is not output.
1303 */
1304 name = def->defname;
1305 if (def->arg != NULL)
1306 value = defGetString(def);
1307 else
1308 value = "true";
1309
1310 /* Insist that name not contain "=", else "a=b=c" is ambiguous */
1311 if (strchr(name, '=') != NULL)
1312 ereport(ERROR,
1313 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1314 errmsg("invalid option name \"%s\": must not contain \"=\"",
1315 name)));
1316
1317 /*
1318 * This is not a great place for this test, but there's no other
1319 * convenient place to filter the option out. As WITH (oids =
1320 * false) will be removed someday, this seems like an acceptable
1321 * amount of ugly.
1322 */
1323 if (acceptOidsOff && def->defnamespace == NULL &&
1324 strcmp(name, "oids") == 0)
1325 {
1326 if (defGetBoolean(def))
1327 ereport(ERROR,
1328 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1329 errmsg("tables declared WITH OIDS are not supported")));
1330 /* skip over option, reloptions machinery doesn't know it */
1331 continue;
1332 }
1333
1334 len = VARHDRSZ + strlen(name) + 1 + strlen(value);
1335 /* +1 leaves room for sprintf's trailing null */
1336 t = (text *) palloc(len + 1);
1337 SET_VARSIZE(t, len);
1338 sprintf(VARDATA(t), "%s=%s", name, value);
1339
1340 astate = accumArrayResult(astate, PointerGetDatum(t),
1341 false, TEXTOID,
1343 }
1344 }
1345
1346 if (astate)
1347 result = makeArrayResult(astate, CurrentMemoryContext);
1348 else
1349 result = (Datum) 0;
1350
1351 return result;
1352}
#define DatumGetArrayTypeP(X)
Definition: array.h:261
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5351
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3698
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5421
#define VARHDRSZ
Definition: c.h:701
size_t Size
Definition: c.h:614
char * defGetString(DefElem *def)
Definition: define.c:35
bool defGetBoolean(DefElem *def)
Definition: define.c:94
static struct @171 value
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
const void size_t len
#define sprintf
Definition: port.h:241
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
char * defnamespace
Definition: parsenodes.h:842
Node * arg
Definition: parsenodes.h:844
static Size VARSIZE(const void *PTR)
Definition: varatt.h:298
static char * VARDATA(const void *PTR)
Definition: varatt.h:305
static void SET_VARSIZE(void *PTR, Size len)
Definition: varatt.h:432

References accumArrayResult(), DefElem::arg, CurrentMemoryContext, DatumGetArrayTypeP, DatumGetPointer(), deconstruct_array_builtin(), defGetBoolean(), defGetString(), DefElem::defname, DefElem::defnamespace, ereport, errcode(), errmsg(), ERROR, i, len, lfirst, makeArrayResult(), name, NIL, palloc(), PointerGetDatum(), SET_VARSIZE(), sprintf, value, VARDATA(), VARHDRSZ, and VARSIZE().

Referenced by AlterTableSpaceOptions(), ATExecSetOptions(), ATExecSetRelOptions(), ComputeIndexAttrs(), create_ctas_internal(), CreateTableSpace(), DefineIndex(), DefineRelation(), and ProcessUtilitySlow().

◆ untransformRelOptions()

List * untransformRelOptions ( Datum  options)

Definition at line 1360 of file reloptions.c.

1361{
1362 List *result = NIL;
1363 ArrayType *array;
1364 Datum *optiondatums;
1365 int noptions;
1366 int i;
1367
1368 /* Nothing to do if no options */
1369 if (DatumGetPointer(options) == NULL)
1370 return result;
1371
1372 array = DatumGetArrayTypeP(options);
1373
1374 deconstruct_array_builtin(array, TEXTOID, &optiondatums, NULL, &noptions);
1375
1376 for (i = 0; i < noptions; i++)
1377 {
1378 char *s;
1379 char *p;
1380 Node *val = NULL;
1381
1382 s = TextDatumGetCString(optiondatums[i]);
1383 p = strchr(s, '=');
1384 if (p)
1385 {
1386 *p++ = '\0';
1387 val = (Node *) makeString(p);
1388 }
1389 result = lappend(result, makeDefElem(s, val, -1));
1390 }
1391
1392 return result;
1393}
#define TextDatumGetCString(d)
Definition: builtins.h:98
long val
Definition: informix.c:689
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:637
Definition: pg_list.h:54
Definition: nodes.h:135
String * makeString(char *str)
Definition: value.c:63

References DatumGetArrayTypeP, DatumGetPointer(), deconstruct_array_builtin(), i, lappend(), makeDefElem(), makeString(), NIL, noptions, TextDatumGetCString, and val.

Referenced by ATExecSetRelOptions(), dblink_fdw_validator(), file_fdw_validator(), generateClonedIndexStmt(), GetForeignColumnOptions(), GetForeignDataWrapperExtended(), GetForeignServerExtended(), GetForeignTable(), GetUserMapping(), pg_options_to_table(), postgres_fdw_validator(), postgresql_fdw_validator(), and transformGenericOptions().

◆ view_reloptions()

bytea * view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2045 of file reloptions.c.

2046{
2047 static const relopt_parse_elt tab[] = {
2048 {"security_barrier", RELOPT_TYPE_BOOL,
2049 offsetof(ViewOptions, security_barrier)},
2050 {"security_invoker", RELOPT_TYPE_BOOL,
2051 offsetof(ViewOptions, security_invoker)},
2052 {"check_option", RELOPT_TYPE_ENUM,
2053 offsetof(ViewOptions, check_option)}
2054 };
2055
2056 return (bytea *) build_reloptions(reloptions, validate,
2058 sizeof(ViewOptions),
2059 tab, lengthof(tab));
2060}

References build_reloptions(), lengthof, RELOPT_KIND_VIEW, RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, and validate().

Referenced by ATExecSetRelOptions(), DefineRelation(), and extractRelOptions().