PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_string
 
struct  relopt_parse_elt
 

Macros

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }
 
#define HAVE_RELOPTION(optname, option)   (pg_strncasecmp(option.gen->name, optname, option.gen->namelen + 1) == 0)
 
#define HANDLE_INT_RELOPTION(optname, var, option, wasset)
 
#define HANDLE_BOOL_RELOPTION(optname, var, option, wasset)
 
#define HANDLE_REAL_RELOPTION(optname, var, option, wasset)
 
#define HANDLE_STRING_RELOPTION(optname, var, option, base, offset, wasset)
 
#define GET_STRING_RELOPTION_LEN(option)
 
#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 void(* validate_string_relopt )(char *value)
 
typedef struct relopt_string relopt_string
 

Enumerations

enum  relopt_type { RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING }
 
enum  relopt_kind {
  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_LAST_DEFAULT = RELOPT_KIND_BRIN,
  RELOPT_KIND_MAX = (1 << 30)
}
 

Functions

relopt_kind add_reloption_kind (void)
 
void add_bool_reloption (bits32 kinds, char *name, char *desc, bool default_val)
 
void add_int_reloption (bits32 kinds, char *name, char *desc, int default_val, int min_val, int max_val)
 
void add_real_reloption (bits32 kinds, char *name, char *desc, double default_val, double min_val, double max_val)
 
void add_string_reloption (bits32 kinds, char *name, char *desc, char *default_val, validate_string_relopt validator)
 
Datum transformRelOptions (Datum oldOptions, List *defList, char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
 
ListuntransformRelOptions (Datum options)
 
byteaextractRelOptions (HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
 
relopt_valueparseRelOptions (Datum options, bool validate, relopt_kind kind, int *numrelopts)
 
void * allocateReloptStruct (Size base, relopt_value *options, int numoptions)
 
void fillRelOptions (void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int nelems)
 
byteadefault_reloptions (Datum reloptions, bool validate, relopt_kind kind)
 
byteaheap_reloptions (char relkind, Datum reloptions, bool validate)
 
byteaview_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

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

Definition at line 242 of file reloptions.h.

#define GET_STRING_RELOPTION_LEN (   option)
Value:
((option).isset ? strlen((option).values.string_val) : \
((relopt_string *) (option).gen)->default_len)

Definition at line 233 of file reloptions.h.

Referenced by allocateReloptStruct().

#define HANDLE_BOOL_RELOPTION (   optname,
  var,
  option,
  wasset 
)
Value:
do { \
if (option.isset) \
var = option.values.bool_val; \
else \
var = ((relopt_bool *) option.gen)->default_val; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
} while (0)
#define NULL
Definition: c.h:229
#define dummyret
Definition: c.h:172

Definition at line 179 of file reloptions.h.

#define HANDLE_INT_RELOPTION (   optname,
  var,
  option,
  wasset 
)
Value:
do { \
if (option.isset) \
var = option.values.int_val; \
else \
var = ((relopt_int *) option.gen)->default_val; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \
} while (0)
#define NULL
Definition: c.h:229
#define dummyret
Definition: c.h:172

Definition at line 170 of file reloptions.h.

#define HANDLE_REAL_RELOPTION (   optname,
  var,
  option,
  wasset 
)
Value:
do { \
if (option.isset) \
var = option.values.real_val; \
else \
var = ((relopt_real *) option.gen)->default_val; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
} while (0)
#define NULL
Definition: c.h:229
#define dummyret
Definition: c.h:172

Definition at line 188 of file reloptions.h.

#define HANDLE_STRING_RELOPTION (   optname,
  var,
  option,
  base,
  offset,
  wasset 
)
Value:
do { \
relopt_string *optstring = (relopt_string *) option.gen;\
char *string_val; \
if (option.isset) \
string_val = option.values.string_val; \
else if (!optstring->default_isnull) \
string_val = optstring->default_val; \
else \
string_val = NULL; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
if (string_val == NULL) \
var = 0; \
else \
{ \
strcpy(((char *)(base)) + (offset), string_val); \
var = (offset); \
(offset) += strlen(string_val) + 1; \
} \
} while (0)
struct relopt_string relopt_string
#define NULL
Definition: c.h:229
#define dummyret
Definition: c.h:172

Definition at line 208 of file reloptions.h.

#define HAVE_RELOPTION (   optname,
  option 
)    (pg_strncasecmp(option.gen->name, optname, option.gen->namelen + 1) == 0)

Definition at line 167 of file reloptions.h.

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

Typedef Documentation

typedef void(* validate_string_relopt)(char *value)

Definition at line 110 of file reloptions.h.

Enumeration Type Documentation

Enumerator
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_LAST_DEFAULT 
RELOPT_KIND_MAX 

Definition at line 38 of file reloptions.h.

39 {
40  RELOPT_KIND_HEAP = (1 << 0),
41  RELOPT_KIND_TOAST = (1 << 1),
42  RELOPT_KIND_BTREE = (1 << 2),
43  RELOPT_KIND_HASH = (1 << 3),
44  RELOPT_KIND_GIN = (1 << 4),
45  RELOPT_KIND_GIST = (1 << 5),
46  RELOPT_KIND_ATTRIBUTE = (1 << 6),
47  RELOPT_KIND_TABLESPACE = (1 << 7),
48  RELOPT_KIND_SPGIST = (1 << 8),
49  RELOPT_KIND_VIEW = (1 << 9),
50  RELOPT_KIND_BRIN = (1 << 10),
51  /* if you add a new kind, make sure you update "last_default" too */
53  /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
54  RELOPT_KIND_MAX = (1 << 30)
55 } relopt_kind;
relopt_kind
Definition: reloptions.h:38
Enumerator
RELOPT_TYPE_BOOL 
RELOPT_TYPE_INT 
RELOPT_TYPE_REAL 
RELOPT_TYPE_STRING 

Definition at line 29 of file reloptions.h.

Function Documentation

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

Definition at line 624 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_bool::default_val, and RELOPT_TYPE_BOOL.

625 {
626  relopt_bool *newoption;
627 
628  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
629  name, desc);
630  newoption->default_val = default_val;
631 
632  add_reloption((relopt_gen *) newoption);
633 }
bool default_val
Definition: reloptions.h:90
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
void add_int_reloption ( bits32  kinds,
char *  name,
char *  desc,
int  default_val,
int  min_val,
int  max_val 
)

Definition at line 640 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_int::default_val, relopt_int::max, relopt_int::min, and RELOPT_TYPE_INT.

Referenced by _PG_init().

642 {
643  relopt_int *newoption;
644 
645  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
646  name, desc);
647  newoption->default_val = default_val;
648  newoption->min = min_val;
649  newoption->max = max_val;
650 
651  add_reloption((relopt_gen *) newoption);
652 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
int default_val
Definition: reloptions.h:96
void add_real_reloption ( bits32  kinds,
char *  name,
char *  desc,
double  default_val,
double  min_val,
double  max_val 
)

Definition at line 659 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_real::default_val, relopt_real::max, relopt_real::min, and RELOPT_TYPE_REAL.

661 {
662  relopt_real *newoption;
663 
664  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
665  name, desc);
666  newoption->default_val = default_val;
667  newoption->min = min_val;
668  newoption->max = max_val;
669 
670  add_reloption((relopt_gen *) newoption);
671 }
double default_val
Definition: reloptions.h:104
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
double max
Definition: reloptions.h:106
double min
Definition: reloptions.h:105
relopt_kind add_reloption_kind ( void  )

Definition at line 525 of file reloptions.c.

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

Referenced by _PG_init().

526 {
527  /* don't hand out the last bit so that the enum's behavior is portable */
529  ereport(ERROR,
530  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
531  errmsg("user-defined relation parameter types limit exceeded")));
532  last_assigned_kind <<= 1;
534 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
relopt_kind
Definition: reloptions.h:38
static bits32 last_assigned_kind
Definition: reloptions.c:419
void add_string_reloption ( bits32  kinds,
char *  name,
char *  desc,
char *  default_val,
validate_string_relopt  validator 
)

Definition at line 683 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_string::default_isnull, relopt_string::default_len, relopt_string::default_val, MemoryContextStrdup(), RELOPT_TYPE_STRING, TopMemoryContext, and relopt_string::validate_cb.

685 {
686  relopt_string *newoption;
687 
688  /* make sure the validator/default combination is sane */
689  if (validator)
690  (validator) (default_val);
691 
692  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
693  name, desc);
694  newoption->validate_cb = validator;
695  if (default_val)
696  {
698  default_val);
699  newoption->default_len = strlen(default_val);
700  newoption->default_isnull = false;
701  }
702  else
703  {
704  newoption->default_val = "";
705  newoption->default_len = 0;
706  newoption->default_isnull = true;
707  }
708 
709  add_reloption((relopt_gen *) newoption);
710 }
bool default_isnull
Definition: reloptions.h:116
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
validate_string_relopt validate_cb
Definition: reloptions.h:117
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1064
char * default_val
Definition: reloptions.h:118
void* allocateReloptStruct ( Size  base,
relopt_value options,
int  numoptions 
)

Definition at line 1208 of file reloptions.c.

References GET_STRING_RELOPTION_LEN, i, palloc0(), and RELOPT_TYPE_STRING.

Referenced by attribute_reloptions(), bloptions(), brinoptions(), default_reloptions(), ginoptions(), gistoptions(), tablespace_reloptions(), and view_reloptions().

1209 {
1210  Size size = base;
1211  int i;
1212 
1213  for (i = 0; i < numoptions; i++)
1214  if (options[i].gen->type == RELOPT_TYPE_STRING)
1215  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1216 
1217  return palloc0(size);
1218 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:233
void * palloc0(Size size)
Definition: mcxt.c:878
size_t Size
Definition: c.h:356
int i
LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 1519 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

1520 {
1521  LOCKMODE lockmode = NoLock;
1522  ListCell *cell;
1523 
1524  if (defList == NIL)
1525  return AccessExclusiveLock;
1526 
1527  if (need_initialization)
1529 
1530  foreach(cell, defList)
1531  {
1532  DefElem *def = (DefElem *) lfirst(cell);
1533  int i;
1534 
1535  for (i = 0; relOpts[i]; i++)
1536  {
1537  if (pg_strncasecmp(relOpts[i]->name,
1538  def->defname,
1539  relOpts[i]->namelen + 1) == 0)
1540  {
1541  if (lockmode < relOpts[i]->lockmode)
1542  lockmode = relOpts[i]->lockmode;
1543  }
1544  }
1545  }
1546 
1547  return lockmode;
1548 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:436
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:67
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h:68
#define lfirst(lc)
Definition: pg_list.h:106
const char * name
Definition: encode.c:521
#define AccessExclusiveLock
Definition: lockdefs.h:46
int i
static bool need_initialization
Definition: reloptions.c:423
char * defname
Definition: parsenodes.h:708
static relopt_gen ** relOpts
Definition: reloptions.c:418
bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1453 of file reloptions.c.

References allocateReloptStruct(), fillRelOptions(), lengthof, NULL, offsetof, options, parseRelOptions(), pfree(), RELOPT_KIND_ATTRIBUTE, and RELOPT_TYPE_REAL.

Referenced by ATExecSetOptions(), and get_attribute_options().

1454 {
1456  AttributeOpts *aopts;
1457  int numoptions;
1458  static const relopt_parse_elt tab[] = {
1459  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1460  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1461  };
1462 
1463  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1464  &numoptions);
1465 
1466  /* if none set, we're done */
1467  if (numoptions == 0)
1468  return NULL;
1469 
1470  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1471 
1472  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1473  validate, tab, lengthof(tab));
1474 
1475  pfree(options);
1476 
1477  return (bytea *) aopts;
1478 }
#define lengthof(array)
Definition: c.h:562
void pfree(void *pointer)
Definition: mcxt.c:950
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
static char ** options
void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
#define offsetof(type, field)
Definition: c.h:555
bytea* default_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind 
)

Definition at line 1309 of file reloptions.c.

References allocateReloptStruct(), fillfactor, fillRelOptions(), lengthof, NULL, offsetof, options, parseRelOptions(), pfree(), RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, and RELOPT_TYPE_REAL.

Referenced by btoptions(), hashoptions(), heap_reloptions(), and spgoptions().

1310 {
1312  StdRdOptions *rdopts;
1313  int numoptions;
1314  static const relopt_parse_elt tab[] = {
1315  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1316  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1317  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, enabled)},
1318  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1319  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_threshold)},
1320  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1321  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_threshold)},
1322  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1323  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_delay)},
1324  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1325  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_limit)},
1326  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1327  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_min_age)},
1328  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1329  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_max_age)},
1330  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1331  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_table_age)},
1332  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1333  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_min_age)},
1334  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1335  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_max_age)},
1336  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1337  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_table_age)},
1338  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1339  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, log_min_duration)},
1340  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1341  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
1342  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1343  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
1344  {"user_catalog_table", RELOPT_TYPE_BOOL,
1345  offsetof(StdRdOptions, user_catalog_table)},
1346  {"parallel_workers", RELOPT_TYPE_INT,
1347  offsetof(StdRdOptions, parallel_workers)}
1348  };
1349 
1350  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1351 
1352  /* if none set, we're done */
1353  if (numoptions == 0)
1354  return NULL;
1355 
1356  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1357 
1358  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1359  validate, tab, lengthof(tab));
1360 
1361  pfree(options);
1362 
1363  return (bytea *) rdopts;
1364 }
#define lengthof(array)
Definition: c.h:562
void pfree(void *pointer)
Definition: mcxt.c:950
int fillfactor
Definition: pgbench.c:112
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
static char ** options
void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
#define offsetof(type, field)
Definition: c.h:555
bytea* extractRelOptions ( HeapTuple  tuple,
TupleDesc  tupdesc,
amoptions_function  amoptions 
)

Definition at line 947 of file reloptions.c.

References Anum_pg_class_reloptions, Assert, fastgetattr, GETSTRUCT, heap_reloptions(), index_reloptions(), NULL, options, RELKIND_FOREIGN_TABLE, RELKIND_INDEX, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_TOASTVALUE, RELKIND_VIEW, and view_reloptions().

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

949 {
950  bytea *options;
951  bool isnull;
952  Datum datum;
953  Form_pg_class classForm;
954 
955  datum = fastgetattr(tuple,
957  tupdesc,
958  &isnull);
959  if (isnull)
960  return NULL;
961 
962  classForm = (Form_pg_class) GETSTRUCT(tuple);
963 
964  /* Parse into appropriate format; don't error out here */
965  switch (classForm->relkind)
966  {
967  case RELKIND_RELATION:
968  case RELKIND_TOASTVALUE:
969  case RELKIND_MATVIEW:
971  options = heap_reloptions(classForm->relkind, datum, false);
972  break;
973  case RELKIND_VIEW:
974  options = view_reloptions(datum, false);
975  break;
976  case RELKIND_INDEX:
977  options = index_reloptions(amoptions, datum, false);
978  break;
980  options = NULL;
981  break;
982  default:
983  Assert(false); /* can't get here */
984  options = NULL; /* keep compiler quiet */
985  break;
986  }
987 
988  return options;
989 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1402
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:719
#define Anum_pg_class_reloptions
Definition: pg_class.h:134
#define RELKIND_MATVIEW
Definition: pg_class.h:165
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1370
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
static char ** options
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
uintptr_t Datum
Definition: postgres.h:372
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1438
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RELKIND_INDEX
Definition: pg_class.h:161
Definition: c.h:439
#define RELKIND_RELATION
Definition: pg_class.h:160
void fillRelOptions ( void *  rdopts,
Size  basesize,
relopt_value options,
int  numoptions,
bool  validate,
const relopt_parse_elt elems,
int  nelems 
)

Definition at line 1232 of file reloptions.c.

References relopt_string::default_isnull, relopt_string::default_val, elog, ERROR, relopt_value::gen, i, NULL, relopt_parse_elt::offset, relopt_parse_elt::optname, pg_strcasecmp(), RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, SET_VARSIZE, relopt_value::string_val, relopt_value::values, and values.

Referenced by attribute_reloptions(), bloptions(), brinoptions(), default_reloptions(), ginoptions(), gistoptions(), tablespace_reloptions(), and view_reloptions().

1236 {
1237  int i;
1238  int offset = basesize;
1239 
1240  for (i = 0; i < numoptions; i++)
1241  {
1242  int j;
1243  bool found = false;
1244 
1245  for (j = 0; j < numelems; j++)
1246  {
1247  if (pg_strcasecmp(options[i].gen->name, elems[j].optname) == 0)
1248  {
1249  relopt_string *optstring;
1250  char *itempos = ((char *) rdopts) + elems[j].offset;
1251  char *string_val;
1252 
1253  switch (options[i].gen->type)
1254  {
1255  case RELOPT_TYPE_BOOL:
1256  *(bool *) itempos = options[i].isset ?
1257  options[i].values.bool_val :
1258  ((relopt_bool *) options[i].gen)->default_val;
1259  break;
1260  case RELOPT_TYPE_INT:
1261  *(int *) itempos = options[i].isset ?
1262  options[i].values.int_val :
1263  ((relopt_int *) options[i].gen)->default_val;
1264  break;
1265  case RELOPT_TYPE_REAL:
1266  *(double *) itempos = options[i].isset ?
1267  options[i].values.real_val :
1268  ((relopt_real *) options[i].gen)->default_val;
1269  break;
1270  case RELOPT_TYPE_STRING:
1271  optstring = (relopt_string *) options[i].gen;
1272  if (options[i].isset)
1273  string_val = options[i].values.string_val;
1274  else if (!optstring->default_isnull)
1275  string_val = optstring->default_val;
1276  else
1277  string_val = NULL;
1278 
1279  if (string_val == NULL)
1280  *(int *) itempos = 0;
1281  else
1282  {
1283  strcpy((char *) rdopts + offset, string_val);
1284  *(int *) itempos = offset;
1285  offset += strlen(string_val) + 1;
1286  }
1287  break;
1288  default:
1289  elog(ERROR, "unsupported reloption type %d",
1290  options[i].gen->type);
1291  break;
1292  }
1293  found = true;
1294  break;
1295  }
1296  }
1297  if (validate && !found)
1298  elog(ERROR, "reloption \"%s\" not found in parse table",
1299  options[i].gen->name);
1300  }
1301  SET_VARSIZE(rdopts, offset);
1302 }
char * string_val
Definition: reloptions.h:82
union relopt_value::@41 values
bool default_isnull
Definition: reloptions.h:116
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
relopt_gen * gen
Definition: reloptions.h:75
#define ERROR
Definition: elog.h:43
const char * optname
Definition: reloptions.h:124
#define NULL
Definition: c.h:229
static Datum values[MAXATTR]
Definition: bootstrap.c:162
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define elog
Definition: elog.h:219
char * default_val
Definition: reloptions.h:118
bytea* heap_reloptions ( char  relkind,
Datum  reloptions,
bool  validate 
)

Definition at line 1402 of file reloptions.c.

References AutoVacOpts::analyze_scale_factor, AutoVacOpts::analyze_threshold, StdRdOptions::autovacuum, default_reloptions(), StdRdOptions::fillfactor, NULL, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_TOASTVALUE, RELOPT_KIND_HEAP, and RELOPT_KIND_TOAST.

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

1403 {
1404  StdRdOptions *rdopts;
1405 
1406  switch (relkind)
1407  {
1408  case RELKIND_TOASTVALUE:
1409  rdopts = (StdRdOptions *)
1410  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1411  if (rdopts != NULL)
1412  {
1413  /* adjust default-only parameters for TOAST relations */
1414  rdopts->fillfactor = 100;
1415  rdopts->autovacuum.analyze_threshold = -1;
1416  rdopts->autovacuum.analyze_scale_factor = -1;
1417  }
1418  return (bytea *) rdopts;
1419  case RELKIND_RELATION:
1420  case RELKIND_MATVIEW:
1422  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1423  default:
1424  /* other relkinds are not supported */
1425  return NULL;
1426  }
1427 }
#define RELKIND_MATVIEW
Definition: pg_class.h:165
int fillfactor
Definition: rel.h:279
int analyze_threshold
Definition: rel.h:262
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
float8 analyze_scale_factor
Definition: rel.h:273
#define NULL
Definition: c.h:229
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1309
Definition: c.h:439
#define RELKIND_RELATION
Definition: pg_class.h:160
AutoVacOpts autovacuum
Definition: rel.h:280
bytea* index_reloptions ( amoptions_function  amoptions,
Datum  reloptions,
bool  validate 
)

Definition at line 1438 of file reloptions.c.

References Assert, DatumGetPointer, NULL, and PointerIsValid.

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

1439 {
1440  Assert(amoptions != NULL);
1441 
1442  /* Assume function is strict */
1443  if (!PointerIsValid(DatumGetPointer(reloptions)))
1444  return NULL;
1445 
1446  return amoptions(reloptions, validate);
1447 }
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define DatumGetPointer(X)
Definition: postgres.h:555
#define PointerIsValid(pointer)
Definition: c.h:526
relopt_value* parseRelOptions ( Datum  options,
bool  validate,
relopt_kind  kind,
int *  numrelopts 
)

Definition at line 1010 of file reloptions.c.

References DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), ereport, errcode(), errmsg(), ERROR, relopt_value::gen, i, initialize_reloptions(), relopt_value::isset, relopt_gen::namelen, need_initialization, noptions, NULL, palloc(), parse_one_reloption(), pfree(), pg_strncasecmp(), PointerIsValid, TextDatumGetCString, TEXTOID, VARDATA, VARHDRSZ, and VARSIZE.

Referenced by attribute_reloptions(), bloptions(), brinoptions(), default_reloptions(), ginoptions(), gistoptions(), tablespace_reloptions(), and view_reloptions().

1012 {
1013  relopt_value *reloptions;
1014  int numoptions = 0;
1015  int i;
1016  int j;
1017 
1018  if (need_initialization)
1020 
1021  /* Build a list of expected options, based on kind */
1022 
1023  for (i = 0; relOpts[i]; i++)
1024  if (relOpts[i]->kinds & kind)
1025  numoptions++;
1026 
1027  if (numoptions == 0)
1028  {
1029  *numrelopts = 0;
1030  return NULL;
1031  }
1032 
1033  reloptions = palloc(numoptions * sizeof(relopt_value));
1034 
1035  for (i = 0, j = 0; relOpts[i]; i++)
1036  {
1037  if (relOpts[i]->kinds & kind)
1038  {
1039  reloptions[j].gen = relOpts[i];
1040  reloptions[j].isset = false;
1041  j++;
1042  }
1043  }
1044 
1045  /* Done if no options */
1047  {
1049  Datum *optiondatums;
1050  int noptions;
1051 
1052  deconstruct_array(array, TEXTOID, -1, false, 'i',
1053  &optiondatums, NULL, &noptions);
1054 
1055  for (i = 0; i < noptions; i++)
1056  {
1057  char *text_str = VARDATA(optiondatums[i]);
1058  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1059  int j;
1060 
1061  /* Search for a match in reloptions */
1062  for (j = 0; j < numoptions; j++)
1063  {
1064  int kw_len = reloptions[j].gen->namelen;
1065 
1066  if (text_len > kw_len && text_str[kw_len] == '=' &&
1067  pg_strncasecmp(text_str, reloptions[j].gen->name,
1068  kw_len) == 0)
1069  {
1070  parse_one_reloption(&reloptions[j], text_str, text_len,
1071  validate);
1072  break;
1073  }
1074  }
1075 
1076  if (j >= numoptions && validate)
1077  {
1078  char *s;
1079  char *p;
1080 
1081  s = TextDatumGetCString(optiondatums[i]);
1082  p = strchr(s, '=');
1083  if (p)
1084  *p = '\0';
1085  ereport(ERROR,
1086  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1087  errmsg("unrecognized parameter \"%s\"", s)));
1088  }
1089  }
1090 
1091  /* It's worth avoiding memory leaks in this function */
1092  pfree(optiondatums);
1093  if (((void *) array) != DatumGetPointer(options))
1094  pfree(array);
1095  }
1096 
1097  *numrelopts = numoptions;
1098  return reloptions;
1099 }
static void initialize_reloptions(void)
Definition: reloptions.c:436
#define VARDATA(PTR)
Definition: postgres.h:303
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define VARHDRSZ
Definition: c.h:445
int errcode(int sqlerrcode)
Definition: elog.c:575
relopt_gen * gen
Definition: reloptions.h:75
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
static void parse_one_reloption(relopt_value *option, char *text_str, int text_len, bool validate)
Definition: reloptions.c:1106
int namelen
Definition: reloptions.h:68
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
#define DatumGetPointer(X)
Definition: postgres.h:555
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3475
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static bool need_initialization
Definition: reloptions.c:423
static relopt_gen ** relOpts
Definition: reloptions.c:418
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:526
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1484 of file reloptions.c.

References allocateReloptStruct(), effective_io_concurrency, fillRelOptions(), lengthof, NULL, offsetof, options, parseRelOptions(), pfree(), random_page_cost, RELOPT_KIND_TABLESPACE, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, and seq_page_cost.

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

1485 {
1487  TableSpaceOpts *tsopts;
1488  int numoptions;
1489  static const relopt_parse_elt tab[] = {
1490  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1491  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1492  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1493  };
1494 
1495  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1496  &numoptions);
1497 
1498  /* if none set, we're done */
1499  if (numoptions == 0)
1500  return NULL;
1501 
1502  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1503 
1504  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1505  validate, tab, lengthof(tab));
1506 
1507  pfree(options);
1508 
1509  return (bytea *) tsopts;
1510 }
#define lengthof(array)
Definition: c.h:562
int effective_io_concurrency
Definition: bufmgr.c:112
double random_page_cost
Definition: costsize.c:105
void pfree(void *pointer)
Definition: mcxt.c:950
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
static char ** options
void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
double seq_page_cost
Definition: costsize.c:104
#define offsetof(type, field)
Definition: c.h:555
Datum transformRelOptions ( Datum  oldOptions,
List defList,
char *  namspace,
char *  validnsps[],
bool  ignoreOids,
bool  isReset 
)

Definition at line 736 of file reloptions.c.

References accumArrayResult(), DefElem::arg, CurrentMemoryContext, DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), defGetString(), DefElem::defname, DefElem::defnamespace, ereport, errcode(), errmsg(), ERROR, i, lfirst, makeArrayResult(), NIL, NULL, palloc(), pg_strcasecmp(), pg_strncasecmp(), PointerGetDatum, PointerIsValid, result, SET_VARSIZE, TEXTOID, value, VARDATA, VARHDRSZ, and VARSIZE.

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

738 {
739  Datum result;
740  ArrayBuildState *astate;
741  ListCell *cell;
742 
743  /* no change if empty list */
744  if (defList == NIL)
745  return oldOptions;
746 
747  /* We build new array using accumArrayResult */
748  astate = NULL;
749 
750  /* Copy any oldOptions that aren't to be replaced */
751  if (PointerIsValid(DatumGetPointer(oldOptions)))
752  {
753  ArrayType *array = DatumGetArrayTypeP(oldOptions);
754  Datum *oldoptions;
755  int noldoptions;
756  int i;
757 
758  deconstruct_array(array, TEXTOID, -1, false, 'i',
759  &oldoptions, NULL, &noldoptions);
760 
761  for (i = 0; i < noldoptions; i++)
762  {
763  char *text_str = VARDATA(oldoptions[i]);
764  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
765 
766  /* Search for a match in defList */
767  foreach(cell, defList)
768  {
769  DefElem *def = (DefElem *) lfirst(cell);
770  int kw_len;
771 
772  /* ignore if not in the same namespace */
773  if (namspace == NULL)
774  {
775  if (def->defnamespace != NULL)
776  continue;
777  }
778  else if (def->defnamespace == NULL)
779  continue;
780  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
781  continue;
782 
783  kw_len = strlen(def->defname);
784  if (text_len > kw_len && text_str[kw_len] == '=' &&
785  pg_strncasecmp(text_str, def->defname, kw_len) == 0)
786  break;
787  }
788  if (!cell)
789  {
790  /* No match, so keep old option */
791  astate = accumArrayResult(astate, oldoptions[i],
792  false, TEXTOID,
794  }
795  }
796  }
797 
798  /*
799  * If CREATE/SET, add new options to array; if RESET, just check that the
800  * user didn't say RESET (option=val). (Must do this because the grammar
801  * doesn't enforce it.)
802  */
803  foreach(cell, defList)
804  {
805  DefElem *def = (DefElem *) lfirst(cell);
806 
807  if (isReset)
808  {
809  if (def->arg != NULL)
810  ereport(ERROR,
811  (errcode(ERRCODE_SYNTAX_ERROR),
812  errmsg("RESET must not include values for parameters")));
813  }
814  else
815  {
816  text *t;
817  const char *value;
818  Size len;
819 
820  /*
821  * Error out if the namespace is not valid. A NULL namespace is
822  * always valid.
823  */
824  if (def->defnamespace != NULL)
825  {
826  bool valid = false;
827  int i;
828 
829  if (validnsps)
830  {
831  for (i = 0; validnsps[i]; i++)
832  {
833  if (pg_strcasecmp(def->defnamespace,
834  validnsps[i]) == 0)
835  {
836  valid = true;
837  break;
838  }
839  }
840  }
841 
842  if (!valid)
843  ereport(ERROR,
844  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
845  errmsg("unrecognized parameter namespace \"%s\"",
846  def->defnamespace)));
847  }
848 
849  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
850  continue;
851 
852  /* ignore if not in the same namespace */
853  if (namspace == NULL)
854  {
855  if (def->defnamespace != NULL)
856  continue;
857  }
858  else if (def->defnamespace == NULL)
859  continue;
860  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
861  continue;
862 
863  /*
864  * Flatten the DefElem into a text string like "name=arg". If we
865  * have just "name", assume "name=true" is meant. Note: the
866  * namespace is not output.
867  */
868  if (def->arg != NULL)
869  value = defGetString(def);
870  else
871  value = "true";
872  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
873  /* +1 leaves room for sprintf's trailing null */
874  t = (text *) palloc(len + 1);
875  SET_VARSIZE(t, len);
876  sprintf(VARDATA(t), "%s=%s", def->defname, value);
877 
878  astate = accumArrayResult(astate, PointerGetDatum(t),
879  false, TEXTOID,
881  }
882  }
883 
884  if (astate)
885  result = makeArrayResult(astate, CurrentMemoryContext);
886  else
887  result = (Datum) 0;
888 
889  return result;
890 }
#define NIL
Definition: pg_list.h:69
#define VARDATA(PTR)
Definition: postgres.h:303
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define PointerGetDatum(X)
Definition: postgres.h:562
#define VARHDRSZ
Definition: c.h:445
char * defnamespace
Definition: parsenodes.h:707
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
static struct @114 value
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define ereport(elevel, rest)
Definition: elog.h:122
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5055
Node * arg
Definition: parsenodes.h:709
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
size_t Size
Definition: c.h:356
#define DatumGetPointer(X)
Definition: postgres.h:555
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3475
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:4991
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: c.h:439
char * defname
Definition: parsenodes.h:708
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define PointerIsValid(pointer)
Definition: c.h:526
#define DatumGetArrayTypeP(X)
Definition: array.h:242
List* untransformRelOptions ( Datum  options)

Definition at line 898 of file reloptions.c.

References DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), i, lappend(), makeDefElem(), makeString(), NIL, noptions, NULL, PointerIsValid, pstrdup(), result, TextDatumGetCString, TEXTOID, and val.

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

899 {
900  List *result = NIL;
901  ArrayType *array;
902  Datum *optiondatums;
903  int noptions;
904  int i;
905 
906  /* Nothing to do if no options */
908  return result;
909 
910  array = DatumGetArrayTypeP(options);
911 
912  deconstruct_array(array, TEXTOID, -1, false, 'i',
913  &optiondatums, NULL, &noptions);
914 
915  for (i = 0; i < noptions; i++)
916  {
917  char *s;
918  char *p;
919  Node *val = NULL;
920 
921  s = TextDatumGetCString(optiondatums[i]);
922  p = strchr(s, '=');
923  if (p)
924  {
925  *p++ = '\0';
926  val = (Node *) makeString(pstrdup(p));
927  }
928  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
929  }
930 
931  return result;
932 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:69
#define TEXTOID
Definition: pg_type.h:324
char * pstrdup(const char *in)
Definition: mcxt.c:1077
Definition: nodes.h:506
return result
Definition: formatting.c:1618
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:543
List * lappend(List *list, void *datum)
Definition: list.c:128
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
#define DatumGetPointer(X)
Definition: postgres.h:555
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3475
int i
static size_t noptions
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:526
long val
Definition: informix.c:689
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1370 of file reloptions.c.

References allocateReloptStruct(), fillRelOptions(), lengthof, NULL, offsetof, options, parseRelOptions(), pfree(), RELOPT_KIND_VIEW, RELOPT_TYPE_BOOL, and RELOPT_TYPE_STRING.

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

1371 {
1373  ViewOptions *vopts;
1374  int numoptions;
1375  static const relopt_parse_elt tab[] = {
1376  {"security_barrier", RELOPT_TYPE_BOOL,
1377  offsetof(ViewOptions, security_barrier)},
1378  {"check_option", RELOPT_TYPE_STRING,
1379  offsetof(ViewOptions, check_option_offset)}
1380  };
1381 
1382  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1383 
1384  /* if none set, we're done */
1385  if (numoptions == 0)
1386  return NULL;
1387 
1388  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1389 
1390  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1391  validate, tab, lengthof(tab));
1392 
1393  pfree(options);
1394 
1395  return (bytea *) vopts;
1396 }
#define lengthof(array)
Definition: c.h:562
void pfree(void *pointer)
Definition: mcxt.c:950
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
static char ** options
void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
#define offsetof(type, field)
Definition: c.h:555