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_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, 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 243 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 234 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 180 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 171 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 189 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 209 of file reloptions.h.

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

Definition at line 168 of file reloptions.h.

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

Typedef Documentation

typedef void(* validate_string_relopt)(char *value)

Definition at line 111 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_PARTITIONED 
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  RELOPT_KIND_PARTITIONED = (1 << 11),
52  /* if you add a new kind, make sure you update "last_default" too */
54  /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
55  RELOPT_KIND_MAX = (1 << 30)
56 } 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 633 of file reloptions.c.

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

634 {
635  relopt_bool *newoption;
636 
637  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
638  name, desc);
639  newoption->default_val = default_val;
640 
641  add_reloption((relopt_gen *) newoption);
642 }
bool default_val
Definition: reloptions.h:91
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:585
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:551
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 649 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().

651 {
652  relopt_int *newoption;
653 
654  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
655  name, desc);
656  newoption->default_val = default_val;
657  newoption->min = min_val;
658  newoption->max = max_val;
659 
660  add_reloption((relopt_gen *) newoption);
661 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:585
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:551
const char * name
Definition: encode.c:521
int default_val
Definition: reloptions.h:97
void add_real_reloption ( bits32  kinds,
char *  name,
char *  desc,
double  default_val,
double  min_val,
double  max_val 
)

Definition at line 668 of file reloptions.c.

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

670 {
671  relopt_real *newoption;
672 
673  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
674  name, desc);
675  newoption->default_val = default_val;
676  newoption->min = min_val;
677  newoption->max = max_val;
678 
679  add_reloption((relopt_gen *) newoption);
680 }
double default_val
Definition: reloptions.h:105
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:585
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:551
const char * name
Definition: encode.c:521
double max
Definition: reloptions.h:107
double min
Definition: reloptions.h:106
relopt_kind add_reloption_kind ( void  )

Definition at line 534 of file reloptions.c.

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

Referenced by _PG_init().

535 {
536  /* don't hand out the last bit so that the enum's behavior is portable */
538  ereport(ERROR,
539  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
540  errmsg("user-defined relation parameter types limit exceeded")));
541  last_assigned_kind <<= 1;
543 }
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:428
void add_string_reloption ( bits32  kinds,
char *  name,
char *  desc,
char *  default_val,
validate_string_relopt  validator 
)

Definition at line 692 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.

694 {
695  relopt_string *newoption;
696 
697  /* make sure the validator/default combination is sane */
698  if (validator)
699  (validator) (default_val);
700 
701  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
702  name, desc);
703  newoption->validate_cb = validator;
704  if (default_val)
705  {
707  default_val);
708  newoption->default_len = strlen(default_val);
709  newoption->default_isnull = false;
710  }
711  else
712  {
713  newoption->default_val = "";
714  newoption->default_len = 0;
715  newoption->default_isnull = true;
716  }
717 
718  add_reloption((relopt_gen *) newoption);
719 }
bool default_isnull
Definition: reloptions.h:117
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:585
validate_string_relopt validate_cb
Definition: reloptions.h:118
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:551
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1064
char * default_val
Definition: reloptions.h:119
void* allocateReloptStruct ( Size  base,
relopt_value options,
int  numoptions 
)

Definition at line 1215 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().

1216 {
1217  Size size = base;
1218  int i;
1219 
1220  for (i = 0; i < numoptions; i++)
1221  if (options[i].gen->type == RELOPT_TYPE_STRING)
1222  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1223 
1224  return palloc0(size);
1225 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:234
void * palloc0(Size size)
Definition: mcxt.c:878
size_t Size
Definition: c.h:356
int i
LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 1528 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().

1529 {
1530  LOCKMODE lockmode = NoLock;
1531  ListCell *cell;
1532 
1533  if (defList == NIL)
1534  return AccessExclusiveLock;
1535 
1536  if (need_initialization)
1538 
1539  foreach(cell, defList)
1540  {
1541  DefElem *def = (DefElem *) lfirst(cell);
1542  int i;
1543 
1544  for (i = 0; relOpts[i]; i++)
1545  {
1546  if (pg_strncasecmp(relOpts[i]->name,
1547  def->defname,
1548  relOpts[i]->namelen + 1) == 0)
1549  {
1550  if (lockmode < relOpts[i]->lockmode)
1551  lockmode = relOpts[i]->lockmode;
1552  }
1553  }
1554  }
1555 
1556  return lockmode;
1557 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:445
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:68
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:69
#define lfirst(lc)
Definition: pg_list.h:106
const char * name
Definition: encode.c:521
#define AccessExclusiveLock
Definition: lockdefs.h:45
int i
static bool need_initialization
Definition: reloptions.c:432
char * defname
Definition: parsenodes.h:719
static relopt_gen ** relOpts
Definition: reloptions.c:427
bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1462 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().

1463 {
1465  AttributeOpts *aopts;
1466  int numoptions;
1467  static const relopt_parse_elt tab[] = {
1468  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1469  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1470  };
1471 
1472  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1473  &numoptions);
1474 
1475  /* if none set, we're done */
1476  if (numoptions == 0)
1477  return NULL;
1478 
1479  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1480 
1481  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1482  validate, tab, lengthof(tab));
1483 
1484  pfree(options);
1485 
1486  return (bytea *) aopts;
1487 }
#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:1215
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:1239
#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:1020
#define offsetof(type, field)
Definition: c.h:555
bytea* default_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind 
)

Definition at line 1316 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().

1317 {
1319  StdRdOptions *rdopts;
1320  int numoptions;
1321  static const relopt_parse_elt tab[] = {
1322  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1323  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1324  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1325  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1326  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1327  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1328  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1329  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1330  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1331  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1332  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1333  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1334  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1335  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1336  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1337  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1338  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1339  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1340  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1341  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1342  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1343  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1344  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1345  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1346  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1347  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1348  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1349  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1350  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1351  {"user_catalog_table", RELOPT_TYPE_BOOL,
1352  offsetof(StdRdOptions, user_catalog_table)},
1353  {"parallel_workers", RELOPT_TYPE_INT,
1354  offsetof(StdRdOptions, parallel_workers)}
1355  };
1356 
1357  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1358 
1359  /* if none set, we're done */
1360  if (numoptions == 0)
1361  return NULL;
1362 
1363  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1364 
1365  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1366  validate, tab, lengthof(tab));
1367 
1368  pfree(options);
1369 
1370  return (bytea *) rdopts;
1371 }
#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:1215
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:1239
#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:1020
#define offsetof(type, field)
Definition: c.h:555
bytea* extractRelOptions ( HeapTuple  tuple,
TupleDesc  tupdesc,
amoptions_function  amoptions 
)

Definition at line 956 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().

958 {
959  bytea *options;
960  bool isnull;
961  Datum datum;
962  Form_pg_class classForm;
963 
964  datum = fastgetattr(tuple,
966  tupdesc,
967  &isnull);
968  if (isnull)
969  return NULL;
970 
971  classForm = (Form_pg_class) GETSTRUCT(tuple);
972 
973  /* Parse into appropriate format; don't error out here */
974  switch (classForm->relkind)
975  {
976  case RELKIND_RELATION:
977  case RELKIND_TOASTVALUE:
978  case RELKIND_MATVIEW:
980  options = heap_reloptions(classForm->relkind, datum, false);
981  break;
982  case RELKIND_VIEW:
983  options = view_reloptions(datum, false);
984  break;
985  case RELKIND_INDEX:
986  options = index_reloptions(amoptions, datum, false);
987  break;
989  options = NULL;
990  break;
991  default:
992  Assert(false); /* can't get here */
993  options = NULL; /* keep compiler quiet */
994  break;
995  }
996 
997  return options;
998 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1409
#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:1377
#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:1447
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
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 1239 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().

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

Definition at line 1409 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, RELOPT_KIND_PARTITIONED, and RELOPT_KIND_TOAST.

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

1410 {
1411  StdRdOptions *rdopts;
1412 
1413  switch (relkind)
1414  {
1415  case RELKIND_TOASTVALUE:
1416  rdopts = (StdRdOptions *)
1417  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1418  if (rdopts != NULL)
1419  {
1420  /* adjust default-only parameters for TOAST relations */
1421  rdopts->fillfactor = 100;
1422  rdopts->autovacuum.analyze_threshold = -1;
1423  rdopts->autovacuum.analyze_scale_factor = -1;
1424  }
1425  return (bytea *) rdopts;
1426  case RELKIND_RELATION:
1427  case RELKIND_MATVIEW:
1428  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1430  return default_reloptions(reloptions, validate,
1432  default:
1433  /* other relkinds are not supported */
1434  return NULL;
1435  }
1436 }
#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:1316
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 1447 of file reloptions.c.

References Assert, DatumGetPointer, NULL, and PointerIsValid.

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

1448 {
1449  Assert(amoptions != NULL);
1450 
1451  /* Assume function is strict */
1452  if (!PointerIsValid(DatumGetPointer(reloptions)))
1453  return NULL;
1454 
1455  return amoptions(reloptions, validate);
1456 }
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
#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 1020 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().

1022 {
1023  relopt_value *reloptions = NULL;
1024  int numoptions = 0;
1025  int i;
1026  int j;
1027 
1028  if (need_initialization)
1030 
1031  /* Build a list of expected options, based on kind */
1032 
1033  for (i = 0; relOpts[i]; i++)
1034  if (relOpts[i]->kinds & kind)
1035  numoptions++;
1036 
1037  if (numoptions > 0)
1038  {
1039  reloptions = palloc(numoptions * sizeof(relopt_value));
1040 
1041  for (i = 0, j = 0; relOpts[i]; i++)
1042  {
1043  if (relOpts[i]->kinds & kind)
1044  {
1045  reloptions[j].gen = relOpts[i];
1046  reloptions[j].isset = false;
1047  j++;
1048  }
1049  }
1050  }
1051 
1052  /* Done if no options */
1054  {
1056  Datum *optiondatums;
1057  int noptions;
1058 
1059  deconstruct_array(array, TEXTOID, -1, false, 'i',
1060  &optiondatums, NULL, &noptions);
1061 
1062  for (i = 0; i < noptions; i++)
1063  {
1064  char *text_str = VARDATA(optiondatums[i]);
1065  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1066  int j;
1067 
1068  /* Search for a match in reloptions */
1069  for (j = 0; j < numoptions; j++)
1070  {
1071  int kw_len = reloptions[j].gen->namelen;
1072 
1073  if (text_len > kw_len && text_str[kw_len] == '=' &&
1074  pg_strncasecmp(text_str, reloptions[j].gen->name,
1075  kw_len) == 0)
1076  {
1077  parse_one_reloption(&reloptions[j], text_str, text_len,
1078  validate);
1079  break;
1080  }
1081  }
1082 
1083  if (j >= numoptions && validate)
1084  {
1085  char *s;
1086  char *p;
1087 
1088  s = TextDatumGetCString(optiondatums[i]);
1089  p = strchr(s, '=');
1090  if (p)
1091  *p = '\0';
1092  ereport(ERROR,
1093  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1094  errmsg("unrecognized parameter \"%s\"", s)));
1095  }
1096  }
1097 
1098  /* It's worth avoiding memory leaks in this function */
1099  pfree(optiondatums);
1100  if (((void *) array) != DatumGetPointer(options))
1101  pfree(array);
1102  }
1103 
1104  *numrelopts = numoptions;
1105  return reloptions;
1106 }
static void initialize_reloptions(void)
Definition: reloptions.c:445
#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:76
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:1113
int namelen
Definition: reloptions.h:69
#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:432
static relopt_gen ** relOpts
Definition: reloptions.c:427
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 1493 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().

1494 {
1496  TableSpaceOpts *tsopts;
1497  int numoptions;
1498  static const relopt_parse_elt tab[] = {
1499  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1500  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1501  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1502  };
1503 
1504  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1505  &numoptions);
1506 
1507  /* if none set, we're done */
1508  if (numoptions == 0)
1509  return NULL;
1510 
1511  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1512 
1513  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1514  validate, tab, lengthof(tab));
1515 
1516  pfree(options);
1517 
1518  return (bytea *) tsopts;
1519 }
#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:1215
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:1239
#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:1020
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 745 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().

747 {
748  Datum result;
749  ArrayBuildState *astate;
750  ListCell *cell;
751 
752  /* no change if empty list */
753  if (defList == NIL)
754  return oldOptions;
755 
756  /* We build new array using accumArrayResult */
757  astate = NULL;
758 
759  /* Copy any oldOptions that aren't to be replaced */
760  if (PointerIsValid(DatumGetPointer(oldOptions)))
761  {
762  ArrayType *array = DatumGetArrayTypeP(oldOptions);
763  Datum *oldoptions;
764  int noldoptions;
765  int i;
766 
767  deconstruct_array(array, TEXTOID, -1, false, 'i',
768  &oldoptions, NULL, &noldoptions);
769 
770  for (i = 0; i < noldoptions; i++)
771  {
772  char *text_str = VARDATA(oldoptions[i]);
773  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
774 
775  /* Search for a match in defList */
776  foreach(cell, defList)
777  {
778  DefElem *def = (DefElem *) lfirst(cell);
779  int kw_len;
780 
781  /* ignore if not in the same namespace */
782  if (namspace == NULL)
783  {
784  if (def->defnamespace != NULL)
785  continue;
786  }
787  else if (def->defnamespace == NULL)
788  continue;
789  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
790  continue;
791 
792  kw_len = strlen(def->defname);
793  if (text_len > kw_len && text_str[kw_len] == '=' &&
794  pg_strncasecmp(text_str, def->defname, kw_len) == 0)
795  break;
796  }
797  if (!cell)
798  {
799  /* No match, so keep old option */
800  astate = accumArrayResult(astate, oldoptions[i],
801  false, TEXTOID,
803  }
804  }
805  }
806 
807  /*
808  * If CREATE/SET, add new options to array; if RESET, just check that the
809  * user didn't say RESET (option=val). (Must do this because the grammar
810  * doesn't enforce it.)
811  */
812  foreach(cell, defList)
813  {
814  DefElem *def = (DefElem *) lfirst(cell);
815 
816  if (isReset)
817  {
818  if (def->arg != NULL)
819  ereport(ERROR,
820  (errcode(ERRCODE_SYNTAX_ERROR),
821  errmsg("RESET must not include values for parameters")));
822  }
823  else
824  {
825  text *t;
826  const char *value;
827  Size len;
828 
829  /*
830  * Error out if the namespace is not valid. A NULL namespace is
831  * always valid.
832  */
833  if (def->defnamespace != NULL)
834  {
835  bool valid = false;
836  int i;
837 
838  if (validnsps)
839  {
840  for (i = 0; validnsps[i]; i++)
841  {
842  if (pg_strcasecmp(def->defnamespace,
843  validnsps[i]) == 0)
844  {
845  valid = true;
846  break;
847  }
848  }
849  }
850 
851  if (!valid)
852  ereport(ERROR,
853  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
854  errmsg("unrecognized parameter namespace \"%s\"",
855  def->defnamespace)));
856  }
857 
858  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
859  continue;
860 
861  /* ignore if not in the same namespace */
862  if (namspace == NULL)
863  {
864  if (def->defnamespace != NULL)
865  continue;
866  }
867  else if (def->defnamespace == NULL)
868  continue;
869  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
870  continue;
871 
872  /*
873  * Flatten the DefElem into a text string like "name=arg". If we
874  * have just "name", assume "name=true" is meant. Note: the
875  * namespace is not output.
876  */
877  if (def->arg != NULL)
878  value = defGetString(def);
879  else
880  value = "true";
881  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
882  /* +1 leaves room for sprintf's trailing null */
883  t = (text *) palloc(len + 1);
884  SET_VARSIZE(t, len);
885  sprintf(VARDATA(t), "%s=%s", def->defname, value);
886 
887  astate = accumArrayResult(astate, PointerGetDatum(t),
888  false, TEXTOID,
890  }
891  }
892 
893  if (astate)
894  result = makeArrayResult(astate, CurrentMemoryContext);
895  else
896  result = (Datum) 0;
897 
898  return result;
899 }
#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:718
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
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
static struct @121 value
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define ereport(elevel, rest)
Definition: elog.h:122
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5054
Node * arg
Definition: parsenodes.h:720
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:4990
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:719
#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 907 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().

908 {
909  List *result = NIL;
910  ArrayType *array;
911  Datum *optiondatums;
912  int noptions;
913  int i;
914 
915  /* Nothing to do if no options */
917  return result;
918 
919  array = DatumGetArrayTypeP(options);
920 
921  deconstruct_array(array, TEXTOID, -1, false, 'i',
922  &optiondatums, NULL, &noptions);
923 
924  for (i = 0; i < noptions; i++)
925  {
926  char *s;
927  char *p;
928  Node *val = NULL;
929 
930  s = TextDatumGetCString(optiondatums[i]);
931  p = strchr(s, '=');
932  if (p)
933  {
934  *p++ = '\0';
935  val = (Node *) makeString(pstrdup(p));
936  }
937  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
938  }
939 
940  return result;
941 }
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:509
return result
Definition: formatting.c:1633
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:544
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 1377 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().

1378 {
1380  ViewOptions *vopts;
1381  int numoptions;
1382  static const relopt_parse_elt tab[] = {
1383  {"security_barrier", RELOPT_TYPE_BOOL,
1384  offsetof(ViewOptions, security_barrier)},
1385  {"check_option", RELOPT_TYPE_STRING,
1386  offsetof(ViewOptions, check_option_offset)}
1387  };
1388 
1389  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1390 
1391  /* if none set, we're done */
1392  if (numoptions == 0)
1393  return NULL;
1394 
1395  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1396 
1397  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1398  validate, tab, lengthof(tab));
1399 
1400  pfree(options);
1401 
1402  return (bytea *) vopts;
1403 }
#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:1215
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:1239
#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:1020
#define offsetof(type, field)
Definition: c.h:555