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 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)
 
void * build_reloptions (Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
 
byteadefault_reloptions (Datum reloptions, bool validate, relopt_kind kind)
 
byteaheap_reloptions (char relkind, Datum reloptions, bool validate)
 
byteaview_reloptions (Datum reloptions, bool validate)
 
byteapartitioned_table_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 157 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 732 of file reloptions.c.

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

Referenced by create_reloptions_table().

734 {
735  relopt_bool *newoption;
736 
737  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
738  name, desc, lockmode);
739  newoption->default_val = default_val;
740 
741  add_reloption((relopt_gen *) newoption);
742 }
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:679
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:645
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 795 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().

798 {
799  relopt_enum *newoption;
800 
801  newoption = (relopt_enum *) allocate_reloption(kinds, RELOPT_TYPE_ENUM,
802  name, desc, lockmode);
803  newoption->members = members;
804  newoption->default_val = default_val;
805  newoption->detailmsg = detailmsg;
806 
807  add_reloption((relopt_gen *) newoption);
808 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:679
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:645
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 749 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().

751 {
752  relopt_int *newoption;
753 
754  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
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 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:679
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:645
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 768 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().

770 {
771  relopt_real *newoption;
772 
773  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
774  name, desc, lockmode);
775  newoption->default_val = default_val;
776  newoption->min = min_val;
777  newoption->max = max_val;
778 
779  add_reloption((relopt_gen *) newoption);
780 }
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:679
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:645
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 628 of file reloptions.c.

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

Referenced by _PG_init(), and create_reloptions_table().

629 {
630  /* don't hand out the last bit so that the enum's behavior is portable */
632  ereport(ERROR,
633  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
634  errmsg("user-defined relation parameter types limit exceeded")));
635  last_assigned_kind <<= 1;
637 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
relopt_kind
Definition: reloptions.h:39
static bits32 last_assigned_kind
Definition: reloptions.c:499

◆ 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 820 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().

822 {
823  relopt_string *newoption;
824 
825  /* make sure the validator/default combination is sane */
826  if (validator)
827  (validator) (default_val);
828 
829  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
830  name, desc, lockmode);
831  newoption->validate_cb = validator;
832  if (default_val)
833  {
835  default_val);
836  newoption->default_len = strlen(default_val);
837  newoption->default_isnull = false;
838  }
839  else
840  {
841  newoption->default_val = "";
842  newoption->default_len = 0;
843  newoption->default_isnull = true;
844  }
845 
846  add_reloption((relopt_gen *) newoption);
847 }
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:679
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:645
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

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

1720 {
1721  LOCKMODE lockmode = NoLock;
1722  ListCell *cell;
1723 
1724  if (defList == NIL)
1725  return AccessExclusiveLock;
1726 
1727  if (need_initialization)
1729 
1730  foreach(cell, defList)
1731  {
1732  DefElem *def = (DefElem *) lfirst(cell);
1733  int i;
1734 
1735  for (i = 0; relOpts[i]; i++)
1736  {
1737  if (strncmp(relOpts[i]->name,
1738  def->defname,
1739  relOpts[i]->namelen + 1) == 0)
1740  {
1741  if (lockmode < relOpts[i]->lockmode)
1742  lockmode = relOpts[i]->lockmode;
1743  }
1744  }
1745  }
1746 
1747  return lockmode;
1748 }
#define NIL
Definition: pg_list.h:65
static void initialize_reloptions(void)
Definition: reloptions.c:525
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:503
char * defname
Definition: parsenodes.h:730
static relopt_gen ** relOpts
Definition: reloptions.c:498

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1681 of file reloptions.c.

References build_reloptions(), lengthof, offsetof, RELOPT_KIND_ATTRIBUTE, and RELOPT_TYPE_REAL.

Referenced by ATExecSetOptions(), and get_attribute_options().

1682 {
1683  static const relopt_parse_elt tab[] = {
1684  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1685  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1686  };
1687 
1688  return (bytea *) build_reloptions(reloptions, validate,
1690  sizeof(AttributeOpts),
1691  tab, lengthof(tab));
1692 }
#define lengthof(array)
Definition: c.h:668
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1562
Definition: c.h:555
#define offsetof(type, field)
Definition: c.h:661

◆ build_reloptions()

void* build_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind,
Size  relopt_struct_size,
const relopt_parse_elt relopt_elems,
int  num_relopt_elems 
)

Definition at line 1562 of file reloptions.c.

References allocateReloptStruct(), Assert, fillRelOptions(), options, parseRelOptions(), and pfree().

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

1567 {
1568  int numoptions;
1570  void *rdopts;
1571 
1572  /* parse options specific to given relation option kind */
1573  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1574  Assert(numoptions <= num_relopt_elems);
1575 
1576  /* if none set, we're done */
1577  if (numoptions == 0)
1578  {
1579  Assert(options == NULL);
1580  return NULL;
1581  }
1582 
1583  /* allocate and fill the structure */
1584  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1585  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1586  validate, relopt_elems, num_relopt_elems);
1587 
1588  pfree(options);
1589 
1590  return rdopts;
1591 }
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1390
void pfree(void *pointer)
Definition: mcxt.c:1056
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1414
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1165
static char ** options
#define Assert(condition)
Definition: c.h:738

◆ default_reloptions()

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

Definition at line 1496 of file reloptions.c.

References build_reloptions(), fillfactor, lengthof, offsetof, RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, and RELOPT_TYPE_REAL.

Referenced by heap_reloptions().

1497 {
1498  static const relopt_parse_elt tab[] = {
1499  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1500  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1501  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1502  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1503  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1504  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1505  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1506  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1507  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1508  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1509  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1510  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1511  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1512  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1513  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1514  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1515  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1516  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1517  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1518  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1519  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1520  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1521  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1522  {"toast_tuple_target", RELOPT_TYPE_INT,
1523  offsetof(StdRdOptions, toast_tuple_target)},
1524  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1525  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1526  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1527  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1528  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1529  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1530  {"user_catalog_table", RELOPT_TYPE_BOOL,
1531  offsetof(StdRdOptions, user_catalog_table)},
1532  {"parallel_workers", RELOPT_TYPE_INT,
1533  offsetof(StdRdOptions, parallel_workers)},
1534  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1535  offsetof(StdRdOptions, vacuum_index_cleanup)},
1536  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1537  offsetof(StdRdOptions, vacuum_truncate)}
1538  };
1539 
1540  return (bytea *) build_reloptions(reloptions, validate, kind,
1541  sizeof(StdRdOptions),
1542  tab, lengthof(tab));
1543 }
#define lengthof(array)
Definition: c.h:668
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1562
int fillfactor
Definition: pgbench.c:159
Definition: c.h:555
#define offsetof(type, field)
Definition: c.h:661

◆ extractRelOptions()

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

Definition at line 1098 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

1100 {
1101  bytea *options;
1102  bool isnull;
1103  Datum datum;
1104  Form_pg_class classForm;
1105 
1106  datum = fastgetattr(tuple,
1107  Anum_pg_class_reloptions,
1108  tupdesc,
1109  &isnull);
1110  if (isnull)
1111  return NULL;
1112 
1113  classForm = (Form_pg_class) GETSTRUCT(tuple);
1114 
1115  /* Parse into appropriate format; don't error out here */
1116  switch (classForm->relkind)
1117  {
1118  case RELKIND_RELATION:
1119  case RELKIND_TOASTVALUE:
1120  case RELKIND_MATVIEW:
1121  options = heap_reloptions(classForm->relkind, datum, false);
1122  break;
1123  case RELKIND_PARTITIONED_TABLE:
1124  options = partitioned_table_reloptions(datum, false);
1125  break;
1126  case RELKIND_VIEW:
1127  options = view_reloptions(datum, false);
1128  break;
1129  case RELKIND_INDEX:
1130  case RELKIND_PARTITIONED_INDEX:
1131  options = index_reloptions(amoptions, datum, false);
1132  break;
1133  case RELKIND_FOREIGN_TABLE:
1134  options = NULL;
1135  break;
1136  default:
1137  Assert(false); /* can't get here */
1138  options = NULL; /* keep compiler quiet */
1139  break;
1140  }
1141 
1142  return options;
1143 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1631
#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:1612
static char ** options
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1597
uintptr_t Datum
Definition: postgres.h:367
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1666
#define Assert(condition)
Definition: c.h:738
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
Definition: c.h:555

◆ heap_reloptions()

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

Definition at line 1631 of file reloptions.c.

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

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

1632 {
1633  StdRdOptions *rdopts;
1634 
1635  switch (relkind)
1636  {
1637  case RELKIND_TOASTVALUE:
1638  rdopts = (StdRdOptions *)
1639  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1640  if (rdopts != NULL)
1641  {
1642  /* adjust default-only parameters for TOAST relations */
1643  rdopts->fillfactor = 100;
1644  rdopts->autovacuum.analyze_threshold = -1;
1645  rdopts->autovacuum.analyze_scale_factor = -1;
1646  }
1647  return (bytea *) rdopts;
1648  case RELKIND_RELATION:
1649  case RELKIND_MATVIEW:
1650  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1651  default:
1652  /* other relkinds are not supported */
1653  return NULL;
1654  }
1655 }
int fillfactor
Definition: rel.h:272
int analyze_threshold
Definition: rel.h:255
float8 analyze_scale_factor
Definition: rel.h:266
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1496
Definition: c.h:555
AutoVacOpts autovacuum
Definition: rel.h:275

◆ index_reloptions()

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

Definition at line 1666 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

1667 {
1668  Assert(amoptions != NULL);
1669 
1670  /* Assume function is strict */
1671  if (!PointerIsValid(DatumGetPointer(reloptions)))
1672  return NULL;
1673 
1674  return amoptions(reloptions, validate);
1675 }
#define Assert(condition)
Definition: c.h:738
#define DatumGetPointer(X)
Definition: postgres.h:549
#define PointerIsValid(pointer)
Definition: c.h:632

◆ partitioned_table_reloptions()

bytea* partitioned_table_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1597 of file reloptions.c.

References build_reloptions(), and RELOPT_KIND_PARTITIONED.

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

1598 {
1599  /*
1600  * There are no options for partitioned tables yet, but this is able to do
1601  * some validation.
1602  */
1603  return (bytea *) build_reloptions(reloptions, validate,
1605  0, NULL, 0);
1606 }
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1562
Definition: c.h:555

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1698 of file reloptions.c.

References build_reloptions(), effective_io_concurrency, lengthof, offsetof, random_page_cost, RELOPT_KIND_TABLESPACE, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, and seq_page_cost.

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

1699 {
1700  static const relopt_parse_elt tab[] = {
1701  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1702  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1703  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1704  };
1705 
1706  return (bytea *) build_reloptions(reloptions, validate,
1708  sizeof(TableSpaceOpts),
1709  tab, lengthof(tab));
1710 }
#define lengthof(array)
Definition: c.h:668
int effective_io_concurrency
Definition: bufmgr.c:113
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1562
double random_page_cost
Definition: costsize.c:111
Definition: c.h:555
double seq_page_cost
Definition: costsize.c:110
#define offsetof(type, field)
Definition: c.h:661

◆ transformRelOptions()

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

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

875 {
876  Datum result;
877  ArrayBuildState *astate;
878  ListCell *cell;
879 
880  /* no change if empty list */
881  if (defList == NIL)
882  return oldOptions;
883 
884  /* We build new array using accumArrayResult */
885  astate = NULL;
886 
887  /* Copy any oldOptions that aren't to be replaced */
888  if (PointerIsValid(DatumGetPointer(oldOptions)))
889  {
890  ArrayType *array = DatumGetArrayTypeP(oldOptions);
891  Datum *oldoptions;
892  int noldoptions;
893  int i;
894 
895  deconstruct_array(array, TEXTOID, -1, false, 'i',
896  &oldoptions, NULL, &noldoptions);
897 
898  for (i = 0; i < noldoptions; i++)
899  {
900  char *text_str = VARDATA(oldoptions[i]);
901  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
902 
903  /* Search for a match in defList */
904  foreach(cell, defList)
905  {
906  DefElem *def = (DefElem *) lfirst(cell);
907  int kw_len;
908 
909  /* ignore if not in the same namespace */
910  if (namspace == NULL)
911  {
912  if (def->defnamespace != NULL)
913  continue;
914  }
915  else if (def->defnamespace == NULL)
916  continue;
917  else if (strcmp(def->defnamespace, namspace) != 0)
918  continue;
919 
920  kw_len = strlen(def->defname);
921  if (text_len > kw_len && text_str[kw_len] == '=' &&
922  strncmp(text_str, def->defname, kw_len) == 0)
923  break;
924  }
925  if (!cell)
926  {
927  /* No match, so keep old option */
928  astate = accumArrayResult(astate, oldoptions[i],
929  false, TEXTOID,
931  }
932  }
933  }
934 
935  /*
936  * If CREATE/SET, add new options to array; if RESET, just check that the
937  * user didn't say RESET (option=val). (Must do this because the grammar
938  * doesn't enforce it.)
939  */
940  foreach(cell, defList)
941  {
942  DefElem *def = (DefElem *) lfirst(cell);
943 
944  if (isReset)
945  {
946  if (def->arg != NULL)
947  ereport(ERROR,
948  (errcode(ERRCODE_SYNTAX_ERROR),
949  errmsg("RESET must not include values for parameters")));
950  }
951  else
952  {
953  text *t;
954  const char *value;
955  Size len;
956 
957  /*
958  * Error out if the namespace is not valid. A NULL namespace is
959  * always valid.
960  */
961  if (def->defnamespace != NULL)
962  {
963  bool valid = false;
964  int i;
965 
966  if (validnsps)
967  {
968  for (i = 0; validnsps[i]; i++)
969  {
970  if (strcmp(def->defnamespace, validnsps[i]) == 0)
971  {
972  valid = true;
973  break;
974  }
975  }
976  }
977 
978  if (!valid)
979  ereport(ERROR,
980  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
981  errmsg("unrecognized parameter namespace \"%s\"",
982  def->defnamespace)));
983  }
984 
985  /* ignore if not in the same namespace */
986  if (namspace == NULL)
987  {
988  if (def->defnamespace != NULL)
989  continue;
990  }
991  else if (def->defnamespace == NULL)
992  continue;
993  else if (strcmp(def->defnamespace, namspace) != 0)
994  continue;
995 
996  /*
997  * Flatten the DefElem into a text string like "name=arg". If we
998  * have just "name", assume "name=true" is meant. Note: the
999  * namespace is not output.
1000  */
1001  if (def->arg != NULL)
1002  value = defGetString(def);
1003  else
1004  value = "true";
1005 
1006  /*
1007  * This is not a great place for this test, but there's no other
1008  * convenient place to filter the option out. As WITH (oids =
1009  * false) will be removed someday, this seems like an acceptable
1010  * amount of ugly.
1011  */
1012  if (acceptOidsOff && def->defnamespace == NULL &&
1013  strcmp(def->defname, "oids") == 0)
1014  {
1015  if (defGetBoolean(def))
1016  ereport(ERROR,
1017  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1018  errmsg("tables declared WITH OIDS are not supported")));
1019  /* skip over option, reloptions machinery doesn't know it */
1020  continue;
1021  }
1022 
1023  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
1024  /* +1 leaves room for sprintf's trailing null */
1025  t = (text *) palloc(len + 1);
1026  SET_VARSIZE(t, len);
1027  sprintf(VARDATA(t), "%s=%s", def->defname, value);
1028 
1029  astate = accumArrayResult(astate, PointerGetDatum(t),
1030  false, TEXTOID,
1032  }
1033  }
1034 
1035  if (astate)
1036  result = makeArrayResult(astate, CurrentMemoryContext);
1037  else
1038  result = (Datum) 0;
1039 
1040  return result;
1041 }
#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:561
char * defnamespace
Definition: parsenodes.h:729
int errcode(int sqlerrcode)
Definition: elog.c:608
#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
static struct @143 value
#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:822
int i
Definition: c.h:555
char * defname
Definition: parsenodes.h:730
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define PointerIsValid(pointer)
Definition: c.h:632
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

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

1050 {
1051  List *result = NIL;
1052  ArrayType *array;
1053  Datum *optiondatums;
1054  int noptions;
1055  int i;
1056 
1057  /* Nothing to do if no options */
1059  return result;
1060 
1061  array = DatumGetArrayTypeP(options);
1062 
1063  deconstruct_array(array, TEXTOID, -1, false, 'i',
1064  &optiondatums, NULL, &noptions);
1065 
1066  for (i = 0; i < noptions; i++)
1067  {
1068  char *s;
1069  char *p;
1070  Node *val = NULL;
1071 
1072  s = TextDatumGetCString(optiondatums[i]);
1073  p = strchr(s, '=');
1074  if (p)
1075  {
1076  *p++ = '\0';
1077  val = (Node *) makeString(pstrdup(p));
1078  }
1079  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1080  }
1081 
1082  return result;
1083 }
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:88
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:632
long val
Definition: informix.c:664
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1612 of file reloptions.c.

References build_reloptions(), lengthof, offsetof, RELOPT_KIND_VIEW, RELOPT_TYPE_BOOL, and RELOPT_TYPE_ENUM.

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

1613 {
1614  static const relopt_parse_elt tab[] = {
1615  {"security_barrier", RELOPT_TYPE_BOOL,
1616  offsetof(ViewOptions, security_barrier)},
1617  {"check_option", RELOPT_TYPE_ENUM,
1618  offsetof(ViewOptions, check_option)}
1619  };
1620 
1621  return (bytea *) build_reloptions(reloptions, validate,
1623  sizeof(ViewOptions),
1624  tab, lengthof(tab));
1625 }
#define lengthof(array)
Definition: c.h:668
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1562
Definition: c.h:555
#define offsetof(type, field)
Definition: c.h:661