PostgreSQL Source Code  git master
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 *namspace, 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 178 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)
58 } relopt_kind;
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 {
36 } relopt_type;
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 849 of file reloptions.c.

851 {
852  relopt_bool *newoption = init_bool_reloption(kinds, name, desc,
853  default_val, lockmode);
854 
855  add_reloption((relopt_gen *) newoption);
856 }
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:700
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:832
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 1018 of file reloptions.c.

1021 {
1022  relopt_enum *newoption = init_enum_reloption(kinds, name, desc,
1023  members, default_val,
1024  detailmsg, lockmode);
1025 
1026  add_reloption((relopt_gen *) newoption);
1027 }
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:989

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 901 of file reloptions.c.

903 {
904  relopt_int *newoption = init_int_reloption(kinds, name, desc,
905  default_val, min_val,
906  max_val, lockmode);
907 
908  add_reloption((relopt_gen *) newoption);
909 }
tree ctl max_val
Definition: radixtree.h:1888
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:881

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 865 of file reloptions.c.

867 {
869  name, desc,
870  default_val, 0);
871 
872  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
873 }
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:757

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 1036 of file reloptions.c.

1039 {
1041  name, desc,
1042  members, default_val,
1043  detailmsg, 0);
1044 
1045  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1046 }

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 
)

Definition at line 918 of file reloptions.c.

921 {
923  name, desc, default_val,
924  min_val, max_val, 0);
925 
926  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
927 }

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

Referenced by _ltree_gist_options(), brin_minmax_multi_options(), g_int_options(), g_intbig_options(), ghstore_options(), gtrgm_options(), gtsvector_options(), and ltree_gist_options().

◆ 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 972 of file reloptions.c.

975 {
977  name, desc,
978  default_val, min_val,
979  max_val, 0);
980 
981  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
982 }
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:934

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 1118 of file reloptions.c.

1122 {
1124  name, desc,
1125  default_val,
1126  validator, filler,
1127  0);
1128 
1129  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1130 }
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:1053

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 954 of file reloptions.c.

957 {
958  relopt_real *newoption = init_real_reloption(kinds, name, desc,
959  default_val, min_val,
960  max_val, lockmode);
961 
962  add_reloption((relopt_gen *) newoption);
963 }

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 683 of file reloptions.c.

684 {
685  /* don't hand out the last bit so that the enum's behavior is portable */
687  ereport(ERROR,
688  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
689  errmsg("user-defined relation parameter types limit exceeded")));
690  last_assigned_kind <<= 1;
692 }
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static bits32 last_assigned_kind
Definition: reloptions.c:554

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 1098 of file reloptions.c.

1101 {
1102  relopt_string *newoption = init_string_reloption(kinds, name, desc,
1103  default_val,
1104  validator, NULL,
1105  lockmode);
1106 
1107  add_reloption((relopt_gen *) newoption);
1108 }

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

Referenced by create_reloptions_table().

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 2108 of file reloptions.c.

2109 {
2110  LOCKMODE lockmode = NoLock;
2111  ListCell *cell;
2112 
2113  if (defList == NIL)
2114  return AccessExclusiveLock;
2115 
2116  if (need_initialization)
2118 
2119  foreach(cell, defList)
2120  {
2121  DefElem *def = (DefElem *) lfirst(cell);
2122  int i;
2123 
2124  for (i = 0; relOpts[i]; i++)
2125  {
2126  if (strncmp(relOpts[i]->name,
2127  def->defname,
2128  relOpts[i]->namelen + 1) == 0)
2129  {
2130  if (lockmode < relOpts[i]->lockmode)
2131  lockmode = relOpts[i]->lockmode;
2132  }
2133  }
2134  }
2135 
2136  return lockmode;
2137 }
int i
Definition: isn.c:73
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:580
static bool need_initialization
Definition: reloptions.c:558
static relopt_gen ** relOpts
Definition: reloptions.c:553
char * defname
Definition: parsenodes.h:817
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 2069 of file reloptions.c.

2070 {
2071  static const relopt_parse_elt tab[] = {
2072  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2073  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2074  };
2075 
2076  return (bytea *) build_reloptions(reloptions, validate,
2078  sizeof(AttributeOpts),
2079  tab, lengthof(tab));
2080 }
#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:1908
Definition: c.h:690

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

Referenced by ATExecSetOptions(), and get_attribute_options().

◆ build_local_reloptions()

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

Definition at line 1945 of file reloptions.c.

1946 {
1947  int noptions = list_length(relopts->options);
1948  relopt_parse_elt *elems = palloc(sizeof(*elems) * noptions);
1949  relopt_value *vals;
1950  void *opts;
1951  int i = 0;
1952  ListCell *lc;
1953 
1954  foreach(lc, relopts->options)
1955  {
1956  local_relopt *opt = lfirst(lc);
1957 
1958  elems[i].optname = opt->option->name;
1959  elems[i].opttype = opt->option->type;
1960  elems[i].offset = opt->offset;
1961 
1962  i++;
1963  }
1964 
1965  vals = parseLocalRelOptions(relopts, options, validate);
1967  fillRelOptions(opts, relopts->relopt_struct_size, vals, noptions, validate,
1968  elems, noptions);
1969 
1970  if (validate)
1971  foreach(lc, relopts->validators)
1972  ((relopts_validator) lfirst(lc)) (opts, vals, noptions);
1973 
1974  if (elems)
1975  pfree(elems);
1976 
1977  return opts;
1978 }
void pfree(void *pointer)
Definition: mcxt.c:1521
void * palloc(Size size)
Definition: mcxt.c:1317
static AmcheckOptions opts
Definition: pg_amcheck.c:111
static int list_length(const List *l)
Definition: pg_list.h:152
static size_t noptions
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1702
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1742
static relopt_value * parseLocalRelOptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1541
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition: reloptions.h:137
relopt_gen * option
Definition: reloptions.h:160
List * validators
Definition: reloptions.h:168
List * options
Definition: reloptions.h:167
Size relopt_struct_size
Definition: reloptions.h:169
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, 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, 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 1908 of file reloptions.c.

1913 {
1914  int numoptions;
1916  void *rdopts;
1917 
1918  /* parse options specific to given relation option kind */
1919  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1920  Assert(numoptions <= num_relopt_elems);
1921 
1922  /* if none set, we're done */
1923  if (numoptions == 0)
1924  {
1925  Assert(options == NULL);
1926  return NULL;
1927  }
1928 
1929  /* allocate and fill the structure */
1930  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1931  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1932  validate, relopt_elems, num_relopt_elems);
1933 
1934  pfree(options);
1935 
1936  return rdopts;
1937 }
#define Assert(condition)
Definition: c.h:861
static char ** options
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1499

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

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 1838 of file reloptions.c.

1839 {
1840  static const relopt_parse_elt tab[] = {
1841  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1842  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1843  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1844  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1845  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1846  {"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT,
1847  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)},
1848  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1849  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1850  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1851  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1852  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1853  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1854  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1855  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1856  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1857  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1858  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1859  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1860  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1861  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1862  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1863  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1864  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1865  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1866  {"toast_tuple_target", RELOPT_TYPE_INT,
1867  offsetof(StdRdOptions, toast_tuple_target)},
1868  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1869  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1870  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1871  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1872  {"autovacuum_vacuum_insert_scale_factor", RELOPT_TYPE_REAL,
1873  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
1874  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1875  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1876  {"user_catalog_table", RELOPT_TYPE_BOOL,
1877  offsetof(StdRdOptions, user_catalog_table)},
1878  {"parallel_workers", RELOPT_TYPE_INT,
1879  offsetof(StdRdOptions, parallel_workers)},
1880  {"vacuum_index_cleanup", RELOPT_TYPE_ENUM,
1881  offsetof(StdRdOptions, vacuum_index_cleanup)},
1882  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1883  offsetof(StdRdOptions, vacuum_truncate)}
1884  };
1885 
1886  return (bytea *) build_reloptions(reloptions, validate, kind,
1887  sizeof(StdRdOptions),
1888  tab, lengthof(tab));
1889 }
static int fillfactor
Definition: pgbench.c:187
double vacuum_cost_delay
Definition: vacuum.c:80
int vacuum_cost_limit
Definition: vacuum.c:81

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

Referenced by heap_reloptions().

◆ extractRelOptions()

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

Definition at line 1379 of file reloptions.c.

1381 {
1382  bytea *options;
1383  bool isnull;
1384  Datum datum;
1385  Form_pg_class classForm;
1386 
1387  datum = fastgetattr(tuple,
1388  Anum_pg_class_reloptions,
1389  tupdesc,
1390  &isnull);
1391  if (isnull)
1392  return NULL;
1393 
1394  classForm = (Form_pg_class) GETSTRUCT(tuple);
1395 
1396  /* Parse into appropriate format; don't error out here */
1397  switch (classForm->relkind)
1398  {
1399  case RELKIND_RELATION:
1400  case RELKIND_TOASTVALUE:
1401  case RELKIND_MATVIEW:
1402  options = heap_reloptions(classForm->relkind, datum, false);
1403  break;
1404  case RELKIND_PARTITIONED_TABLE:
1405  options = partitioned_table_reloptions(datum, false);
1406  break;
1407  case RELKIND_VIEW:
1408  options = view_reloptions(datum, false);
1409  break;
1410  case RELKIND_INDEX:
1411  case RELKIND_PARTITIONED_INDEX:
1412  options = index_reloptions(amoptions, datum, false);
1413  break;
1414  case RELKIND_FOREIGN_TABLE:
1415  options = NULL;
1416  break;
1417  default:
1418  Assert(false); /* can't get here */
1419  options = NULL; /* keep compiler quiet */
1420  break;
1421  }
1422 
1423  return options;
1424 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:749
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
uintptr_t Datum
Definition: postgres.h:64
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:2054
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:2019
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1998
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1984

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 2019 of file reloptions.c.

2020 {
2021  StdRdOptions *rdopts;
2022 
2023  switch (relkind)
2024  {
2025  case RELKIND_TOASTVALUE:
2026  rdopts = (StdRdOptions *)
2027  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
2028  if (rdopts != NULL)
2029  {
2030  /* adjust default-only parameters for TOAST relations */
2031  rdopts->fillfactor = 100;
2032  rdopts->autovacuum.analyze_threshold = -1;
2033  rdopts->autovacuum.analyze_scale_factor = -1;
2034  }
2035  return (bytea *) rdopts;
2036  case RELKIND_RELATION:
2037  case RELKIND_MATVIEW:
2038  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
2039  default:
2040  /* other relkinds are not supported */
2041  return NULL;
2042  }
2043 }
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1838
int analyze_threshold
Definition: rel.h:313
float8 analyze_scale_factor
Definition: rel.h:325
int fillfactor
Definition: rel.h:339
AutoVacOpts autovacuum
Definition: rel.h:341

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

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 2054 of file reloptions.c.

2055 {
2056  Assert(amoptions != NULL);
2057 
2058  /* Assume function is strict */
2059  if (!PointerIsValid(DatumGetPointer(reloptions)))
2060  return NULL;
2061 
2062  return amoptions(reloptions, validate);
2063 }
#define PointerIsValid(pointer)
Definition: c.h:766
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312

References Assert, DatumGetPointer(), and PointerIsValid.

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 1984 of file reloptions.c.

1985 {
1986  if (validate && reloptions)
1987  ereport(ERROR,
1988  errcode(ERRCODE_WRONG_OBJECT_TYPE),
1989  errmsg("cannot specify storage parameters for a partitioned table"),
1990  errhint("Specify storage parameters for its leaf partitions instead."));
1991  return NULL;
1992 }
int errhint(const char *fmt,...)
Definition: elog.c:1317

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

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

◆ register_reloptions_validator()

void register_reloptions_validator ( local_relopts relopts,
relopts_validator  validator 
)

Definition at line 747 of file reloptions.c.

748 {
749  relopts->validators = lappend(relopts->validators, validator);
750 }
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 2086 of file reloptions.c.

2087 {
2088  static const relopt_parse_elt tab[] = {
2089  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
2090  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
2091  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
2092  {"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
2093  };
2094 
2095  return (bytea *) build_reloptions(reloptions, validate,
2097  sizeof(TableSpaceOpts),
2098  tab, lengthof(tab));
2099 }
int maintenance_io_concurrency
Definition: bufmgr.c:158
int effective_io_concurrency
Definition: bufmgr.c:151
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, and seq_page_cost.

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

◆ transformRelOptions()

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

Definition at line 1156 of file reloptions.c.

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

References accumArrayResult(), DefElem::arg, CurrentMemoryContext, DatumGetArrayTypeP, DatumGetPointer(), deconstruct_array_builtin(), defGetBoolean(), defGetString(), DefElem::defname, DefElem::defnamespace, ereport, errcode(), errmsg(), ERROR, i, len, lfirst, makeArrayResult(), NIL, palloc(), PointerGetDatum(), PointerIsValid, 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 1331 of file reloptions.c.

1332 {
1333  List *result = NIL;
1334  ArrayType *array;
1335  Datum *optiondatums;
1336  int noptions;
1337  int i;
1338 
1339  /* Nothing to do if no options */
1341  return result;
1342 
1343  array = DatumGetArrayTypeP(options);
1344 
1345  deconstruct_array_builtin(array, TEXTOID, &optiondatums, NULL, &noptions);
1346 
1347  for (i = 0; i < noptions; i++)
1348  {
1349  char *s;
1350  char *p;
1351  Node *val = NULL;
1352 
1353  s = TextDatumGetCString(optiondatums[i]);
1354  p = strchr(s, '=');
1355  if (p)
1356  {
1357  *p++ = '\0';
1358  val = (Node *) makeString(p);
1359  }
1360  result = lappend(result, makeDefElem(s, val, -1));
1361  }
1362 
1363  return result;
1364 }
#define TextDatumGetCString(d)
Definition: builtins.h:98
long val
Definition: informix.c:689
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:564
Definition: pg_list.h:54
Definition: nodes.h:129
String * makeString(char *str)
Definition: value.c:63

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

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

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1998 of file reloptions.c.

1999 {
2000  static const relopt_parse_elt tab[] = {
2001  {"security_barrier", RELOPT_TYPE_BOOL,
2002  offsetof(ViewOptions, security_barrier)},
2003  {"security_invoker", RELOPT_TYPE_BOOL,
2004  offsetof(ViewOptions, security_invoker)},
2005  {"check_option", RELOPT_TYPE_ENUM,
2006  offsetof(ViewOptions, check_option)}
2007  };
2008 
2009  return (bytea *) build_reloptions(reloptions, validate,
2011  sizeof(ViewOptions),
2012  tab, lengthof(tab));
2013 }

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

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