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)
Oid member

Definition at line 178 of file reloptions.h.

◆ HEAP_RELOPT_NAMESPACES

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

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:39

◆ 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.

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

References add_reloption(), and init_bool_reloption().

Referenced by create_reloptions_table().

827 {
828  relopt_bool *newoption = init_bool_reloption(kinds, name, desc,
829  default_val, lockmode);
830 
831  add_reloption((relopt_gen *) newoption);
832 }
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:808

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

References add_reloption(), and init_enum_reloption().

Referenced by create_reloptions_table().

997 {
998  relopt_enum *newoption = init_enum_reloption(kinds, name, desc,
999  members, default_val,
1000  detailmsg, lockmode);
1001 
1002  add_reloption((relopt_gen *) newoption);
1003 }
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:965
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561

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

References add_reloption(), and init_int_reloption().

Referenced by _PG_init(), and create_reloptions_table().

879 {
880  relopt_int *newoption = init_int_reloption(kinds, name, desc,
881  default_val, min_val,
882  max_val, lockmode);
883 
884  add_reloption((relopt_gen *) newoption);
885 }
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:857
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561

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

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

843 {
845  name, desc,
846  default_val, 0);
847 
848  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
849 }
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:808

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

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

1015 {
1017  name, desc,
1018  members, default_val,
1019  detailmsg, 0);
1020 
1021  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1022 }
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:965
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561

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

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

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

897 {
899  name, desc, default_val,
900  min_val, max_val, 0);
901 
902  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
903 }
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:857
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561

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

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

951 {
953  name, desc,
954  default_val, min_val,
955  max_val, 0);
956 
957  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
958 }
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:910
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561

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

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

1098 {
1100  name, desc,
1101  default_val,
1102  validator, filler,
1103  0);
1104 
1105  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1106 }
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
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:1029
const char * name
Definition: encode.c:561

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

References add_reloption(), and init_real_reloption().

Referenced by create_reloptions_table().

933 {
934  relopt_real *newoption = init_real_reloption(kinds, name, desc,
935  default_val, min_val,
936  max_val, lockmode);
937 
938  add_reloption((relopt_gen *) newoption);
939 }
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:910
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 659 of file reloptions.c.

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

Referenced by _PG_init(), and create_reloptions_table().

660 {
661  /* don't hand out the last bit so that the enum's behavior is portable */
663  ereport(ERROR,
664  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
665  errmsg("user-defined relation parameter types limit exceeded")));
666  last_assigned_kind <<= 1;
668 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
relopt_kind
Definition: reloptions.h:39
static bits32 last_assigned_kind
Definition: reloptions.c:530

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

References add_reloption(), and init_string_reloption().

Referenced by create_reloptions_table().

1077 {
1078  relopt_string *newoption = init_string_reloption(kinds, name, desc,
1079  default_val,
1080  validator, NULL,
1081  lockmode);
1082 
1083  add_reloption((relopt_gen *) newoption);
1084 }
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
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:1029
const char * name
Definition: encode.c:561

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 2085 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

2086 {
2087  LOCKMODE lockmode = NoLock;
2088  ListCell *cell;
2089 
2090  if (defList == NIL)
2091  return AccessExclusiveLock;
2092 
2093  if (need_initialization)
2095 
2096  foreach(cell, defList)
2097  {
2098  DefElem *def = (DefElem *) lfirst(cell);
2099  int i;
2100 
2101  for (i = 0; relOpts[i]; i++)
2102  {
2103  if (strncmp(relOpts[i]->name,
2104  def->defname,
2105  relOpts[i]->namelen + 1) == 0)
2106  {
2107  if (lockmode < relOpts[i]->lockmode)
2108  lockmode = relOpts[i]->lockmode;
2109  }
2110  }
2111  }
2112 
2113  return lockmode;
2114 }
#define NIL
Definition: pg_list.h:65
static void initialize_reloptions(void)
Definition: reloptions.c:556
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:70
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h:71
#define lfirst(lc)
Definition: pg_list.h:190
const char * name
Definition: encode.c:561
#define AccessExclusiveLock
Definition: lockdefs.h:45
int i
static bool need_initialization
Definition: reloptions.c:534
char * defname
Definition: parsenodes.h:733
static relopt_gen ** relOpts
Definition: reloptions.c:529

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2046 of file reloptions.c.

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

Referenced by ATExecSetOptions(), and get_attribute_options().

2047 {
2048  static const relopt_parse_elt tab[] = {
2049  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2050  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2051  };
2052 
2053  return (bytea *) build_reloptions(reloptions, validate,
2055  sizeof(AttributeOpts),
2056  tab, lengthof(tab));
2057 }
#define lengthof(array)
Definition: c.h:675
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:1887
Definition: c.h:562
#define offsetof(type, field)
Definition: c.h:668

◆ build_local_reloptions()

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

Definition at line 1924 of file reloptions.c.

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, relopt_parse_elt::opttype, palloc(), parseLocalRelOptions(), pfree(), local_relopts::relopt_struct_size, relopt_gen::type, and local_relopts::validators.

Referenced by index_opclass_options().

1925 {
1926  int noptions = list_length(relopts->options);
1927  relopt_parse_elt *elems = palloc(sizeof(*elems) * noptions);
1928  relopt_value *vals;
1929  void *opts;
1930  int i = 0;
1931  ListCell *lc;
1932 
1933  foreach(lc, relopts->options)
1934  {
1935  local_relopt *opt = lfirst(lc);
1936 
1937  elems[i].optname = opt->option->name;
1938  elems[i].opttype = opt->option->type;
1939  elems[i].offset = opt->offset;
1940 
1941  i++;
1942  }
1943 
1944  vals = parseLocalRelOptions(relopts, options, validate);
1945  opts = allocateReloptStruct(relopts->relopt_struct_size, vals, noptions);
1946  fillRelOptions(opts, relopts->relopt_struct_size, vals, noptions, validate,
1947  elems, noptions);
1948 
1949  foreach(lc, relopts->validators)
1950  ((relopts_validator) lfirst(lc)) (opts, vals, noptions);
1951 
1952  if (elems)
1953  pfree(elems);
1954 
1955  return opts;
1956 }
static relopt_value * parseLocalRelOptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1520
relopt_type opttype
Definition: reloptions.h:153
List * validators
Definition: reloptions.h:168
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1681
List * options
Definition: reloptions.h:167
void pfree(void *pointer)
Definition: mcxt.c:1057
Size relopt_struct_size
Definition: reloptions.h:169
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1721
relopt_gen * option
Definition: reloptions.h:160
const char * optname
Definition: reloptions.h:152
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition: reloptions.h:137
#define lfirst(lc)
Definition: pg_list.h:190
relopt_type type
Definition: reloptions.h:72
static int list_length(const List *l)
Definition: pg_list.h:169
void * palloc(Size size)
Definition: mcxt.c:950
const char * name
Definition: reloptions.h:66
int i
static size_t noptions

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

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().

1892 {
1893  int numoptions;
1895  void *rdopts;
1896 
1897  /* parse options specific to given relation option kind */
1898  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1899  Assert(numoptions <= num_relopt_elems);
1900 
1901  /* if none set, we're done */
1902  if (numoptions == 0)
1903  {
1904  Assert(options == NULL);
1905  return NULL;
1906  }
1907 
1908  /* allocate and fill the structure */
1909  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1910  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1911  validate, relopt_elems, num_relopt_elems);
1912 
1913  pfree(options);
1914 
1915  return rdopts;
1916 }
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1681
void pfree(void *pointer)
Definition: mcxt.c:1057
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1721
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1478
static char ** options
#define Assert(condition)
Definition: c.h:745

◆ default_reloptions()

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

Definition at line 1817 of file reloptions.c.

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

Referenced by heap_reloptions().

1818 {
1819  static const relopt_parse_elt tab[] = {
1820  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1821  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1822  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1823  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1824  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1825  {"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT,
1826  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)},
1827  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1828  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1829  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1830  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1831  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1832  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1833  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1834  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1835  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1836  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1837  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1838  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1839  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1840  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1841  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1842  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1843  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1844  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1845  {"toast_tuple_target", RELOPT_TYPE_INT,
1846  offsetof(StdRdOptions, toast_tuple_target)},
1847  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1848  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1849  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1850  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1851  {"autovacuum_vacuum_insert_scale_factor", RELOPT_TYPE_REAL,
1852  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
1853  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1854  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1855  {"user_catalog_table", RELOPT_TYPE_BOOL,
1856  offsetof(StdRdOptions, user_catalog_table)},
1857  {"parallel_workers", RELOPT_TYPE_INT,
1858  offsetof(StdRdOptions, parallel_workers)},
1859  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1860  offsetof(StdRdOptions, vacuum_index_cleanup)},
1861  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1862  offsetof(StdRdOptions, vacuum_truncate)}
1863  };
1864 
1865  return (bytea *) build_reloptions(reloptions, validate, kind,
1866  sizeof(StdRdOptions),
1867  tab, lengthof(tab));
1868 }
#define lengthof(array)
Definition: c.h:675
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:1887
int fillfactor
Definition: pgbench.c:160
Definition: c.h:562
#define offsetof(type, field)
Definition: c.h:668

◆ extractRelOptions()

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

Definition at line 1357 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

1359 {
1360  bytea *options;
1361  bool isnull;
1362  Datum datum;
1363  Form_pg_class classForm;
1364 
1365  datum = fastgetattr(tuple,
1366  Anum_pg_class_reloptions,
1367  tupdesc,
1368  &isnull);
1369  if (isnull)
1370  return NULL;
1371 
1372  classForm = (Form_pg_class) GETSTRUCT(tuple);
1373 
1374  /* Parse into appropriate format; don't error out here */
1375  switch (classForm->relkind)
1376  {
1377  case RELKIND_RELATION:
1378  case RELKIND_TOASTVALUE:
1379  case RELKIND_MATVIEW:
1380  options = heap_reloptions(classForm->relkind, datum, false);
1381  break;
1382  case RELKIND_PARTITIONED_TABLE:
1383  options = partitioned_table_reloptions(datum, false);
1384  break;
1385  case RELKIND_VIEW:
1386  options = view_reloptions(datum, false);
1387  break;
1388  case RELKIND_INDEX:
1389  case RELKIND_PARTITIONED_INDEX:
1390  options = index_reloptions(amoptions, datum, false);
1391  break;
1392  case RELKIND_FOREIGN_TABLE:
1393  options = NULL;
1394  break;
1395  default:
1396  Assert(false); /* can't get here */
1397  options = NULL; /* keep compiler quiet */
1398  break;
1399  }
1400 
1401  return options;
1402 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1996
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:712
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1977
static char ** options
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1962
uintptr_t Datum
Definition: postgres.h:367
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:2031
#define Assert(condition)
Definition: c.h:745
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
Definition: c.h:562

◆ heap_reloptions()

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

Definition at line 1996 of file reloptions.c.

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().

1997 {
1998  StdRdOptions *rdopts;
1999 
2000  switch (relkind)
2001  {
2002  case RELKIND_TOASTVALUE:
2003  rdopts = (StdRdOptions *)
2004  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
2005  if (rdopts != NULL)
2006  {
2007  /* adjust default-only parameters for TOAST relations */
2008  rdopts->fillfactor = 100;
2009  rdopts->autovacuum.analyze_threshold = -1;
2010  rdopts->autovacuum.analyze_scale_factor = -1;
2011  }
2012  return (bytea *) rdopts;
2013  case RELKIND_RELATION:
2014  case RELKIND_MATVIEW:
2015  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
2016  default:
2017  /* other relkinds are not supported */
2018  return NULL;
2019  }
2020 }
int fillfactor
Definition: rel.h:300
int analyze_threshold
Definition: rel.h:282
float8 analyze_scale_factor
Definition: rel.h:294
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1817
Definition: c.h:562
AutoVacOpts autovacuum
Definition: rel.h:303

◆ index_reloptions()

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

Definition at line 2031 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

2032 {
2033  Assert(amoptions != NULL);
2034 
2035  /* Assume function is strict */
2036  if (!PointerIsValid(DatumGetPointer(reloptions)))
2037  return NULL;
2038 
2039  return amoptions(reloptions, validate);
2040 }
#define Assert(condition)
Definition: c.h:745
#define DatumGetPointer(X)
Definition: postgres.h:549
#define PointerIsValid(pointer)
Definition: c.h:639

◆ init_local_reloptions()

void init_local_reloptions ( local_relopts opts,
Size  relopt_struct_size 
)

Definition at line 710 of file reloptions.c.

References NIL, local_relopts::options, local_relopts::relopt_struct_size, and local_relopts::validators.

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

711 {
712  opts->options = NIL;
713  opts->validators = NIL;
714  opts->relopt_struct_size = relopt_struct_size;
715 }
#define NIL
Definition: pg_list.h:65
List * validators
Definition: reloptions.h:168
List * options
Definition: reloptions.h:167
Size relopt_struct_size
Definition: reloptions.h:169

◆ partitioned_table_reloptions()

bytea* partitioned_table_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1962 of file reloptions.c.

References build_reloptions(), and RELOPT_KIND_PARTITIONED.

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

1963 {
1964  /*
1965  * There are no options for partitioned tables yet, but this is able to do
1966  * some validation.
1967  */
1968  return (bytea *) build_reloptions(reloptions, validate,
1970  0, NULL, 0);
1971 }
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:1887
Definition: c.h:562

◆ register_reloptions_validator()

void register_reloptions_validator ( local_relopts opts,
relopts_validator  validator 
)

Definition at line 723 of file reloptions.c.

References lappend(), and local_relopts::validators.

724 {
725  opts->validators = lappend(opts->validators, validator);
726 }
List * validators
Definition: reloptions.h:168
List * lappend(List *list, void *datum)
Definition: list.c:321

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2063 of file reloptions.c.

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().

2064 {
2065  static const relopt_parse_elt tab[] = {
2066  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
2067  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
2068  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
2069  {"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
2070  };
2071 
2072  return (bytea *) build_reloptions(reloptions, validate,
2074  sizeof(TableSpaceOpts),
2075  tab, lengthof(tab));
2076 }
int maintenance_io_concurrency
Definition: bufmgr.c:142
#define lengthof(array)
Definition: c.h:675
int effective_io_concurrency
Definition: bufmgr.c:135
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:1887
double random_page_cost
Definition: costsize.c:112
Definition: c.h:562
double seq_page_cost
Definition: costsize.c:111
#define offsetof(type, field)
Definition: c.h:668

◆ transformRelOptions()

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

Definition at line 1132 of file reloptions.c.

References accumArrayResult(), DefElem::arg, CurrentMemoryContext, DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), defGetBoolean(), defGetString(), DefElem::defname, DefElem::defnamespace, ereport, errcode(), errmsg(), ERROR, i, 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().

1134 {
1135  Datum result;
1136  ArrayBuildState *astate;
1137  ListCell *cell;
1138 
1139  /* no change if empty list */
1140  if (defList == NIL)
1141  return oldOptions;
1142 
1143  /* We build new array using accumArrayResult */
1144  astate = NULL;
1145 
1146  /* Copy any oldOptions that aren't to be replaced */
1147  if (PointerIsValid(DatumGetPointer(oldOptions)))
1148  {
1149  ArrayType *array = DatumGetArrayTypeP(oldOptions);
1150  Datum *oldoptions;
1151  int noldoptions;
1152  int i;
1153 
1154  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1155  &oldoptions, NULL, &noldoptions);
1156 
1157  for (i = 0; i < noldoptions; i++)
1158  {
1159  char *text_str = VARDATA(oldoptions[i]);
1160  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
1161 
1162  /* Search for a match in defList */
1163  foreach(cell, defList)
1164  {
1165  DefElem *def = (DefElem *) lfirst(cell);
1166  int kw_len;
1167 
1168  /* ignore if not in the same namespace */
1169  if (namspace == NULL)
1170  {
1171  if (def->defnamespace != NULL)
1172  continue;
1173  }
1174  else if (def->defnamespace == NULL)
1175  continue;
1176  else if (strcmp(def->defnamespace, namspace) != 0)
1177  continue;
1178 
1179  kw_len = strlen(def->defname);
1180  if (text_len > kw_len && text_str[kw_len] == '=' &&
1181  strncmp(text_str, def->defname, kw_len) == 0)
1182  break;
1183  }
1184  if (!cell)
1185  {
1186  /* No match, so keep old option */
1187  astate = accumArrayResult(astate, oldoptions[i],
1188  false, TEXTOID,
1190  }
1191  }
1192  }
1193 
1194  /*
1195  * If CREATE/SET, add new options to array; if RESET, just check that the
1196  * user didn't say RESET (option=val). (Must do this because the grammar
1197  * doesn't enforce it.)
1198  */
1199  foreach(cell, defList)
1200  {
1201  DefElem *def = (DefElem *) lfirst(cell);
1202 
1203  if (isReset)
1204  {
1205  if (def->arg != NULL)
1206  ereport(ERROR,
1207  (errcode(ERRCODE_SYNTAX_ERROR),
1208  errmsg("RESET must not include values for parameters")));
1209  }
1210  else
1211  {
1212  text *t;
1213  const char *value;
1214  Size len;
1215 
1216  /*
1217  * Error out if the namespace is not valid. A NULL namespace is
1218  * always valid.
1219  */
1220  if (def->defnamespace != NULL)
1221  {
1222  bool valid = false;
1223  int i;
1224 
1225  if (validnsps)
1226  {
1227  for (i = 0; validnsps[i]; i++)
1228  {
1229  if (strcmp(def->defnamespace, validnsps[i]) == 0)
1230  {
1231  valid = true;
1232  break;
1233  }
1234  }
1235  }
1236 
1237  if (!valid)
1238  ereport(ERROR,
1239  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1240  errmsg("unrecognized parameter namespace \"%s\"",
1241  def->defnamespace)));
1242  }
1243 
1244  /* ignore if not in the same namespace */
1245  if (namspace == NULL)
1246  {
1247  if (def->defnamespace != NULL)
1248  continue;
1249  }
1250  else if (def->defnamespace == NULL)
1251  continue;
1252  else if (strcmp(def->defnamespace, namspace) != 0)
1253  continue;
1254 
1255  /*
1256  * Flatten the DefElem into a text string like "name=arg". If we
1257  * have just "name", assume "name=true" is meant. Note: the
1258  * namespace is not output.
1259  */
1260  if (def->arg != NULL)
1261  value = defGetString(def);
1262  else
1263  value = "true";
1264 
1265  /*
1266  * This is not a great place for this test, but there's no other
1267  * convenient place to filter the option out. As WITH (oids =
1268  * false) will be removed someday, this seems like an acceptable
1269  * amount of ugly.
1270  */
1271  if (acceptOidsOff && def->defnamespace == NULL &&
1272  strcmp(def->defname, "oids") == 0)
1273  {
1274  if (defGetBoolean(def))
1275  ereport(ERROR,
1276  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1277  errmsg("tables declared WITH OIDS are not supported")));
1278  /* skip over option, reloptions machinery doesn't know it */
1279  continue;
1280  }
1281 
1282  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
1283  /* +1 leaves room for sprintf's trailing null */
1284  t = (text *) palloc(len + 1);
1285  SET_VARSIZE(t, len);
1286  sprintf(VARDATA(t), "%s=%s", def->defname, value);
1287 
1288  astate = accumArrayResult(astate, PointerGetDatum(t),
1289  false, TEXTOID,
1291  }
1292  }
1293 
1294  if (astate)
1295  result = makeArrayResult(astate, CurrentMemoryContext);
1296  else
1297  result = (Datum) 0;
1298 
1299  return result;
1300 }
#define NIL
Definition: pg_list.h:65
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
#define VARHDRSZ
Definition: c.h:568
char * defnamespace
Definition: parsenodes.h:732
int errcode(int sqlerrcode)
Definition: elog.c:610
#define sprintf
Definition: port.h:195
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5144
Node * arg
Definition: parsenodes.h:734
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
#define lfirst(lc)
Definition: pg_list.h:190
size_t Size
Definition: c.h:473
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3483
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5080
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i
Definition: c.h:562
char * defname
Definition: parsenodes.h:733
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define PointerIsValid(pointer)
Definition: c.h:639
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 1308 of file reloptions.c.

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(), pg_options_to_table(), postgres_fdw_validator(), postgresql_fdw_validator(), and transformGenericOptions().

1309 {
1310  List *result = NIL;
1311  ArrayType *array;
1312  Datum *optiondatums;
1313  int noptions;
1314  int i;
1315 
1316  /* Nothing to do if no options */
1318  return result;
1319 
1320  array = DatumGetArrayTypeP(options);
1321 
1322  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1323  &optiondatums, NULL, &noptions);
1324 
1325  for (i = 0; i < noptions; i++)
1326  {
1327  char *s;
1328  char *p;
1329  Node *val = NULL;
1330 
1331  s = TextDatumGetCString(optiondatums[i]);
1332  p = strchr(s, '=');
1333  if (p)
1334  {
1335  *p++ = '\0';
1336  val = (Node *) makeString(pstrdup(p));
1337  }
1338  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1339  }
1340 
1341  return result;
1342 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1187
Definition: nodes.h:529
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
List * lappend(List *list, void *datum)
Definition: list.c:321
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3483
int i
static size_t noptions
Definition: pg_list.h:50
#define PointerIsValid(pointer)
Definition: c.h:639
long val
Definition: informix.c:664
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1977 of file reloptions.c.

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

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

1978 {
1979  static const relopt_parse_elt tab[] = {
1980  {"security_barrier", RELOPT_TYPE_BOOL,
1981  offsetof(ViewOptions, security_barrier)},
1982  {"check_option", RELOPT_TYPE_ENUM,
1983  offsetof(ViewOptions, check_option)}
1984  };
1985 
1986  return (bytea *) build_reloptions(reloptions, validate,
1988  sizeof(ViewOptions),
1989  tab, lengthof(tab));
1990 }
#define lengthof(array)
Definition: c.h:675
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:1887
Definition: c.h:562
#define offsetof(type, field)
Definition: c.h:668