PostgreSQL Source Code  git master
reloptions.h File Reference
#include "access/amapi.h"
#include "access/htup.h"
#include "access/tupdesc.h"
#include "nodes/pg_list.h"
#include "storage/lock.h"
Include dependency graph for reloptions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  relopt_gen
 
struct  relopt_value
 
struct  relopt_bool
 
struct  relopt_int
 
struct  relopt_real
 
struct  relopt_string
 
struct  relopt_parse_elt
 

Macros

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }
 
#define HAVE_RELOPTION(optname, option)   (strncmp(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) (const 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_INDEX = RELOPT_KIND_BTREE|RELOPT_KIND_HASH|RELOPT_KIND_GIN|RELOPT_KIND_SPGIST, RELOPT_KIND_MAX = (1 << 30)
}
 

Functions

relopt_kind add_reloption_kind (void)
 
void add_bool_reloption (bits32 kinds, const char *name, const char *desc, bool default_val)
 
void add_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val)
 
void add_real_reloption (bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val)
 
void add_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator)
 
Datum transformRelOptions (Datum oldOptions, List *defList, const 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)
 
byteaindex_generic_reloptions (Datum reloptions, bool validate)
 
byteaattribute_reloptions (Datum reloptions, bool validate)
 
byteatablespace_reloptions (Datum reloptions, bool validate)
 
LOCKMODE AlterTableGetRelOptionsLockLevel (List *defList)
 

Macro Definition Documentation

◆ GET_STRING_RELOPTION

#define GET_STRING_RELOPTION (   optstruct,
  member 
)
Value:
((optstruct)->member == 0 ? NULL : \
(char *)(optstruct) + (optstruct)->member)
Oid member

Definition at line 244 of file reloptions.h.

◆ GET_STRING_RELOPTION_LEN

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

Definition at line 235 of file reloptions.h.

Referenced by allocateReloptStruct().

◆ HANDLE_BOOL_RELOPTION

#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 dummyret
Definition: c.h:234

Definition at line 181 of file reloptions.h.

◆ HANDLE_INT_RELOPTION

#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 dummyret
Definition: c.h:234

Definition at line 172 of file reloptions.h.

◆ HANDLE_REAL_RELOPTION

#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 dummyret
Definition: c.h:234

Definition at line 190 of file reloptions.h.

◆ HANDLE_STRING_RELOPTION

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

Definition at line 210 of file reloptions.h.

◆ HAVE_RELOPTION

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

Definition at line 169 of file reloptions.h.

◆ HEAP_RELOPT_NAMESPACES

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

Typedef Documentation

◆ relopt_bool

◆ relopt_gen

◆ relopt_int

◆ relopt_kind

◆ relopt_real

◆ relopt_string

◆ relopt_type

◆ relopt_value

◆ validate_string_relopt

typedef void(* validate_string_relopt) (const char *value)

Definition at line 112 of file reloptions.h.

Enumeration Type Documentation

◆ relopt_kind

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_INDEX 
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 */
55  /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
56  RELOPT_KIND_MAX = (1 << 30)
57 } relopt_kind;
relopt_kind
Definition: reloptions.h:38

◆ relopt_type

Enumerator
RELOPT_TYPE_BOOL 
RELOPT_TYPE_INT 
RELOPT_TYPE_REAL 
RELOPT_TYPE_STRING 

Definition at line 29 of file reloptions.h.

Function Documentation

◆ add_bool_reloption()

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

Definition at line 661 of file reloptions.c.

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

662 {
663  relopt_bool *newoption;
664 
665  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
666  name, desc);
667  newoption->default_val = default_val;
668 
669  add_reloption((relopt_gen *) newoption);
670 }
bool default_val
Definition: reloptions.h:92
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:613
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:579
const char * name
Definition: encode.c:521

◆ add_int_reloption()

void add_int_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
int  default_val,
int  min_val,
int  max_val 
)

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

679 {
680  relopt_int *newoption;
681 
682  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
683  name, desc);
684  newoption->default_val = default_val;
685  newoption->min = min_val;
686  newoption->max = max_val;
687 
688  add_reloption((relopt_gen *) newoption);
689 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:613
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:579
const char * name
Definition: encode.c:521
int default_val
Definition: reloptions.h:98

◆ add_real_reloption()

void add_real_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
double  default_val,
double  min_val,
double  max_val 
)

Definition at line 696 of file reloptions.c.

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

698 {
699  relopt_real *newoption;
700 
701  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
702  name, desc);
703  newoption->default_val = default_val;
704  newoption->min = min_val;
705  newoption->max = max_val;
706 
707  add_reloption((relopt_gen *) newoption);
708 }
double default_val
Definition: reloptions.h:106
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:613
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:579
const char * name
Definition: encode.c:521
double max
Definition: reloptions.h:108
double min
Definition: reloptions.h:107

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 562 of file reloptions.c.

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

Referenced by _PG_init().

563 {
564  /* don't hand out the last bit so that the enum's behavior is portable */
566  ereport(ERROR,
567  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
568  errmsg("user-defined relation parameter types limit exceeded")));
569  last_assigned_kind <<= 1;
571 }
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:456

◆ add_string_reloption()

void add_string_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
const char *  default_val,
validate_string_relopt  validator 
)

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

722 {
723  relopt_string *newoption;
724 
725  /* make sure the validator/default combination is sane */
726  if (validator)
727  (validator) (default_val);
728 
729  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
730  name, desc);
731  newoption->validate_cb = validator;
732  if (default_val)
733  {
735  default_val);
736  newoption->default_len = strlen(default_val);
737  newoption->default_isnull = false;
738  }
739  else
740  {
741  newoption->default_val = "";
742  newoption->default_len = 0;
743  newoption->default_isnull = true;
744  }
745 
746  add_reloption((relopt_gen *) newoption);
747 }
bool default_isnull
Definition: reloptions.h:118
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:613
validate_string_relopt validate_cb
Definition: reloptions.h:119
MemoryContext TopMemoryContext
Definition: mcxt.c:44
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:579
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1148
char * default_val
Definition: reloptions.h:120

◆ allocateReloptStruct()

void* allocateReloptStruct ( Size  base,
relopt_value options,
int  numoptions 
)

Definition at line 1242 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(), index_generic_reloptions(), tablespace_reloptions(), and view_reloptions().

1243 {
1244  Size size = base;
1245  int i;
1246 
1247  for (i = 0; i < numoptions; i++)
1248  if (options[i].gen->type == RELOPT_TYPE_STRING)
1249  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1250 
1251  return palloc0(size);
1252 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:235
void * palloc0(Size size)
Definition: mcxt.c:955
size_t Size
Definition: c.h:433
int i

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 1593 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

1594 {
1595  LOCKMODE lockmode = NoLock;
1596  ListCell *cell;
1597 
1598  if (defList == NIL)
1599  return AccessExclusiveLock;
1600 
1601  if (need_initialization)
1603 
1604  foreach(cell, defList)
1605  {
1606  DefElem *def = (DefElem *) lfirst(cell);
1607  int i;
1608 
1609  for (i = 0; relOpts[i]; i++)
1610  {
1611  if (strncmp(relOpts[i]->name,
1612  def->defname,
1613  relOpts[i]->namelen + 1) == 0)
1614  {
1615  if (lockmode < relOpts[i]->lockmode)
1616  lockmode = relOpts[i]->lockmode;
1617  }
1618  }
1619  }
1620 
1621  return lockmode;
1622 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:473
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:69
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h:70
#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:460
char * defname
Definition: parsenodes.h:730
static relopt_gen ** relOpts
Definition: reloptions.c:455

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1527 of file reloptions.c.

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

Referenced by ATExecSetOptions(), and get_attribute_options().

1528 {
1530  AttributeOpts *aopts;
1531  int numoptions;
1532  static const relopt_parse_elt tab[] = {
1533  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1534  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1535  };
1536 
1537  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1538  &numoptions);
1539 
1540  /* if none set, we're done */
1541  if (numoptions == 0)
1542  return NULL;
1543 
1544  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1545 
1546  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1547  validate, tab, lengthof(tab));
1548 
1549  pfree(options);
1550 
1551  return (bytea *) aopts;
1552 }
#define lengthof(array)
Definition: c.h:629
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1242
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:1266
Definition: c.h:516
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1048
#define offsetof(type, field)
Definition: c.h:622

◆ default_reloptions()

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

Definition at line 1343 of file reloptions.c.

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

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

1344 {
1346  StdRdOptions *rdopts;
1347  int numoptions;
1348  static const relopt_parse_elt tab[] = {
1349  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1350  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1351  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1352  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1353  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1354  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1355  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1356  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1357  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1358  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1359  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1360  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1361  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1362  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1363  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1364  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1365  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1366  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1367  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1368  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1369  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1370  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1371  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1372  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1373  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1374  {"toast_tuple_target", RELOPT_TYPE_INT,
1375  offsetof(StdRdOptions, toast_tuple_target)},
1376  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1377  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1378  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1379  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1380  {"user_catalog_table", RELOPT_TYPE_BOOL,
1381  offsetof(StdRdOptions, user_catalog_table)},
1382  {"parallel_workers", RELOPT_TYPE_INT,
1383  offsetof(StdRdOptions, parallel_workers)},
1384  {"vacuum_cleanup_index_scale_factor", RELOPT_TYPE_REAL,
1386  };
1387 
1388  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1389 
1390  /* if none set, we're done */
1391  if (numoptions == 0)
1392  return NULL;
1393 
1394  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1395 
1396  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1397  validate, tab, lengthof(tab));
1398 
1399  pfree(options);
1400 
1401  return (bytea *) rdopts;
1402 }
double vacuum_cleanup_index_scale_factor
Definition: globals.c:151
#define lengthof(array)
Definition: c.h:629
void pfree(void *pointer)
Definition: mcxt.c:1031
int fillfactor
Definition: pgbench.c:126
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1242
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:1266
Definition: c.h:516
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1048
#define offsetof(type, field)
Definition: c.h:622

◆ extractRelOptions()

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

Definition at line 983 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

985 {
986  bytea *options;
987  bool isnull;
988  Datum datum;
989  Form_pg_class classForm;
990 
991  datum = fastgetattr(tuple,
992  Anum_pg_class_reloptions,
993  tupdesc,
994  &isnull);
995  if (isnull)
996  return NULL;
997 
998  classForm = (Form_pg_class) GETSTRUCT(tuple);
999 
1000  /* Parse into appropriate format; don't error out here */
1001  switch (classForm->relkind)
1002  {
1003  case RELKIND_RELATION:
1004  case RELKIND_TOASTVALUE:
1005  case RELKIND_MATVIEW:
1006  case RELKIND_PARTITIONED_TABLE:
1007  options = heap_reloptions(classForm->relkind, datum, false);
1008  break;
1009  case RELKIND_VIEW:
1010  options = view_reloptions(datum, false);
1011  break;
1012  case RELKIND_INDEX:
1013  case RELKIND_PARTITIONED_INDEX:
1014  options = index_reloptions(amoptions, datum, false);
1015  break;
1016  case RELKIND_FOREIGN_TABLE:
1017  options = NULL;
1018  break;
1019  default:
1020  Assert(false); /* can't get here */
1021  options = NULL; /* keep compiler quiet */
1022  break;
1023  }
1024 
1025  return options;
1026 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1440
#define GETSTRUCT(TUP)
Definition: htup_details.h:673
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:736
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1408
static char ** options
uintptr_t Datum
Definition: postgres.h:365
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1478
#define Assert(condition)
Definition: c.h:699
FormData_pg_class * Form_pg_class
Definition: pg_class.h:92
Definition: c.h:516

◆ fillRelOptions()

void fillRelOptions ( void *  rdopts,
Size  basesize,
relopt_value options,
int  numoptions,
bool  validate,
const relopt_parse_elt elems,
int  nelems 
)

Definition at line 1266 of file reloptions.c.

References relopt_string::default_isnull, relopt_string::default_val, elog, ERROR, relopt_value::gen, i, relopt_parse_elt::offset, relopt_parse_elt::optname, RELOPT_KIND_INDEX, 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(), index_generic_reloptions(), tablespace_reloptions(), and view_reloptions().

1270 {
1271  int i;
1272  int offset = basesize;
1273 
1274  for (i = 0; i < numoptions; i++)
1275  {
1276  int j;
1277  bool found = false;
1278 
1279  for (j = 0; j < numelems; j++)
1280  {
1281  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1282  {
1283  relopt_string *optstring;
1284  char *itempos = ((char *) rdopts) + elems[j].offset;
1285  char *string_val;
1286 
1287  switch (options[i].gen->type)
1288  {
1289  case RELOPT_TYPE_BOOL:
1290  *(bool *) itempos = options[i].isset ?
1291  options[i].values.bool_val :
1292  ((relopt_bool *) options[i].gen)->default_val;
1293  break;
1294  case RELOPT_TYPE_INT:
1295  *(int *) itempos = options[i].isset ?
1296  options[i].values.int_val :
1297  ((relopt_int *) options[i].gen)->default_val;
1298  break;
1299  case RELOPT_TYPE_REAL:
1300  *(double *) itempos = options[i].isset ?
1301  options[i].values.real_val :
1302  ((relopt_real *) options[i].gen)->default_val;
1303  break;
1304  case RELOPT_TYPE_STRING:
1305  optstring = (relopt_string *) options[i].gen;
1306  if (options[i].isset)
1307  string_val = options[i].values.string_val;
1308  else if (!optstring->default_isnull)
1309  string_val = optstring->default_val;
1310  else
1311  string_val = NULL;
1312 
1313  if (string_val == NULL)
1314  *(int *) itempos = 0;
1315  else
1316  {
1317  strcpy((char *) rdopts + offset, string_val);
1318  *(int *) itempos = offset;
1319  offset += strlen(string_val) + 1;
1320  }
1321  break;
1322  default:
1323  elog(ERROR, "unsupported reloption type %d",
1324  options[i].gen->type);
1325  break;
1326  }
1327  found = true;
1328  break;
1329  }
1330  }
1331  if (validate && !found && options[i].gen->kinds != RELOPT_KIND_INDEX)
1332  elog(ERROR, "reloption \"%s\" not found in parse table",
1333  options[i].gen->name);
1334  }
1335  SET_VARSIZE(rdopts, offset);
1336 }
char * string_val
Definition: reloptions.h:84
bool default_isnull
Definition: reloptions.h:118
relopt_gen * gen
Definition: reloptions.h:77
#define ERROR
Definition: elog.h:43
union relopt_value::@47 values
const char * optname
Definition: reloptions.h:126
static Datum values[MAXATTR]
Definition: bootstrap.c:164
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:327
#define elog
Definition: elog.h:219
char * default_val
Definition: reloptions.h:120

◆ heap_reloptions()

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

Definition at line 1440 of file reloptions.c.

References AutoVacOpts::analyze_scale_factor, AutoVacOpts::analyze_threshold, StdRdOptions::autovacuum, default_reloptions(), StdRdOptions::fillfactor, RELOPT_KIND_HEAP, RELOPT_KIND_PARTITIONED, and RELOPT_KIND_TOAST.

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

1441 {
1442  StdRdOptions *rdopts;
1443 
1444  switch (relkind)
1445  {
1446  case RELKIND_TOASTVALUE:
1447  rdopts = (StdRdOptions *)
1448  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1449  if (rdopts != NULL)
1450  {
1451  /* adjust default-only parameters for TOAST relations */
1452  rdopts->fillfactor = 100;
1453  rdopts->autovacuum.analyze_threshold = -1;
1454  rdopts->autovacuum.analyze_scale_factor = -1;
1455  }
1456  return (bytea *) rdopts;
1457  case RELKIND_RELATION:
1458  case RELKIND_MATVIEW:
1459  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1460  case RELKIND_PARTITIONED_TABLE:
1461  return default_reloptions(reloptions, validate,
1463  default:
1464  /* other relkinds are not supported */
1465  return NULL;
1466  }
1467 }
int fillfactor
Definition: rel.h:259
char relkind
Definition: pg_class.h:51
int analyze_threshold
Definition: rel.h:242
float8 analyze_scale_factor
Definition: rel.h:253
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1343
Definition: c.h:516
AutoVacOpts autovacuum
Definition: rel.h:263

◆ index_generic_reloptions()

bytea* index_generic_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1496 of file reloptions.c.

References allocateReloptStruct(), fillRelOptions(), lengthof, offsetof, options, parseRelOptions(), pfree(), RELOPT_KIND_INDEX, and RELOPT_TYPE_BOOL.

Referenced by IsProjectionFunctionalIndex().

1497 {
1498  int numoptions;
1499  GenericIndexOpts *idxopts;
1501  static const relopt_parse_elt tab[] = {
1502  {"recheck_on_update", RELOPT_TYPE_BOOL, offsetof(GenericIndexOpts, recheck_on_update)}
1503  };
1504 
1505  options = parseRelOptions(reloptions, validate,
1507  &numoptions);
1508 
1509  /* if none set, we're done */
1510  if (numoptions == 0)
1511  return NULL;
1512 
1513  idxopts = allocateReloptStruct(sizeof(GenericIndexOpts), options, numoptions);
1514 
1515  fillRelOptions((void *)idxopts, sizeof(GenericIndexOpts), options, numoptions,
1516  validate, tab, lengthof(tab));
1517 
1518  pfree(options);
1519 
1520  return (bytea*) idxopts;
1521 }
#define lengthof(array)
Definition: c.h:629
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1242
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:1266
Definition: c.h:516
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1048
#define offsetof(type, field)
Definition: c.h:622

◆ index_reloptions()

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

Definition at line 1478 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

1479 {
1480  Assert(amoptions != NULL);
1481 
1482  /* Assume function is strict */
1483  if (!PointerIsValid(DatumGetPointer(reloptions)))
1484  return NULL;
1485 
1486  return amoptions(reloptions, validate);
1487 }
#define Assert(condition)
Definition: c.h:699
#define DatumGetPointer(X)
Definition: postgres.h:532
#define PointerIsValid(pointer)
Definition: c.h:593

◆ parseRelOptions()

relopt_value* parseRelOptions ( Datum  options,
bool  validate,
relopt_kind  kind,
int *  numrelopts 
)

Definition at line 1048 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, palloc(), parse_one_reloption(), pfree(), PointerIsValid, TextDatumGetCString, VARDATA, VARHDRSZ, and VARSIZE.

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

1050 {
1051  relopt_value *reloptions = NULL;
1052  int numoptions = 0;
1053  int i;
1054  int j;
1055 
1056  if (need_initialization)
1058 
1059  /* Build a list of expected options, based on kind */
1060 
1061  for (i = 0; relOpts[i]; i++)
1062  if (relOpts[i]->kinds & kind)
1063  numoptions++;
1064 
1065  if (numoptions > 0)
1066  {
1067  reloptions = palloc(numoptions * sizeof(relopt_value));
1068 
1069  for (i = 0, j = 0; relOpts[i]; i++)
1070  {
1071  if (relOpts[i]->kinds & kind)
1072  {
1073  reloptions[j].gen = relOpts[i];
1074  reloptions[j].isset = false;
1075  j++;
1076  }
1077  }
1078  }
1079 
1080  /* Done if no options */
1082  {
1084  Datum *optiondatums;
1085  int noptions;
1086 
1087  deconstruct_array(array, TEXTOID, -1, false, 'i',
1088  &optiondatums, NULL, &noptions);
1089 
1090  for (i = 0; i < noptions; i++)
1091  {
1092  char *text_str = VARDATA(optiondatums[i]);
1093  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1094  int j;
1095 
1096  /* Search for a match in reloptions */
1097  for (j = 0; j < numoptions; j++)
1098  {
1099  int kw_len = reloptions[j].gen->namelen;
1100 
1101  if (text_len > kw_len && text_str[kw_len] == '=' &&
1102  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1103  {
1104  parse_one_reloption(&reloptions[j], text_str, text_len,
1105  validate);
1106  break;
1107  }
1108  }
1109 
1110  if (j >= numoptions && validate)
1111  {
1112  char *s;
1113  char *p;
1114 
1115  s = TextDatumGetCString(optiondatums[i]);
1116  p = strchr(s, '=');
1117  if (p)
1118  *p = '\0';
1119  ereport(ERROR,
1120  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1121  errmsg("unrecognized parameter \"%s\"", s)));
1122  }
1123  }
1124 
1125  /* It's worth avoiding memory leaks in this function */
1126  pfree(optiondatums);
1127  if (((void *) array) != DatumGetPointer(options))
1128  pfree(array);
1129  }
1130 
1131  *numrelopts = numoptions;
1132  return reloptions;
1133 }
static void initialize_reloptions(void)
Definition: reloptions.c:473
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:522
int errcode(int sqlerrcode)
Definition: elog.c:575
relopt_gen * gen
Definition: reloptions.h:77
void pfree(void *pointer)
Definition: mcxt.c:1031
#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:1140
int namelen
Definition: reloptions.h:70
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:365
#define DatumGetPointer(X)
Definition: postgres.h:532
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3449
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static bool need_initialization
Definition: reloptions.c:460
static relopt_gen ** relOpts
Definition: reloptions.c:455
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:593
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1558 of file reloptions.c.

References allocateReloptStruct(), effective_io_concurrency, fillRelOptions(), lengthof, 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().

1559 {
1561  TableSpaceOpts *tsopts;
1562  int numoptions;
1563  static const relopt_parse_elt tab[] = {
1564  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1565  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1566  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1567  };
1568 
1569  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1570  &numoptions);
1571 
1572  /* if none set, we're done */
1573  if (numoptions == 0)
1574  return NULL;
1575 
1576  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1577 
1578  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1579  validate, tab, lengthof(tab));
1580 
1581  pfree(options);
1582 
1583  return (bytea *) tsopts;
1584 }
#define lengthof(array)
Definition: c.h:629
int effective_io_concurrency
Definition: bufmgr.c:112
double random_page_cost
Definition: costsize.c:112
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1242
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:1266
Definition: c.h:516
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1048
double seq_page_cost
Definition: costsize.c:111
#define offsetof(type, field)
Definition: c.h:622

◆ transformRelOptions()

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

Definition at line 773 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, palloc(), PointerGetDatum, PointerIsValid, SET_VARSIZE, value, VARDATA, VARHDRSZ, and VARSIZE.

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

775 {
776  Datum result;
777  ArrayBuildState *astate;
778  ListCell *cell;
779 
780  /* no change if empty list */
781  if (defList == NIL)
782  return oldOptions;
783 
784  /* We build new array using accumArrayResult */
785  astate = NULL;
786 
787  /* Copy any oldOptions that aren't to be replaced */
788  if (PointerIsValid(DatumGetPointer(oldOptions)))
789  {
790  ArrayType *array = DatumGetArrayTypeP(oldOptions);
791  Datum *oldoptions;
792  int noldoptions;
793  int i;
794 
795  deconstruct_array(array, TEXTOID, -1, false, 'i',
796  &oldoptions, NULL, &noldoptions);
797 
798  for (i = 0; i < noldoptions; i++)
799  {
800  char *text_str = VARDATA(oldoptions[i]);
801  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
802 
803  /* Search for a match in defList */
804  foreach(cell, defList)
805  {
806  DefElem *def = (DefElem *) lfirst(cell);
807  int kw_len;
808 
809  /* ignore if not in the same namespace */
810  if (namspace == NULL)
811  {
812  if (def->defnamespace != NULL)
813  continue;
814  }
815  else if (def->defnamespace == NULL)
816  continue;
817  else if (strcmp(def->defnamespace, namspace) != 0)
818  continue;
819 
820  kw_len = strlen(def->defname);
821  if (text_len > kw_len && text_str[kw_len] == '=' &&
822  strncmp(text_str, def->defname, kw_len) == 0)
823  break;
824  }
825  if (!cell)
826  {
827  /* No match, so keep old option */
828  astate = accumArrayResult(astate, oldoptions[i],
829  false, TEXTOID,
831  }
832  }
833  }
834 
835  /*
836  * If CREATE/SET, add new options to array; if RESET, just check that the
837  * user didn't say RESET (option=val). (Must do this because the grammar
838  * doesn't enforce it.)
839  */
840  foreach(cell, defList)
841  {
842  DefElem *def = (DefElem *) lfirst(cell);
843 
844  if (isReset)
845  {
846  if (def->arg != NULL)
847  ereport(ERROR,
848  (errcode(ERRCODE_SYNTAX_ERROR),
849  errmsg("RESET must not include values for parameters")));
850  }
851  else
852  {
853  text *t;
854  const char *value;
855  Size len;
856 
857  /*
858  * Error out if the namespace is not valid. A NULL namespace is
859  * always valid.
860  */
861  if (def->defnamespace != NULL)
862  {
863  bool valid = false;
864  int i;
865 
866  if (validnsps)
867  {
868  for (i = 0; validnsps[i]; i++)
869  {
870  if (strcmp(def->defnamespace, validnsps[i]) == 0)
871  {
872  valid = true;
873  break;
874  }
875  }
876  }
877 
878  if (!valid)
879  ereport(ERROR,
880  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
881  errmsg("unrecognized parameter namespace \"%s\"",
882  def->defnamespace)));
883  }
884 
885  if (ignoreOids && strcmp(def->defname, "oids") == 0)
886  continue;
887 
888  /* ignore if not in the same namespace */
889  if (namspace == NULL)
890  {
891  if (def->defnamespace != NULL)
892  continue;
893  }
894  else if (def->defnamespace == NULL)
895  continue;
896  else if (strcmp(def->defnamespace, namspace) != 0)
897  continue;
898 
899  /*
900  * Flatten the DefElem into a text string like "name=arg". If we
901  * have just "name", assume "name=true" is meant. Note: the
902  * namespace is not output.
903  */
904  if (def->arg != NULL)
905  value = defGetString(def);
906  else
907  value = "true";
908  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
909  /* +1 leaves room for sprintf's trailing null */
910  t = (text *) palloc(len + 1);
911  SET_VARSIZE(t, len);
912  sprintf(VARDATA(t), "%s=%s", def->defname, value);
913 
914  astate = accumArrayResult(astate, PointerGetDatum(t),
915  false, TEXTOID,
917  }
918  }
919 
920  if (astate)
921  result = makeArrayResult(astate, CurrentMemoryContext);
922  else
923  result = (Datum) 0;
924 
925  return result;
926 }
#define NIL
Definition: pg_list.h:69
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:539
#define VARHDRSZ
Definition: c.h:522
char * defnamespace
Definition: parsenodes.h:729
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define ereport(elevel, rest)
Definition: elog.h:122
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5106
Node * arg
Definition: parsenodes.h:731
uintptr_t Datum
Definition: postgres.h:365
static struct @131 value
#define lfirst(lc)
Definition: pg_list.h:106
size_t Size
Definition: c.h:433
#define DatumGetPointer(X)
Definition: postgres.h:532
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3449
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5042
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: c.h:516
char * defname
Definition: parsenodes.h:730
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:327
#define PointerIsValid(pointer)
Definition: c.h:593
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 934 of file reloptions.c.

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

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

935 {
936  List *result = NIL;
937  ArrayType *array;
938  Datum *optiondatums;
939  int noptions;
940  int i;
941 
942  /* Nothing to do if no options */
944  return result;
945 
946  array = DatumGetArrayTypeP(options);
947 
948  deconstruct_array(array, TEXTOID, -1, false, 'i',
949  &optiondatums, NULL, &noptions);
950 
951  for (i = 0; i < noptions; i++)
952  {
953  char *s;
954  char *p;
955  Node *val = NULL;
956 
957  s = TextDatumGetCString(optiondatums[i]);
958  p = strchr(s, '=');
959  if (p)
960  {
961  *p++ = '\0';
962  val = (Node *) makeString(pstrdup(p));
963  }
964  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
965  }
966 
967  return result;
968 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:69
char * pstrdup(const char *in)
Definition: mcxt.c:1161
Definition: nodes.h:517
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
List * lappend(List *list, void *datum)
Definition: list.c:128
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:365
#define DatumGetPointer(X)
Definition: postgres.h:532
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3449
int i
static size_t noptions
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:593
long val
Definition: informix.c:689
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1408 of file reloptions.c.

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

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

1409 {
1411  ViewOptions *vopts;
1412  int numoptions;
1413  static const relopt_parse_elt tab[] = {
1414  {"security_barrier", RELOPT_TYPE_BOOL,
1415  offsetof(ViewOptions, security_barrier)},
1416  {"check_option", RELOPT_TYPE_STRING,
1417  offsetof(ViewOptions, check_option_offset)}
1418  };
1419 
1420  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1421 
1422  /* if none set, we're done */
1423  if (numoptions == 0)
1424  return NULL;
1425 
1426  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1427 
1428  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1429  validate, tab, lengthof(tab));
1430 
1431  pfree(options);
1432 
1433  return (bytea *) vopts;
1434 }
#define lengthof(array)
Definition: c.h:629
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1242
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:1266
Definition: c.h:516
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1048
#define offsetof(type, field)
Definition: c.h:622