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

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

Referenced by create_reloptions_table().

724 {
725  relopt_bool *newoption;
726 
727  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
728  name, desc, lockmode);
729  newoption->default_val = default_val;
730 
731  add_reloption((relopt_gen *) newoption);
732 }
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:669
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:635
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 785 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().

788 {
789  relopt_enum *newoption;
790 
791  newoption = (relopt_enum *) allocate_reloption(kinds, RELOPT_TYPE_ENUM,
792  name, desc, lockmode);
793  newoption->members = members;
794  newoption->default_val = default_val;
795  newoption->detailmsg = detailmsg;
796 
797  add_reloption((relopt_gen *) newoption);
798 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:669
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:635
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 739 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().

741 {
742  relopt_int *newoption;
743 
744  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
745  name, desc, lockmode);
746  newoption->default_val = default_val;
747  newoption->min = min_val;
748  newoption->max = max_val;
749 
750  add_reloption((relopt_gen *) newoption);
751 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:669
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:635
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 758 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().

760 {
761  relopt_real *newoption;
762 
763  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
764  name, desc, lockmode);
765  newoption->default_val = default_val;
766  newoption->min = min_val;
767  newoption->max = max_val;
768 
769  add_reloption((relopt_gen *) newoption);
770 }
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:669
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:635
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 618 of file reloptions.c.

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

Referenced by _PG_init(), and create_reloptions_table().

619 {
620  /* don't hand out the last bit so that the enum's behavior is portable */
622  ereport(ERROR,
623  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
624  errmsg("user-defined relation parameter types limit exceeded")));
625  last_assigned_kind <<= 1;
627 }
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: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 810 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().

812 {
813  relopt_string *newoption;
814 
815  /* make sure the validator/default combination is sane */
816  if (validator)
817  (validator) (default_val);
818 
819  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
820  name, desc, lockmode);
821  newoption->validate_cb = validator;
822  if (default_val)
823  {
825  default_val);
826  newoption->default_len = strlen(default_val);
827  newoption->default_isnull = false;
828  }
829  else
830  {
831  newoption->default_val = "";
832  newoption->default_len = 0;
833  newoption->default_isnull = true;
834  }
835 
836  add_reloption((relopt_gen *) newoption);
837 }
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:669
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:635
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 1709 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().

1710 {
1711  LOCKMODE lockmode = NoLock;
1712  ListCell *cell;
1713 
1714  if (defList == NIL)
1715  return AccessExclusiveLock;
1716 
1717  if (need_initialization)
1719 
1720  foreach(cell, defList)
1721  {
1722  DefElem *def = (DefElem *) lfirst(cell);
1723  int i;
1724 
1725  for (i = 0; relOpts[i]; i++)
1726  {
1727  if (strncmp(relOpts[i]->name,
1728  def->defname,
1729  relOpts[i]->namelen + 1) == 0)
1730  {
1731  if (lockmode < relOpts[i]->lockmode)
1732  lockmode = relOpts[i]->lockmode;
1733  }
1734  }
1735  }
1736 
1737  return lockmode;
1738 }
#define NIL
Definition: pg_list.h:65
static void initialize_reloptions(void)
Definition: reloptions.c:515
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 1671 of file reloptions.c.

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

Referenced by ATExecSetOptions(), and get_attribute_options().

1672 {
1673  static const relopt_parse_elt tab[] = {
1674  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1675  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1676  };
1677 
1678  return (bytea *) build_reloptions(reloptions, validate,
1680  sizeof(AttributeOpts),
1681  tab, lengthof(tab));
1682 }
#define lengthof(array)
Definition: c.h:669
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:1552
Definition: c.h:556
#define offsetof(type, field)
Definition: c.h:662

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

1557 {
1558  int numoptions;
1560  void *rdopts;
1561 
1562  /* parse options specific to given relation option kind */
1563  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1564  Assert(numoptions <= num_relopt_elems);
1565 
1566  /* if none set, we're done */
1567  if (numoptions == 0)
1568  {
1569  Assert(options == NULL);
1570  return NULL;
1571  }
1572 
1573  /* allocate and fill the structure */
1574  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1575  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1576  validate, relopt_elems, num_relopt_elems);
1577 
1578  pfree(options);
1579 
1580  return rdopts;
1581 }
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1380
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:1404
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1155
static char ** options
#define Assert(condition)
Definition: c.h:739

◆ default_reloptions()

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

Definition at line 1486 of file reloptions.c.

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

Referenced by heap_reloptions().

1487 {
1488  static const relopt_parse_elt tab[] = {
1489  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1490  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1491  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1492  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1493  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1494  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1495  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1496  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1497  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1498  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1499  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1500  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1501  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1502  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1503  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1504  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1505  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1506  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1507  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1508  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1509  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1510  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1511  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1512  {"toast_tuple_target", RELOPT_TYPE_INT,
1513  offsetof(StdRdOptions, toast_tuple_target)},
1514  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1515  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1516  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1517  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1518  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1519  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1520  {"user_catalog_table", RELOPT_TYPE_BOOL,
1521  offsetof(StdRdOptions, user_catalog_table)},
1522  {"parallel_workers", RELOPT_TYPE_INT,
1523  offsetof(StdRdOptions, parallel_workers)},
1524  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1525  offsetof(StdRdOptions, vacuum_index_cleanup)},
1526  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1527  offsetof(StdRdOptions, vacuum_truncate)}
1528  };
1529 
1530  return (bytea *) build_reloptions(reloptions, validate, kind,
1531  sizeof(StdRdOptions),
1532  tab, lengthof(tab));
1533 }
#define lengthof(array)
Definition: c.h:669
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:1552
int fillfactor
Definition: pgbench.c:160
Definition: c.h:556
#define offsetof(type, field)
Definition: c.h:662

◆ extractRelOptions()

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

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

1090 {
1091  bytea *options;
1092  bool isnull;
1093  Datum datum;
1094  Form_pg_class classForm;
1095 
1096  datum = fastgetattr(tuple,
1097  Anum_pg_class_reloptions,
1098  tupdesc,
1099  &isnull);
1100  if (isnull)
1101  return NULL;
1102 
1103  classForm = (Form_pg_class) GETSTRUCT(tuple);
1104 
1105  /* Parse into appropriate format; don't error out here */
1106  switch (classForm->relkind)
1107  {
1108  case RELKIND_RELATION:
1109  case RELKIND_TOASTVALUE:
1110  case RELKIND_MATVIEW:
1111  options = heap_reloptions(classForm->relkind, datum, false);
1112  break;
1113  case RELKIND_PARTITIONED_TABLE:
1114  options = partitioned_table_reloptions(datum, false);
1115  break;
1116  case RELKIND_VIEW:
1117  options = view_reloptions(datum, false);
1118  break;
1119  case RELKIND_INDEX:
1120  case RELKIND_PARTITIONED_INDEX:
1121  options = index_reloptions(amoptions, datum, false);
1122  break;
1123  case RELKIND_FOREIGN_TABLE:
1124  options = NULL;
1125  break;
1126  default:
1127  Assert(false); /* can't get here */
1128  options = NULL; /* keep compiler quiet */
1129  break;
1130  }
1131 
1132  return options;
1133 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1621
#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:1602
static char ** options
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1587
uintptr_t Datum
Definition: postgres.h:367
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1656
#define Assert(condition)
Definition: c.h:739
FormData_pg_class * Form_pg_class
Definition: pg_class.h:150
Definition: c.h:556

◆ heap_reloptions()

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

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

1622 {
1623  StdRdOptions *rdopts;
1624 
1625  switch (relkind)
1626  {
1627  case RELKIND_TOASTVALUE:
1628  rdopts = (StdRdOptions *)
1629  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1630  if (rdopts != NULL)
1631  {
1632  /* adjust default-only parameters for TOAST relations */
1633  rdopts->fillfactor = 100;
1634  rdopts->autovacuum.analyze_threshold = -1;
1635  rdopts->autovacuum.analyze_scale_factor = -1;
1636  }
1637  return (bytea *) rdopts;
1638  case RELKIND_RELATION:
1639  case RELKIND_MATVIEW:
1640  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1641  default:
1642  /* other relkinds are not supported */
1643  return NULL;
1644  }
1645 }
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:1486
Definition: c.h:556
AutoVacOpts autovacuum
Definition: rel.h:269

◆ index_reloptions()

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

Definition at line 1656 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

1657 {
1658  Assert(amoptions != NULL);
1659 
1660  /* Assume function is strict */
1661  if (!PointerIsValid(DatumGetPointer(reloptions)))
1662  return NULL;
1663 
1664  return amoptions(reloptions, validate);
1665 }
#define Assert(condition)
Definition: c.h:739
#define DatumGetPointer(X)
Definition: postgres.h:549
#define PointerIsValid(pointer)
Definition: c.h:633

◆ partitioned_table_reloptions()

bytea* partitioned_table_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1587 of file reloptions.c.

References build_reloptions(), and RELOPT_KIND_PARTITIONED.

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

1588 {
1589  /*
1590  * There are no options for partitioned tables yet, but this is able to do
1591  * some validation.
1592  */
1593  return (bytea *) build_reloptions(reloptions, validate,
1595  0, NULL, 0);
1596 }
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:1552
Definition: c.h:556

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

1689 {
1690  static const relopt_parse_elt tab[] = {
1691  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1692  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1693  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1694  };
1695 
1696  return (bytea *) build_reloptions(reloptions, validate,
1698  sizeof(TableSpaceOpts),
1699  tab, lengthof(tab));
1700 }
#define lengthof(array)
Definition: c.h:669
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:1552
double random_page_cost
Definition: costsize.c:111
Definition: c.h:556
double seq_page_cost
Definition: costsize.c:110
#define offsetof(type, field)
Definition: c.h:662

◆ transformRelOptions()

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

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

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

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

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

1040 {
1041  List *result = NIL;
1042  ArrayType *array;
1043  Datum *optiondatums;
1044  int noptions;
1045  int i;
1046 
1047  /* Nothing to do if no options */
1049  return result;
1050 
1051  array = DatumGetArrayTypeP(options);
1052 
1053  deconstruct_array(array, TEXTOID, -1, false, 'i',
1054  &optiondatums, NULL, &noptions);
1055 
1056  for (i = 0; i < noptions; i++)
1057  {
1058  char *s;
1059  char *p;
1060  Node *val = NULL;
1061 
1062  s = TextDatumGetCString(optiondatums[i]);
1063  p = strchr(s, '=');
1064  if (p)
1065  {
1066  *p++ = '\0';
1067  val = (Node *) makeString(pstrdup(p));
1068  }
1069  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1070  }
1071 
1072  return result;
1073 }
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:633
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 1602 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().

1603 {
1604  static const relopt_parse_elt tab[] = {
1605  {"security_barrier", RELOPT_TYPE_BOOL,
1606  offsetof(ViewOptions, security_barrier)},
1607  {"check_option", RELOPT_TYPE_ENUM,
1608  offsetof(ViewOptions, check_option)}
1609  };
1610 
1611  return (bytea *) build_reloptions(reloptions, validate,
1613  sizeof(ViewOptions),
1614  tab, lengthof(tab));
1615 }
#define lengthof(array)
Definition: c.h:669
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:1552
Definition: c.h:556
#define offsetof(type, field)
Definition: c.h:662