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 *opts, Size relopt_struct_size)
 
void register_reloptions_validator (local_relopts *opts, relopts_validator validator)
 
void add_local_bool_reloption (local_relopts *opts, const char *name, const char *desc, bool default_val, int offset)
 
void add_local_int_reloption (local_relopts *opts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)
 
void add_local_real_reloption (local_relopts *opts, 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 *opts, 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, char *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 851 of file reloptions.c.

853 {
854  relopt_bool *newoption = init_bool_reloption(kinds, name, desc,
855  default_val, lockmode);
856 
857  add_reloption((relopt_gen *) newoption);
858 }
const char * name
Definition: encode.c:561
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:702
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:834

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

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

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

905 {
906  relopt_int *newoption = init_int_reloption(kinds, name, desc,
907  default_val, min_val,
908  max_val, lockmode);
909 
910  add_reloption((relopt_gen *) newoption);
911 }
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:883

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

Referenced by _PG_init(), and create_reloptions_table().

◆ add_local_bool_reloption()

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

Definition at line 867 of file reloptions.c.

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

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

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

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

◆ add_local_int_reloption()

void add_local_int_reloption ( local_relopts opts,
const char *  name,
const char *  desc,
int  default_val,
int  min_val,
int  max_val,
int  offset 
)

Definition at line 920 of file reloptions.c.

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

References add_local_reloption(), init_int_reloption(), 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 opts,
const char *  name,
const char *  desc,
double  default_val,
double  min_val,
double  max_val,
int  offset 
)

Definition at line 974 of file reloptions.c.

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

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

Referenced by brin_bloom_options().

◆ add_local_string_reloption()

void add_local_string_reloption ( local_relopts opts,
const char *  name,
const char *  desc,
const char *  default_val,
validate_string_relopt  validator,
fill_string_relopt  filler,
int  offset 
)

Definition at line 1120 of file reloptions.c.

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

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

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

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

Referenced by create_reloptions_table().

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 685 of file reloptions.c.

686 {
687  /* don't hand out the last bit so that the enum's behavior is portable */
689  ereport(ERROR,
690  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
691  errmsg("user-defined relation parameter types limit exceeded")));
692  last_assigned_kind <<= 1;
694 }
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
static bits32 last_assigned_kind
Definition: reloptions.c:556

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

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

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

Referenced by create_reloptions_table().

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 2113 of file reloptions.c.

2114 {
2115  LOCKMODE lockmode = NoLock;
2116  ListCell *cell;
2117 
2118  if (defList == NIL)
2119  return AccessExclusiveLock;
2120 
2121  if (need_initialization)
2123 
2124  foreach(cell, defList)
2125  {
2126  DefElem *def = (DefElem *) lfirst(cell);
2127  int i;
2128 
2129  for (i = 0; relOpts[i]; i++)
2130  {
2131  if (strncmp(relOpts[i]->name,
2132  def->defname,
2133  relOpts[i]->namelen + 1) == 0)
2134  {
2135  if (lockmode < relOpts[i]->lockmode)
2136  lockmode = relOpts[i]->lockmode;
2137  }
2138  }
2139  }
2140 
2141  return lockmode;
2142 }
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:169
#define NIL
Definition: pg_list.h:65
static void initialize_reloptions(void)
Definition: reloptions.c:582
static bool need_initialization
Definition: reloptions.c:560
static relopt_gen ** relOpts
Definition: reloptions.c:555
char * defname
Definition: parsenodes.h:765
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 2074 of file reloptions.c.

2075 {
2076  static const relopt_parse_elt tab[] = {
2077  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2078  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2079  };
2080 
2081  return (bytea *) build_reloptions(reloptions, validate,
2083  sizeof(AttributeOpts),
2084  tab, lengthof(tab));
2085 }
#define offsetof(type, field)
Definition: c.h:727
#define lengthof(array)
Definition: c.h:734
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:1913
Definition: c.h:622

References build_reloptions(), lengthof, offsetof, 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 1950 of file reloptions.c.

1951 {
1952  int noptions = list_length(relopts->options);
1953  relopt_parse_elt *elems = palloc(sizeof(*elems) * noptions);
1954  relopt_value *vals;
1955  void *opts;
1956  int i = 0;
1957  ListCell *lc;
1958 
1959  foreach(lc, relopts->options)
1960  {
1961  local_relopt *opt = lfirst(lc);
1962 
1963  elems[i].optname = opt->option->name;
1964  elems[i].opttype = opt->option->type;
1965  elems[i].offset = opt->offset;
1966 
1967  i++;
1968  }
1969 
1970  vals = parseLocalRelOptions(relopts, options, validate);
1972  fillRelOptions(opts, relopts->relopt_struct_size, vals, noptions, validate,
1973  elems, noptions);
1974 
1975  foreach(lc, relopts->validators)
1976  ((relopts_validator) lfirst(lc)) (opts, vals, noptions);
1977 
1978  if (elems)
1979  pfree(elems);
1980 
1981  return opts;
1982 }
void pfree(void *pointer)
Definition: mcxt.c:1175
void * palloc(Size size)
Definition: mcxt.c:1068
static AmcheckOptions opts
Definition: pg_amcheck.c:110
static int list_length(const List *l)
Definition: pg_list.h:149
static size_t noptions
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1707
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1747
static relopt_value * parseLocalRelOptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1546
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 1913 of file reloptions.c.

1918 {
1919  int numoptions;
1921  void *rdopts;
1922 
1923  /* parse options specific to given relation option kind */
1924  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1925  Assert(numoptions <= num_relopt_elems);
1926 
1927  /* if none set, we're done */
1928  if (numoptions == 0)
1929  {
1930  Assert(options == NULL);
1931  return NULL;
1932  }
1933 
1934  /* allocate and fill the structure */
1935  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1936  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1937  validate, relopt_elems, num_relopt_elems);
1938 
1939  pfree(options);
1940 
1941  return rdopts;
1942 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static char ** options
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1504

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

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

◆ default_reloptions()

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

Definition at line 1843 of file reloptions.c.

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

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

Referenced by heap_reloptions().

◆ extractRelOptions()

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

Definition at line 1383 of file reloptions.c.

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

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

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

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

2060 {
2061  Assert(amoptions != NULL);
2062 
2063  /* Assume function is strict */
2064  if (!PointerIsValid(DatumGetPointer(reloptions)))
2065  return NULL;
2066 
2067  return amoptions(reloptions, validate);
2068 }
#define PointerIsValid(pointer)
Definition: c.h:698
#define DatumGetPointer(X)
Definition: postgres.h:593

References Assert(), DatumGetPointer, and PointerIsValid.

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

◆ init_local_reloptions()

void init_local_reloptions ( local_relopts opts,
Size  relopt_struct_size 
)

Definition at line 736 of file reloptions.c.

737 {
738  opts->options = NIL;
739  opts->validators = NIL;
740  opts->relopt_struct_size = relopt_struct_size;
741 }

References NIL, and opts.

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

◆ partitioned_table_reloptions()

bytea* partitioned_table_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1988 of file reloptions.c.

1989 {
1990  /*
1991  * There are no options for partitioned tables yet, but this is able to do
1992  * some validation.
1993  */
1994  return (bytea *) build_reloptions(reloptions, validate,
1996  0, NULL, 0);
1997 }

References build_reloptions(), and RELOPT_KIND_PARTITIONED.

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

◆ register_reloptions_validator()

void register_reloptions_validator ( local_relopts opts,
relopts_validator  validator 
)

Definition at line 749 of file reloptions.c.

750 {
751  opts->validators = lappend(opts->validators, validator);
752 }
List * lappend(List *list, void *datum)
Definition: list.c:336

References lappend(), and opts.

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2091 of file reloptions.c.

2092 {
2093  static const relopt_parse_elt tab[] = {
2094  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
2095  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
2096  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
2097  {"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
2098  };
2099 
2100  return (bytea *) build_reloptions(reloptions, validate,
2102  sizeof(TableSpaceOpts),
2103  tab, lengthof(tab));
2104 }
int maintenance_io_concurrency
Definition: bufmgr.c:152
int effective_io_concurrency
Definition: bufmgr.c:145
double random_page_cost
Definition: costsize.c:121
double seq_page_cost
Definition: costsize.c:120

References build_reloptions(), effective_io_concurrency, lengthof, maintenance_io_concurrency, offsetof, 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,
char *  validnsps[],
bool  acceptOidsOff,
bool  isReset 
)

Definition at line 1158 of file reloptions.c.

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

References accumArrayResult(), DefElem::arg, CurrentMemoryContext, DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), 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 1334 of file reloptions.c.

1335 {
1336  List *result = NIL;
1337  ArrayType *array;
1338  Datum *optiondatums;
1339  int noptions;
1340  int i;
1341 
1342  /* Nothing to do if no options */
1344  return result;
1345 
1346  array = DatumGetArrayTypeP(options);
1347 
1348  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1349  &optiondatums, NULL, &noptions);
1350 
1351  for (i = 0; i < noptions; i++)
1352  {
1353  char *s;
1354  char *p;
1355  Node *val = NULL;
1356 
1357  s = TextDatumGetCString(optiondatums[i]);
1358  p = strchr(s, '=');
1359  if (p)
1360  {
1361  *p++ = '\0';
1362  val = (Node *) makeString(pstrdup(p));
1363  }
1364  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1365  }
1366 
1367  return result;
1368 }
#define TextDatumGetCString(d)
Definition: builtins.h:86
long val
Definition: informix.c:664
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:547
char * pstrdup(const char *in)
Definition: mcxt.c:1305
Definition: pg_list.h:51
Definition: nodes.h:574
String * makeString(char *str)
Definition: value.c:63

References DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), i, lappend(), makeDefElem(), makeString(), NIL, noptions, PointerIsValid, pstrdup(), 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 2003 of file reloptions.c.

2004 {
2005  static const relopt_parse_elt tab[] = {
2006  {"security_barrier", RELOPT_TYPE_BOOL,
2007  offsetof(ViewOptions, security_barrier)},
2008  {"security_invoker", RELOPT_TYPE_BOOL,
2009  offsetof(ViewOptions, security_invoker)},
2010  {"check_option", RELOPT_TYPE_ENUM,
2011  offsetof(ViewOptions, check_option)}
2012  };
2013 
2014  return (bytea *) build_reloptions(reloptions, validate,
2016  sizeof(ViewOptions),
2017  tab, lengthof(tab));
2018 }

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

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