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

Go to the source code of this file.

Data Structures

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

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 struct relopt_enum_elt_def relopt_enum_elt_def
 
typedef struct relopt_enum relopt_enum
 
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_ENUM,
  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, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
 
void add_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
 
void add_real_reloption (bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
 
void add_enum_reloption (bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
 
void add_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
 
Datum transformRelOptions (Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
 
ListuntransformRelOptions (Datum options)
 
byteaextractRelOptions (HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
 
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

◆ GET_STRING_RELOPTION

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

Definition at line 264 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 255 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:267

Definition at line 201 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:267

Definition at line 192 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:267

Definition at line 210 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:267

Definition at line 230 of file reloptions.h.

◆ HAVE_RELOPTION

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

Definition at line 189 of file reloptions.h.

◆ HEAP_RELOPT_NAMESPACES

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

Typedef Documentation

◆ relopt_bool

typedef struct relopt_bool relopt_bool

◆ relopt_enum

typedef struct relopt_enum relopt_enum

◆ relopt_enum_elt_def

◆ relopt_gen

typedef struct relopt_gen relopt_gen

◆ relopt_int

typedef struct relopt_int relopt_int

◆ relopt_kind

typedef enum relopt_kind relopt_kind

◆ relopt_real

typedef struct relopt_real relopt_real

◆ relopt_string

typedef struct relopt_string relopt_string

◆ relopt_type

typedef enum relopt_type relopt_type

◆ relopt_value

typedef struct relopt_value relopt_value

◆ validate_string_relopt

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

Definition at line 132 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_MAX 

Definition at line 39 of file reloptions.h.

40 {
41  RELOPT_KIND_HEAP = (1 << 0),
42  RELOPT_KIND_TOAST = (1 << 1),
43  RELOPT_KIND_BTREE = (1 << 2),
44  RELOPT_KIND_HASH = (1 << 3),
45  RELOPT_KIND_GIN = (1 << 4),
46  RELOPT_KIND_GIST = (1 << 5),
47  RELOPT_KIND_ATTRIBUTE = (1 << 6),
48  RELOPT_KIND_TABLESPACE = (1 << 7),
49  RELOPT_KIND_SPGIST = (1 << 8),
50  RELOPT_KIND_VIEW = (1 << 9),
51  RELOPT_KIND_BRIN = (1 << 10),
52  RELOPT_KIND_PARTITIONED = (1 << 11),
53  /* 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:39

◆ relopt_type

Enumerator
RELOPT_TYPE_BOOL 
RELOPT_TYPE_INT 
RELOPT_TYPE_REAL 
RELOPT_TYPE_ENUM 
RELOPT_TYPE_STRING 

Definition at line 29 of file reloptions.h.

Function Documentation

◆ add_bool_reloption()

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

Definition at line 713 of file reloptions.c.

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

Referenced by create_reloptions_table().

715 {
716  relopt_bool *newoption;
717 
718  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
719  name, desc, lockmode);
720  newoption->default_val = default_val;
721 
722  add_reloption((relopt_gen *) newoption);
723 }
bool default_val
Definition: reloptions.h:93
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:660
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:626
const char * name
Definition: encode.c:521

◆ add_enum_reloption()

void add_enum_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
relopt_enum_elt_def members,
int  default_val,
const char *  detailmsg,
LOCKMODE  lockmode 
)

Definition at line 776 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_enum::default_val, relopt_enum::detailmsg, relopt_enum::members, and RELOPT_TYPE_ENUM.

Referenced by create_reloptions_table().

779 {
780  relopt_enum *newoption;
781 
782  newoption = (relopt_enum *) allocate_reloption(kinds, RELOPT_TYPE_ENUM,
783  name, desc, lockmode);
784  newoption->members = members;
785  newoption->default_val = default_val;
786  newoption->detailmsg = detailmsg;
787 
788  add_reloption((relopt_gen *) newoption);
789 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:660
const char * detailmsg
Definition: reloptions.h:127
relopt_enum_elt_def * members
Definition: reloptions.h:125
int default_val
Definition: reloptions.h:126
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:626
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,
LOCKMODE  lockmode 
)

Definition at line 730 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(), and create_reloptions_table().

732 {
733  relopt_int *newoption;
734 
735  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
736  name, desc, lockmode);
737  newoption->default_val = default_val;
738  newoption->min = min_val;
739  newoption->max = max_val;
740 
741  add_reloption((relopt_gen *) newoption);
742 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:660
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:626
const char * name
Definition: encode.c:521
int default_val
Definition: reloptions.h:99

◆ add_real_reloption()

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

Definition at line 749 of file reloptions.c.

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

Referenced by create_reloptions_table().

751 {
752  relopt_real *newoption;
753 
754  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
755  name, desc, lockmode);
756  newoption->default_val = default_val;
757  newoption->min = min_val;
758  newoption->max = max_val;
759 
760  add_reloption((relopt_gen *) newoption);
761 }
double default_val
Definition: reloptions.h:107
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:660
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:626
const char * name
Definition: encode.c:521
double max
Definition: reloptions.h:109
double min
Definition: reloptions.h:108

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 609 of file reloptions.c.

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

Referenced by _PG_init(), and create_reloptions_table().

610 {
611  /* don't hand out the last bit so that the enum's behavior is portable */
613  ereport(ERROR,
614  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
615  errmsg("user-defined relation parameter types limit exceeded")));
616  last_assigned_kind <<= 1;
618 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
relopt_kind
Definition: reloptions.h:39
static bits32 last_assigned_kind
Definition: reloptions.c:489

◆ add_string_reloption()

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

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

Referenced by create_reloptions_table().

803 {
804  relopt_string *newoption;
805 
806  /* make sure the validator/default combination is sane */
807  if (validator)
808  (validator) (default_val);
809 
810  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
811  name, desc, lockmode);
812  newoption->validate_cb = validator;
813  if (default_val)
814  {
816  default_val);
817  newoption->default_len = strlen(default_val);
818  newoption->default_isnull = false;
819  }
820  else
821  {
822  newoption->default_val = "";
823  newoption->default_len = 0;
824  newoption->default_isnull = true;
825  }
826 
827  add_reloption((relopt_gen *) newoption);
828 }
bool default_isnull
Definition: reloptions.h:138
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:660
validate_string_relopt validate_cb
Definition: reloptions.h:139
MemoryContext TopMemoryContext
Definition: mcxt.c:44
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:626
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1173
char * default_val
Definition: reloptions.h:140

◆ allocateReloptStruct()

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

Definition at line 1369 of file reloptions.c.

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

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

1370 {
1371  Size size = base;
1372  int i;
1373 
1374  for (i = 0; i < numoptions; i++)
1375  if (options[i].gen->type == RELOPT_TYPE_STRING)
1376  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1377 
1378  return palloc0(size);
1379 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:255
void * palloc0(Size size)
Definition: mcxt.c:980
size_t Size
Definition: c.h:466
int i

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

1696 {
1697  LOCKMODE lockmode = NoLock;
1698  ListCell *cell;
1699 
1700  if (defList == NIL)
1701  return AccessExclusiveLock;
1702 
1703  if (need_initialization)
1705 
1706  foreach(cell, defList)
1707  {
1708  DefElem *def = (DefElem *) lfirst(cell);
1709  int i;
1710 
1711  for (i = 0; relOpts[i]; i++)
1712  {
1713  if (strncmp(relOpts[i]->name,
1714  def->defname,
1715  relOpts[i]->namelen + 1) == 0)
1716  {
1717  if (lockmode < relOpts[i]->lockmode)
1718  lockmode = relOpts[i]->lockmode;
1719  }
1720  }
1721  }
1722 
1723  return lockmode;
1724 }
#define NIL
Definition: pg_list.h:65
static void initialize_reloptions(void)
Definition: reloptions.c:506
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:190
const char * name
Definition: encode.c:521
#define AccessExclusiveLock
Definition: lockdefs.h:45
int i
static bool need_initialization
Definition: reloptions.c:493
char * defname
Definition: parsenodes.h:730
static relopt_gen ** relOpts
Definition: reloptions.c:488

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

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

1630 {
1632  AttributeOpts *aopts;
1633  int numoptions;
1634  static const relopt_parse_elt tab[] = {
1635  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1636  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1637  };
1638 
1639  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1640  &numoptions);
1641 
1642  /* if none set, we're done */
1643  if (numoptions == 0)
1644  return NULL;
1645 
1646  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1647 
1648  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1649  validate, tab, lengthof(tab));
1650 
1651  pfree(options);
1652 
1653  return (bytea *) aopts;
1654 }
#define lengthof(array)
Definition: c.h:662
void pfree(void *pointer)
Definition: mcxt.c:1056
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1369
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:1393
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1144
#define offsetof(type, field)
Definition: c.h:655

◆ default_reloptions()

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

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

1476 {
1478  StdRdOptions *rdopts;
1479  int numoptions;
1480  static const relopt_parse_elt tab[] = {
1481  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1482  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1483  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1484  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1485  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1486  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1487  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1488  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1489  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1490  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1491  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1492  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1493  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1494  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1495  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1496  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1497  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1498  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1499  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1500  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1501  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1502  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1503  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1504  {"toast_tuple_target", RELOPT_TYPE_INT,
1505  offsetof(StdRdOptions, toast_tuple_target)},
1506  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1507  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1508  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1509  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1510  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1511  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1512  {"user_catalog_table", RELOPT_TYPE_BOOL,
1513  offsetof(StdRdOptions, user_catalog_table)},
1514  {"parallel_workers", RELOPT_TYPE_INT,
1515  offsetof(StdRdOptions, parallel_workers)},
1516  {"vacuum_cleanup_index_scale_factor", RELOPT_TYPE_REAL,
1518  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1519  offsetof(StdRdOptions, vacuum_index_cleanup)},
1520  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1521  offsetof(StdRdOptions, vacuum_truncate)}
1522  };
1523 
1524  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1525 
1526  /* if none set, we're done */
1527  if (numoptions == 0)
1528  return NULL;
1529 
1530  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1531 
1532  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1533  validate, tab, lengthof(tab));
1534 
1535  pfree(options);
1536 
1537  return (bytea *) rdopts;
1538 }
double vacuum_cleanup_index_scale_factor
Definition: globals.c:150
#define lengthof(array)
Definition: c.h:662
void pfree(void *pointer)
Definition: mcxt.c:1056
int fillfactor
Definition: pgbench.c:157
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1369
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:1393
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1144
#define offsetof(type, field)
Definition: c.h:655

◆ extractRelOptions()

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

Definition at line 1079 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

1081 {
1082  bytea *options;
1083  bool isnull;
1084  Datum datum;
1085  Form_pg_class classForm;
1086 
1087  datum = fastgetattr(tuple,
1088  Anum_pg_class_reloptions,
1089  tupdesc,
1090  &isnull);
1091  if (isnull)
1092  return NULL;
1093 
1094  classForm = (Form_pg_class) GETSTRUCT(tuple);
1095 
1096  /* Parse into appropriate format; don't error out here */
1097  switch (classForm->relkind)
1098  {
1099  case RELKIND_RELATION:
1100  case RELKIND_TOASTVALUE:
1101  case RELKIND_MATVIEW:
1102  case RELKIND_PARTITIONED_TABLE:
1103  options = heap_reloptions(classForm->relkind, datum, false);
1104  break;
1105  case RELKIND_VIEW:
1106  options = view_reloptions(datum, false);
1107  break;
1108  case RELKIND_INDEX:
1109  case RELKIND_PARTITIONED_INDEX:
1110  options = index_reloptions(amoptions, datum, false);
1111  break;
1112  case RELKIND_FOREIGN_TABLE:
1113  options = NULL;
1114  break;
1115  default:
1116  Assert(false); /* can't get here */
1117  options = NULL; /* keep compiler quiet */
1118  break;
1119  }
1120 
1121  return options;
1122 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1576
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:712
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1544
static char ** options
uintptr_t Datum
Definition: postgres.h:367
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1614
#define Assert(condition)
Definition: c.h:732
FormData_pg_class * Form_pg_class
Definition: pg_class.h:150
Definition: c.h:549

◆ fillRelOptions()

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

Definition at line 1393 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_TYPE_BOOL, RELOPT_TYPE_ENUM, 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(), dioptions(), ginoptions(), gistoptions(), tablespace_reloptions(), and view_reloptions().

1397 {
1398  int i;
1399  int offset = basesize;
1400 
1401  for (i = 0; i < numoptions; i++)
1402  {
1403  int j;
1404  bool found = false;
1405 
1406  for (j = 0; j < numelems; j++)
1407  {
1408  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1409  {
1410  relopt_string *optstring;
1411  char *itempos = ((char *) rdopts) + elems[j].offset;
1412  char *string_val;
1413 
1414  switch (options[i].gen->type)
1415  {
1416  case RELOPT_TYPE_BOOL:
1417  *(bool *) itempos = options[i].isset ?
1418  options[i].values.bool_val :
1419  ((relopt_bool *) options[i].gen)->default_val;
1420  break;
1421  case RELOPT_TYPE_INT:
1422  *(int *) itempos = options[i].isset ?
1423  options[i].values.int_val :
1424  ((relopt_int *) options[i].gen)->default_val;
1425  break;
1426  case RELOPT_TYPE_REAL:
1427  *(double *) itempos = options[i].isset ?
1428  options[i].values.real_val :
1429  ((relopt_real *) options[i].gen)->default_val;
1430  break;
1431  case RELOPT_TYPE_ENUM:
1432  *(int *) itempos = options[i].isset ?
1433  options[i].values.enum_val :
1434  ((relopt_enum *) options[i].gen)->default_val;
1435  break;
1436  case RELOPT_TYPE_STRING:
1437  optstring = (relopt_string *) options[i].gen;
1438  if (options[i].isset)
1439  string_val = options[i].values.string_val;
1440  else if (!optstring->default_isnull)
1441  string_val = optstring->default_val;
1442  else
1443  string_val = NULL;
1444 
1445  if (string_val == NULL)
1446  *(int *) itempos = 0;
1447  else
1448  {
1449  strcpy((char *) rdopts + offset, string_val);
1450  *(int *) itempos = offset;
1451  offset += strlen(string_val) + 1;
1452  }
1453  break;
1454  default:
1455  elog(ERROR, "unsupported reloption type %d",
1456  options[i].gen->type);
1457  break;
1458  }
1459  found = true;
1460  break;
1461  }
1462  }
1463  if (validate && !found)
1464  elog(ERROR, "reloption \"%s\" not found in parse table",
1465  options[i].gen->name);
1466  }
1467  SET_VARSIZE(rdopts, offset);
1468 }
char * string_val
Definition: reloptions.h:85
bool default_isnull
Definition: reloptions.h:138
relopt_gen * gen
Definition: reloptions.h:77
#define ERROR
Definition: elog.h:43
union relopt_value::@47 values
const char * optname
Definition: reloptions.h:146
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:226
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * default_val
Definition: reloptions.h:140

◆ heap_reloptions()

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

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

1577 {
1578  StdRdOptions *rdopts;
1579 
1580  switch (relkind)
1581  {
1582  case RELKIND_TOASTVALUE:
1583  rdopts = (StdRdOptions *)
1584  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1585  if (rdopts != NULL)
1586  {
1587  /* adjust default-only parameters for TOAST relations */
1588  rdopts->fillfactor = 100;
1589  rdopts->autovacuum.analyze_threshold = -1;
1590  rdopts->autovacuum.analyze_scale_factor = -1;
1591  }
1592  return (bytea *) rdopts;
1593  case RELKIND_RELATION:
1594  case RELKIND_MATVIEW:
1595  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1596  case RELKIND_PARTITIONED_TABLE:
1597  return default_reloptions(reloptions, validate,
1599  default:
1600  /* other relkinds are not supported */
1601  return NULL;
1602  }
1603 }
int fillfactor
Definition: rel.h:266
char relkind
Definition: pg_class.h:81
int analyze_threshold
Definition: rel.h:249
float8 analyze_scale_factor
Definition: rel.h:260
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1475
Definition: c.h:549
AutoVacOpts autovacuum
Definition: rel.h:270

◆ index_reloptions()

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

Definition at line 1614 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

1615 {
1616  Assert(amoptions != NULL);
1617 
1618  /* Assume function is strict */
1619  if (!PointerIsValid(DatumGetPointer(reloptions)))
1620  return NULL;
1621 
1622  return amoptions(reloptions, validate);
1623 }
#define Assert(condition)
Definition: c.h:732
#define DatumGetPointer(X)
Definition: postgres.h:549
#define PointerIsValid(pointer)
Definition: c.h:626

◆ parseRelOptions()

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

Definition at line 1144 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(), dioptions(), ginoptions(), gistoptions(), tablespace_reloptions(), and view_reloptions().

1146 {
1147  relopt_value *reloptions = NULL;
1148  int numoptions = 0;
1149  int i;
1150  int j;
1151 
1152  if (need_initialization)
1154 
1155  /* Build a list of expected options, based on kind */
1156 
1157  for (i = 0; relOpts[i]; i++)
1158  if (relOpts[i]->kinds & kind)
1159  numoptions++;
1160 
1161  if (numoptions > 0)
1162  {
1163  reloptions = palloc(numoptions * sizeof(relopt_value));
1164 
1165  for (i = 0, j = 0; relOpts[i]; i++)
1166  {
1167  if (relOpts[i]->kinds & kind)
1168  {
1169  reloptions[j].gen = relOpts[i];
1170  reloptions[j].isset = false;
1171  j++;
1172  }
1173  }
1174  }
1175 
1176  /* Done if no options */
1178  {
1180  Datum *optiondatums;
1181  int noptions;
1182 
1183  deconstruct_array(array, TEXTOID, -1, false, 'i',
1184  &optiondatums, NULL, &noptions);
1185 
1186  for (i = 0; i < noptions; i++)
1187  {
1188  char *text_str = VARDATA(optiondatums[i]);
1189  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1190  int j;
1191 
1192  /* Search for a match in reloptions */
1193  for (j = 0; j < numoptions; j++)
1194  {
1195  int kw_len = reloptions[j].gen->namelen;
1196 
1197  if (text_len > kw_len && text_str[kw_len] == '=' &&
1198  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1199  {
1200  parse_one_reloption(&reloptions[j], text_str, text_len,
1201  validate);
1202  break;
1203  }
1204  }
1205 
1206  if (j >= numoptions && validate)
1207  {
1208  char *s;
1209  char *p;
1210 
1211  s = TextDatumGetCString(optiondatums[i]);
1212  p = strchr(s, '=');
1213  if (p)
1214  *p = '\0';
1215  ereport(ERROR,
1216  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1217  errmsg("unrecognized parameter \"%s\"", s)));
1218  }
1219  }
1220 
1221  /* It's worth avoiding memory leaks in this function */
1222  pfree(optiondatums);
1223  if (((void *) array) != DatumGetPointer(options))
1224  pfree(array);
1225  }
1226 
1227  *numrelopts = numoptions;
1228  return reloptions;
1229 }
static void initialize_reloptions(void)
Definition: reloptions.c:506
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:555
int errcode(int sqlerrcode)
Definition: elog.c:570
relopt_gen * gen
Definition: reloptions.h:77
void pfree(void *pointer)
Definition: mcxt.c:1056
#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:1236
int namelen
Definition: reloptions.h:70
#define ereport(elevel, rest)
Definition: elog.h:141
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
static bool need_initialization
Definition: reloptions.c:493
static relopt_gen ** relOpts
Definition: reloptions.c:488
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:626
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

1661 {
1663  TableSpaceOpts *tsopts;
1664  int numoptions;
1665  static const relopt_parse_elt tab[] = {
1666  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1667  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1668  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1669  };
1670 
1671  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1672  &numoptions);
1673 
1674  /* if none set, we're done */
1675  if (numoptions == 0)
1676  return NULL;
1677 
1678  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1679 
1680  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1681  validate, tab, lengthof(tab));
1682 
1683  pfree(options);
1684 
1685  return (bytea *) tsopts;
1686 }
#define lengthof(array)
Definition: c.h:662
int effective_io_concurrency
Definition: bufmgr.c:113
double random_page_cost
Definition: costsize.c:111
void pfree(void *pointer)
Definition: mcxt.c:1056
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1369
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:1393
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1144
double seq_page_cost
Definition: costsize.c:110
#define offsetof(type, field)
Definition: c.h:655

◆ transformRelOptions()

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

Definition at line 854 of file reloptions.c.

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

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

856 {
857  Datum result;
858  ArrayBuildState *astate;
859  ListCell *cell;
860 
861  /* no change if empty list */
862  if (defList == NIL)
863  return oldOptions;
864 
865  /* We build new array using accumArrayResult */
866  astate = NULL;
867 
868  /* Copy any oldOptions that aren't to be replaced */
869  if (PointerIsValid(DatumGetPointer(oldOptions)))
870  {
871  ArrayType *array = DatumGetArrayTypeP(oldOptions);
872  Datum *oldoptions;
873  int noldoptions;
874  int i;
875 
876  deconstruct_array(array, TEXTOID, -1, false, 'i',
877  &oldoptions, NULL, &noldoptions);
878 
879  for (i = 0; i < noldoptions; i++)
880  {
881  char *text_str = VARDATA(oldoptions[i]);
882  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
883 
884  /* Search for a match in defList */
885  foreach(cell, defList)
886  {
887  DefElem *def = (DefElem *) lfirst(cell);
888  int kw_len;
889 
890  /* ignore if not in the same namespace */
891  if (namspace == NULL)
892  {
893  if (def->defnamespace != NULL)
894  continue;
895  }
896  else if (def->defnamespace == NULL)
897  continue;
898  else if (strcmp(def->defnamespace, namspace) != 0)
899  continue;
900 
901  kw_len = strlen(def->defname);
902  if (text_len > kw_len && text_str[kw_len] == '=' &&
903  strncmp(text_str, def->defname, kw_len) == 0)
904  break;
905  }
906  if (!cell)
907  {
908  /* No match, so keep old option */
909  astate = accumArrayResult(astate, oldoptions[i],
910  false, TEXTOID,
912  }
913  }
914  }
915 
916  /*
917  * If CREATE/SET, add new options to array; if RESET, just check that the
918  * user didn't say RESET (option=val). (Must do this because the grammar
919  * doesn't enforce it.)
920  */
921  foreach(cell, defList)
922  {
923  DefElem *def = (DefElem *) lfirst(cell);
924 
925  if (isReset)
926  {
927  if (def->arg != NULL)
928  ereport(ERROR,
929  (errcode(ERRCODE_SYNTAX_ERROR),
930  errmsg("RESET must not include values for parameters")));
931  }
932  else
933  {
934  text *t;
935  const char *value;
936  Size len;
937 
938  /*
939  * Error out if the namespace is not valid. A NULL namespace is
940  * always valid.
941  */
942  if (def->defnamespace != NULL)
943  {
944  bool valid = false;
945  int i;
946 
947  if (validnsps)
948  {
949  for (i = 0; validnsps[i]; i++)
950  {
951  if (strcmp(def->defnamespace, validnsps[i]) == 0)
952  {
953  valid = true;
954  break;
955  }
956  }
957  }
958 
959  if (!valid)
960  ereport(ERROR,
961  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
962  errmsg("unrecognized parameter namespace \"%s\"",
963  def->defnamespace)));
964  }
965 
966  /* ignore if not in the same namespace */
967  if (namspace == NULL)
968  {
969  if (def->defnamespace != NULL)
970  continue;
971  }
972  else if (def->defnamespace == NULL)
973  continue;
974  else if (strcmp(def->defnamespace, namspace) != 0)
975  continue;
976 
977  /*
978  * Flatten the DefElem into a text string like "name=arg". If we
979  * have just "name", assume "name=true" is meant. Note: the
980  * namespace is not output.
981  */
982  if (def->arg != NULL)
983  value = defGetString(def);
984  else
985  value = "true";
986 
987  /*
988  * This is not a great place for this test, but there's no other
989  * convenient place to filter the option out. As WITH (oids =
990  * false) will be removed someday, this seems like an acceptable
991  * amount of ugly.
992  */
993  if (acceptOidsOff && def->defnamespace == NULL &&
994  strcmp(def->defname, "oids") == 0)
995  {
996  if (defGetBoolean(def))
997  ereport(ERROR,
998  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
999  errmsg("tables declared WITH OIDS are not supported")));
1000  /* skip over option, reloptions machinery doesn't know it */
1001  continue;
1002  }
1003 
1004  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
1005  /* +1 leaves room for sprintf's trailing null */
1006  t = (text *) palloc(len + 1);
1007  SET_VARSIZE(t, len);
1008  sprintf(VARDATA(t), "%s=%s", def->defname, value);
1009 
1010  astate = accumArrayResult(astate, PointerGetDatum(t),
1011  false, TEXTOID,
1013  }
1014  }
1015 
1016  if (astate)
1017  result = makeArrayResult(astate, CurrentMemoryContext);
1018  else
1019  result = (Datum) 0;
1020 
1021  return result;
1022 }
#define NIL
Definition: pg_list.h:65
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
#define VARHDRSZ
Definition: c.h:555
char * defnamespace
Definition: parsenodes.h:729
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:570
#define sprintf
Definition: port.h:194
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define ereport(elevel, rest)
Definition: elog.h:141
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5117
Node * arg
Definition: parsenodes.h:731
uintptr_t Datum
Definition: postgres.h:367
#define lfirst(lc)
Definition: pg_list.h:190
size_t Size
Definition: c.h:466
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5053
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
Definition: c.h:549
char * defname
Definition: parsenodes.h:730
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define PointerIsValid(pointer)
Definition: c.h:626
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 1030 of file reloptions.c.

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

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

1031 {
1032  List *result = NIL;
1033  ArrayType *array;
1034  Datum *optiondatums;
1035  int noptions;
1036  int i;
1037 
1038  /* Nothing to do if no options */
1040  return result;
1041 
1042  array = DatumGetArrayTypeP(options);
1043 
1044  deconstruct_array(array, TEXTOID, -1, false, 'i',
1045  &optiondatums, NULL, &noptions);
1046 
1047  for (i = 0; i < noptions; i++)
1048  {
1049  char *s;
1050  char *p;
1051  Node *val = NULL;
1052 
1053  s = TextDatumGetCString(optiondatums[i]);
1054  p = strchr(s, '=');
1055  if (p)
1056  {
1057  *p++ = '\0';
1058  val = (Node *) makeString(pstrdup(p));
1059  }
1060  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1061  }
1062 
1063  return result;
1064 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1186
Definition: nodes.h:525
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:544
List * lappend(List *list, void *datum)
Definition: list.c:322
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
int i
static size_t noptions
Definition: pg_list.h:50
#define PointerIsValid(pointer)
Definition: c.h:626
long val
Definition: informix.c:684
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1544 of file reloptions.c.

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

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

1545 {
1547  ViewOptions *vopts;
1548  int numoptions;
1549  static const relopt_parse_elt tab[] = {
1550  {"security_barrier", RELOPT_TYPE_BOOL,
1551  offsetof(ViewOptions, security_barrier)},
1552  {"check_option", RELOPT_TYPE_ENUM,
1553  offsetof(ViewOptions, check_option)}
1554  };
1555 
1556  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1557 
1558  /* if none set, we're done */
1559  if (numoptions == 0)
1560  return NULL;
1561 
1562  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1563 
1564  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1565  validate, tab, lengthof(tab));
1566 
1567  pfree(options);
1568 
1569  return (bytea *) vopts;
1570 }
#define lengthof(array)
Definition: c.h:662
void pfree(void *pointer)
Definition: mcxt.c:1056
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1369
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:1393
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1144
#define offsetof(type, field)
Definition: c.h:655