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

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:226
#define dummyret
Definition: c.h:169

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:226
#define dummyret
Definition: c.h:169

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:226
#define dummyret
Definition: c.h:169

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:226
#define dummyret
Definition: c.h:169

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

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

589 {
590  relopt_bool *newoption;
591 
592  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
593  name, desc);
594  newoption->default_val = default_val;
595 
596  add_reloption((relopt_gen *) newoption);
597 }
bool default_val
Definition: reloptions.h:90
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:506
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 604 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().

606 {
607  relopt_int *newoption;
608 
609  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
610  name, desc);
611  newoption->default_val = default_val;
612  newoption->min = min_val;
613  newoption->max = max_val;
614 
615  add_reloption((relopt_gen *) newoption);
616 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:506
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 623 of file reloptions.c.

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

625 {
626  relopt_real *newoption;
627 
628  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
629  name, desc);
630  newoption->default_val = default_val;
631  newoption->min = min_val;
632  newoption->max = max_val;
633 
634  add_reloption((relopt_gen *) newoption);
635 }
double default_val
Definition: reloptions.h:104
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:506
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 489 of file reloptions.c.

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

Referenced by _PG_init().

490 {
491  /* don't hand out the last bit so that the enum's behavior is portable */
493  ereport(ERROR,
494  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
495  errmsg("user-defined relation parameter types limit exceeded")));
496  last_assigned_kind <<= 1;
498 }
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:383
void add_string_reloption ( bits32  kinds,
char *  name,
char *  desc,
char *  default_val,
validate_string_relopt  validator 
)

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

649 {
650  relopt_string *newoption;
651 
652  /* make sure the validator/default combination is sane */
653  if (validator)
654  (validator) (default_val);
655 
656  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
657  name, desc);
658  newoption->validate_cb = validator;
659  if (default_val)
660  {
662  default_val);
663  newoption->default_len = strlen(default_val);
664  newoption->default_isnull = false;
665  }
666  else
667  {
668  newoption->default_val = "";
669  newoption->default_len = 0;
670  newoption->default_isnull = true;
671  }
672 
673  add_reloption((relopt_gen *) newoption);
674 }
bool default_isnull
Definition: reloptions.h:116
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
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:506
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1152
char * default_val
Definition: reloptions.h:118
void* allocateReloptStruct ( Size  base,
relopt_value options,
int  numoptions 
)

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

1175 {
1176  Size size = base;
1177  int i;
1178 
1179  for (i = 0; i < numoptions; i++)
1180  if (options[i].gen->type == RELOPT_TYPE_STRING)
1181  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1182 
1183  return palloc0(size);
1184 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:233
void * palloc0(Size size)
Definition: mcxt.c:920
size_t Size
Definition: c.h:353
int i
LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

1486 {
1487  LOCKMODE lockmode = NoLock;
1488  ListCell *cell;
1489 
1490  if (defList == NIL)
1491  return AccessExclusiveLock;
1492 
1493  if (need_initialization)
1495 
1496  foreach(cell, defList)
1497  {
1498  DefElem *def = (DefElem *) lfirst(cell);
1499  int i;
1500 
1501  for (i = 0; relOpts[i]; i++)
1502  {
1503  if (pg_strncasecmp(relOpts[i]->name,
1504  def->defname,
1505  relOpts[i]->namelen + 1) == 0)
1506  {
1507  if (lockmode < relOpts[i]->lockmode)
1508  lockmode = relOpts[i]->lockmode;
1509  }
1510  }
1511  }
1512 
1513  return lockmode;
1514 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:400
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:387
char * defname
Definition: parsenodes.h:675
static relopt_gen ** relOpts
Definition: reloptions.c:382
bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

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

1420 {
1422  AttributeOpts *aopts;
1423  int numoptions;
1424  static const relopt_parse_elt tab[] = {
1425  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1426  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1427  };
1428 
1429  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1430  &numoptions);
1431 
1432  /* if none set, we're done */
1433  if (numoptions == 0)
1434  return NULL;
1435 
1436  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1437 
1438  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1439  validate, tab, lengthof(tab));
1440 
1441  pfree(options);
1442 
1443  return (bytea *) aopts;
1444 }
#define lengthof(array)
Definition: c.h:558
void pfree(void *pointer)
Definition: mcxt.c:992
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
#define offsetof(type, field)
Definition: c.h:551
bytea* default_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind 
)

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

1276 {
1278  StdRdOptions *rdopts;
1279  int numoptions;
1280  static const relopt_parse_elt tab[] = {
1281  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1282  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1283  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, enabled)},
1284  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1285  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_threshold)},
1286  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1287  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_threshold)},
1288  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1289  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_delay)},
1290  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1291  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_limit)},
1292  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1293  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_min_age)},
1294  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1295  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_max_age)},
1296  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1297  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_table_age)},
1298  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1299  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_min_age)},
1300  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1301  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_max_age)},
1302  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1303  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_table_age)},
1304  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1305  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, log_min_duration)},
1306  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1307  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
1308  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1309  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
1310  {"user_catalog_table", RELOPT_TYPE_BOOL,
1311  offsetof(StdRdOptions, user_catalog_table)},
1312  {"parallel_workers", RELOPT_TYPE_INT,
1313  offsetof(StdRdOptions, parallel_workers)}
1314  };
1315 
1316  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1317 
1318  /* if none set, we're done */
1319  if (numoptions == 0)
1320  return NULL;
1321 
1322  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1323 
1324  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1325  validate, tab, lengthof(tab));
1326 
1327  pfree(options);
1328 
1329  return (bytea *) rdopts;
1330 }
#define lengthof(array)
Definition: c.h:558
void pfree(void *pointer)
Definition: mcxt.c:992
int fillfactor
Definition: pgbench.c:112
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
#define offsetof(type, field)
Definition: c.h:551
bytea* extractRelOptions ( HeapTuple  tuple,
TupleDesc  tupdesc,
amoptions_function  amoptions 
)

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

914 {
915  bytea *options;
916  bool isnull;
917  Datum datum;
918  Form_pg_class classForm;
919 
920  datum = fastgetattr(tuple,
922  tupdesc,
923  &isnull);
924  if (isnull)
925  return NULL;
926 
927  classForm = (Form_pg_class) GETSTRUCT(tuple);
928 
929  /* Parse into appropriate format; don't error out here */
930  switch (classForm->relkind)
931  {
932  case RELKIND_RELATION:
933  case RELKIND_TOASTVALUE:
934  case RELKIND_MATVIEW:
936  options = heap_reloptions(classForm->relkind, datum, false);
937  break;
938  case RELKIND_VIEW:
939  options = view_reloptions(datum, false);
940  break;
941  case RELKIND_INDEX:
942  options = index_reloptions(amoptions, datum, false);
943  break;
945  options = NULL;
946  break;
947  default:
948  Assert(false); /* can't get here */
949  options = NULL; /* keep compiler quiet */
950  break;
951  }
952 
953  return options;
954 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1368
#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:167
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1336
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:166
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:374
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1404
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
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:435
#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 1198 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().

1202 {
1203  int i;
1204  int offset = basesize;
1205 
1206  for (i = 0; i < numoptions; i++)
1207  {
1208  int j;
1209  bool found = false;
1210 
1211  for (j = 0; j < numelems; j++)
1212  {
1213  if (pg_strcasecmp(options[i].gen->name, elems[j].optname) == 0)
1214  {
1215  relopt_string *optstring;
1216  char *itempos = ((char *) rdopts) + elems[j].offset;
1217  char *string_val;
1218 
1219  switch (options[i].gen->type)
1220  {
1221  case RELOPT_TYPE_BOOL:
1222  *(bool *) itempos = options[i].isset ?
1223  options[i].values.bool_val :
1224  ((relopt_bool *) options[i].gen)->default_val;
1225  break;
1226  case RELOPT_TYPE_INT:
1227  *(int *) itempos = options[i].isset ?
1228  options[i].values.int_val :
1229  ((relopt_int *) options[i].gen)->default_val;
1230  break;
1231  case RELOPT_TYPE_REAL:
1232  *(double *) itempos = options[i].isset ?
1233  options[i].values.real_val :
1234  ((relopt_real *) options[i].gen)->default_val;
1235  break;
1236  case RELOPT_TYPE_STRING:
1237  optstring = (relopt_string *) options[i].gen;
1238  if (options[i].isset)
1239  string_val = options[i].values.string_val;
1240  else if (!optstring->default_isnull)
1241  string_val = optstring->default_val;
1242  else
1243  string_val = NULL;
1244 
1245  if (string_val == NULL)
1246  *(int *) itempos = 0;
1247  else
1248  {
1249  strcpy((char *) rdopts + offset, string_val);
1250  *(int *) itempos = offset;
1251  offset += strlen(string_val) + 1;
1252  }
1253  break;
1254  default:
1255  elog(ERROR, "unsupported reloption type %d",
1256  options[i].gen->type);
1257  break;
1258  }
1259  found = true;
1260  break;
1261  }
1262  }
1263  if (validate && !found)
1264  elog(ERROR, "reloption \"%s\" not found in parse table",
1265  options[i].gen->name);
1266  }
1267  SET_VARSIZE(rdopts, offset);
1268 }
char * string_val
Definition: reloptions.h:82
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
union relopt_value::@40 values
#define ERROR
Definition: elog.h:43
const char * optname
Definition: reloptions.h:124
#define NULL
Definition: c.h:226
static Datum values[MAXATTR]
Definition: bootstrap.c:162
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#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 1368 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().

1369 {
1370  StdRdOptions *rdopts;
1371 
1372  switch (relkind)
1373  {
1374  case RELKIND_TOASTVALUE:
1375  rdopts = (StdRdOptions *)
1376  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1377  if (rdopts != NULL)
1378  {
1379  /* adjust default-only parameters for TOAST relations */
1380  rdopts->fillfactor = 100;
1381  rdopts->autovacuum.analyze_threshold = -1;
1382  rdopts->autovacuum.analyze_scale_factor = -1;
1383  }
1384  return (bytea *) rdopts;
1385  case RELKIND_RELATION:
1386  case RELKIND_MATVIEW:
1388  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1389  default:
1390  /* other relkinds are not supported */
1391  return NULL;
1392  }
1393 }
#define RELKIND_MATVIEW
Definition: pg_class.h:167
int fillfactor
Definition: rel.h:275
int analyze_threshold
Definition: rel.h:258
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
float8 analyze_scale_factor
Definition: rel.h:269
#define NULL
Definition: c.h:226
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1275
Definition: c.h:435
#define RELKIND_RELATION
Definition: pg_class.h:160
AutoVacOpts autovacuum
Definition: rel.h:276
bytea* index_reloptions ( amoptions_function  amoptions,
Datum  reloptions,
bool  validate 
)

Definition at line 1404 of file reloptions.c.

References Assert, DatumGetPointer, NULL, and PointerIsValid.

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

1405 {
1406  Assert(amoptions != NULL);
1407 
1408  /* Assume function is strict */
1409  if (!PointerIsValid(DatumGetPointer(reloptions)))
1410  return NULL;
1411 
1412  return amoptions(reloptions, validate);
1413 }
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define DatumGetPointer(X)
Definition: postgres.h:557
#define PointerIsValid(pointer)
Definition: c.h:522
relopt_value* parseRelOptions ( Datum  options,
bool  validate,
relopt_kind  kind,
int *  numrelopts 
)

Definition at line 975 of file reloptions.c.

References DatumGetArrayTypeP, DatumGetPointer, DatumGetTextP, 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().

977 {
978  relopt_value *reloptions;
979  int numoptions = 0;
980  int i;
981  int j;
982 
985 
986  /* Build a list of expected options, based on kind */
987 
988  for (i = 0; relOpts[i]; i++)
989  if (relOpts[i]->kinds & kind)
990  numoptions++;
991 
992  if (numoptions == 0)
993  {
994  *numrelopts = 0;
995  return NULL;
996  }
997 
998  reloptions = palloc(numoptions * sizeof(relopt_value));
999 
1000  for (i = 0, j = 0; relOpts[i]; i++)
1001  {
1002  if (relOpts[i]->kinds & kind)
1003  {
1004  reloptions[j].gen = relOpts[i];
1005  reloptions[j].isset = false;
1006  j++;
1007  }
1008  }
1009 
1010  /* Done if no options */
1012  {
1014  Datum *optiondatums;
1015  int noptions;
1016 
1017  deconstruct_array(array, TEXTOID, -1, false, 'i',
1018  &optiondatums, NULL, &noptions);
1019 
1020  for (i = 0; i < noptions; i++)
1021  {
1022  text *optiontext = DatumGetTextP(optiondatums[i]);
1023  char *text_str = VARDATA(optiontext);
1024  int text_len = VARSIZE(optiontext) - VARHDRSZ;
1025  int j;
1026 
1027  /* Search for a match in reloptions */
1028  for (j = 0; j < numoptions; j++)
1029  {
1030  int kw_len = reloptions[j].gen->namelen;
1031 
1032  if (text_len > kw_len && text_str[kw_len] == '=' &&
1033  pg_strncasecmp(text_str, reloptions[j].gen->name,
1034  kw_len) == 0)
1035  {
1036  parse_one_reloption(&reloptions[j], text_str, text_len,
1037  validate);
1038  break;
1039  }
1040  }
1041 
1042  if (j >= numoptions && validate)
1043  {
1044  char *s;
1045  char *p;
1046 
1047  s = TextDatumGetCString(optiondatums[i]);
1048  p = strchr(s, '=');
1049  if (p)
1050  *p = '\0';
1051  ereport(ERROR,
1052  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1053  errmsg("unrecognized parameter \"%s\"", s)));
1054  }
1055  }
1056 
1057  /* It's worth avoiding memory leaks in this function */
1058  pfree(optiondatums);
1059  if (((void *) array) != DatumGetPointer(options))
1060  pfree(array);
1061  }
1062 
1063  *numrelopts = numoptions;
1064  return reloptions;
1065 }
static void initialize_reloptions(void)
Definition: reloptions.c:400
#define VARDATA(PTR)
Definition: postgres.h:305
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:306
#define VARHDRSZ
Definition: c.h:441
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:992
#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:1072
int namelen
Definition: reloptions.h:68
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:91
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define DatumGetTextP(X)
Definition: fmgr.h:248
#define DatumGetPointer(X)
Definition: postgres.h:557
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:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static bool need_initialization
Definition: reloptions.c:387
Definition: c.h:435
static relopt_gen ** relOpts
Definition: reloptions.c:382
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:522
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

1451 {
1453  TableSpaceOpts *tsopts;
1454  int numoptions;
1455  static const relopt_parse_elt tab[] = {
1456  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1457  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1458  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1459  };
1460 
1461  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1462  &numoptions);
1463 
1464  /* if none set, we're done */
1465  if (numoptions == 0)
1466  return NULL;
1467 
1468  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1469 
1470  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1471  validate, tab, lengthof(tab));
1472 
1473  pfree(options);
1474 
1475  return (bytea *) tsopts;
1476 }
#define lengthof(array)
Definition: c.h:558
int effective_io_concurrency
Definition: bufmgr.c:112
double random_page_cost
Definition: costsize.c:105
void pfree(void *pointer)
Definition: mcxt.c:992
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
double seq_page_cost
Definition: costsize.c:104
#define offsetof(type, field)
Definition: c.h:551
Datum transformRelOptions ( Datum  oldOptions,
List defList,
char *  namspace,
char *  validnsps[],
bool  ignoreOids,
bool  isReset 
)

Definition at line 700 of file reloptions.c.

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

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

702 {
703  Datum result;
704  ArrayBuildState *astate;
705  ListCell *cell;
706 
707  /* no change if empty list */
708  if (defList == NIL)
709  return oldOptions;
710 
711  /* We build new array using accumArrayResult */
712  astate = NULL;
713 
714  /* Copy any oldOptions that aren't to be replaced */
715  if (PointerIsValid(DatumGetPointer(oldOptions)))
716  {
717  ArrayType *array = DatumGetArrayTypeP(oldOptions);
718  Datum *oldoptions;
719  int noldoptions;
720  int i;
721 
722  deconstruct_array(array, TEXTOID, -1, false, 'i',
723  &oldoptions, NULL, &noldoptions);
724 
725  for (i = 0; i < noldoptions; i++)
726  {
727  text *oldoption = DatumGetTextP(oldoptions[i]);
728  char *text_str = VARDATA(oldoption);
729  int text_len = VARSIZE(oldoption) - VARHDRSZ;
730 
731  /* Search for a match in defList */
732  foreach(cell, defList)
733  {
734  DefElem *def = (DefElem *) lfirst(cell);
735  int kw_len;
736 
737  /* ignore if not in the same namespace */
738  if (namspace == NULL)
739  {
740  if (def->defnamespace != NULL)
741  continue;
742  }
743  else if (def->defnamespace == NULL)
744  continue;
745  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
746  continue;
747 
748  kw_len = strlen(def->defname);
749  if (text_len > kw_len && text_str[kw_len] == '=' &&
750  pg_strncasecmp(text_str, def->defname, kw_len) == 0)
751  break;
752  }
753  if (!cell)
754  {
755  /* No match, so keep old option */
756  astate = accumArrayResult(astate, oldoptions[i],
757  false, TEXTOID,
759  }
760  }
761  }
762 
763  /*
764  * If CREATE/SET, add new options to array; if RESET, just check that the
765  * user didn't say RESET (option=val). (Must do this because the grammar
766  * doesn't enforce it.)
767  */
768  foreach(cell, defList)
769  {
770  DefElem *def = (DefElem *) lfirst(cell);
771 
772  if (isReset)
773  {
774  if (def->arg != NULL)
775  ereport(ERROR,
776  (errcode(ERRCODE_SYNTAX_ERROR),
777  errmsg("RESET must not include values for parameters")));
778  }
779  else
780  {
781  text *t;
782  const char *value;
783  Size len;
784 
785  /*
786  * Error out if the namespace is not valid. A NULL namespace is
787  * always valid.
788  */
789  if (def->defnamespace != NULL)
790  {
791  bool valid = false;
792  int i;
793 
794  if (validnsps)
795  {
796  for (i = 0; validnsps[i]; i++)
797  {
798  if (pg_strcasecmp(def->defnamespace,
799  validnsps[i]) == 0)
800  {
801  valid = true;
802  break;
803  }
804  }
805  }
806 
807  if (!valid)
808  ereport(ERROR,
809  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
810  errmsg("unrecognized parameter namespace \"%s\"",
811  def->defnamespace)));
812  }
813 
814  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
815  continue;
816 
817  /* ignore if not in the same namespace */
818  if (namspace == NULL)
819  {
820  if (def->defnamespace != NULL)
821  continue;
822  }
823  else if (def->defnamespace == NULL)
824  continue;
825  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
826  continue;
827 
828  /*
829  * Flatten the DefElem into a text string like "name=arg". If we
830  * have just "name", assume "name=true" is meant. Note: the
831  * namespace is not output.
832  */
833  if (def->arg != NULL)
834  value = defGetString(def);
835  else
836  value = "true";
837  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
838  /* +1 leaves room for sprintf's trailing null */
839  t = (text *) palloc(len + 1);
840  SET_VARSIZE(t, len);
841  sprintf(VARDATA(t), "%s=%s", def->defname, value);
842 
843  astate = accumArrayResult(astate, PointerGetDatum(t),
844  false, TEXTOID,
846  }
847  }
848 
849  if (astate)
850  result = makeArrayResult(astate, CurrentMemoryContext);
851  else
852  result = (Datum) 0;
853 
854  return result;
855 }
#define NIL
Definition: pg_list.h:69
static struct @76 value
#define VARDATA(PTR)
Definition: postgres.h:305
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:306
#define PointerGetDatum(X)
Definition: postgres.h:564
#define VARHDRSZ
Definition: c.h:441
char * defnamespace
Definition: parsenodes.h:674
int errcode(int sqlerrcode)
Definition: elog.c:575
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
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:676
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
size_t Size
Definition: c.h:353
#define DatumGetTextP(X)
Definition: fmgr.h:248
#define DatumGetPointer(X)
Definition: postgres.h:557
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:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: c.h:435
char * defname
Definition: parsenodes.h:675
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#define PointerIsValid(pointer)
Definition: c.h:522
#define DatumGetArrayTypeP(X)
Definition: array.h:242
List* untransformRelOptions ( Datum  options)

Definition at line 863 of file reloptions.c.

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

864 {
865  List *result = NIL;
866  ArrayType *array;
867  Datum *optiondatums;
868  int noptions;
869  int i;
870 
871  /* Nothing to do if no options */
873  return result;
874 
875  array = DatumGetArrayTypeP(options);
876 
877  deconstruct_array(array, TEXTOID, -1, false, 'i',
878  &optiondatums, NULL, &noptions);
879 
880  for (i = 0; i < noptions; i++)
881  {
882  char *s;
883  char *p;
884  Node *val = NULL;
885 
886  s = TextDatumGetCString(optiondatums[i]);
887  p = strchr(s, '=');
888  if (p)
889  {
890  *p++ = '\0';
891  val = (Node *) makeString(pstrdup(p));
892  }
893  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
894  }
895 
896  return result;
897 }
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:1165
Definition: nodes.h:508
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:91
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define DatumGetPointer(X)
Definition: postgres.h:557
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:522
long val
Definition: informix.c:689
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

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

1337 {
1339  ViewOptions *vopts;
1340  int numoptions;
1341  static const relopt_parse_elt tab[] = {
1342  {"security_barrier", RELOPT_TYPE_BOOL,
1343  offsetof(ViewOptions, security_barrier)},
1344  {"check_option", RELOPT_TYPE_STRING,
1345  offsetof(ViewOptions, check_option_offset)}
1346  };
1347 
1348  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1349 
1350  /* if none set, we're done */
1351  if (numoptions == 0)
1352  return NULL;
1353 
1354  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1355 
1356  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1357  validate, tab, lengthof(tab));
1358 
1359  pfree(options);
1360 
1361  return (bytea *) vopts;
1362 }
#define lengthof(array)
Definition: c.h:558
void pfree(void *pointer)
Definition: mcxt.c:992
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
#define offsetof(type, field)
Definition: c.h:551