PostgreSQL Source Code  git master
reloptions.c File Reference
#include "postgres.h"
#include <float.h>
#include "access/gist_private.h"
#include "access/hash.h"
#include "access/heaptoast.h"
#include "access/htup_details.h"
#include "access/nbtree.h"
#include "access/reloptions.h"
#include "access/spgist_private.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
#include "commands/tablespace.h"
#include "commands/view.h"
#include "nodes/makefuncs.h"
#include "postmaster/postmaster.h"
#include "utils/array.h"
#include "utils/attoptcache.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/rel.h"
Include dependency graph for reloptions.c:

Go to the source code of this file.

Macros

#define GET_STRING_RELOPTION_LEN(option)
 

Functions

static void initialize_reloptions (void)
 
static void parse_one_reloption (relopt_value *option, char *text_str, int text_len, bool validate)
 
relopt_kind add_reloption_kind (void)
 
static void add_reloption (relopt_gen *newoption)
 
static relopt_genallocate_reloption (bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
 
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)
 
static relopt_valueparseRelOptions (Datum options, bool validate, relopt_kind kind, int *numrelopts)
 
static void * allocateReloptStruct (Size base, relopt_value *options, int numoptions)
 
static void fillRelOptions (void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
 
byteadefault_reloptions (Datum reloptions, bool validate, relopt_kind kind)
 
void * build_reloptions (Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
 
byteapartitioned_table_reloptions (Datum reloptions, bool validate)
 
byteaview_reloptions (Datum reloptions, bool validate)
 
byteaheap_reloptions (char relkind, 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)
 

Variables

static relopt_bool boolRelOpts []
 
static relopt_int intRelOpts []
 
static relopt_real realRelOpts []
 
relopt_enum_elt_def gistBufferingOptValues []
 
relopt_enum_elt_def viewCheckOptValues []
 
static relopt_enum enumRelOpts []
 
static relopt_string stringRelOpts []
 
static relopt_gen ** relOpts = NULL
 
static bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
 
static int num_custom_options = 0
 
static relopt_gen ** custom_options = NULL
 
static bool need_initialization = true
 

Macro Definition Documentation

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

Referenced by allocateReloptStruct().

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()

static void add_reloption ( relopt_gen newoption)
static

Definition at line 635 of file reloptions.c.

References MemoryContextSwitchTo(), need_initialization, num_custom_options, palloc(), repalloc(), and TopMemoryContext.

Referenced by add_bool_reloption(), add_enum_reloption(), add_int_reloption(), add_real_reloption(), and add_string_reloption().

636 {
637  static int max_custom_options = 0;
638 
639  if (num_custom_options >= max_custom_options)
640  {
641  MemoryContext oldcxt;
642 
644 
645  if (max_custom_options == 0)
646  {
647  max_custom_options = 8;
648  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
649  }
650  else
651  {
652  max_custom_options *= 2;
654  max_custom_options * sizeof(relopt_gen *));
655  }
656  MemoryContextSwitchTo(oldcxt);
657  }
658  custom_options[num_custom_options++] = newoption;
659 
660  need_initialization = true;
661 }
static relopt_gen ** custom_options
Definition: reloptions.c:492
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:491
MemoryContext TopMemoryContext
Definition: mcxt.c:44
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1069
void * palloc(Size size)
Definition: mcxt.c:949
static bool need_initialization
Definition: reloptions.c:493

◆ 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

◆ allocate_reloption()

static relopt_gen* allocate_reloption ( bits32  kinds,
int  type,
const char *  name,
const char *  desc,
LOCKMODE  lockmode 
)
static

Definition at line 669 of file reloptions.c.

References relopt_gen::desc, elog, ERROR, relopt_gen::kinds, relopt_gen::lockmode, MemoryContextSwitchTo(), relopt_gen::name, relopt_gen::namelen, palloc(), pstrdup(), RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, TopMemoryContext, relopt_gen::type, and generate_unaccent_rules::type.

Referenced by add_bool_reloption(), add_enum_reloption(), add_int_reloption(), add_real_reloption(), and add_string_reloption().

671 {
672  MemoryContext oldcxt;
673  size_t size;
674  relopt_gen *newoption;
675 
677 
678  switch (type)
679  {
680  case RELOPT_TYPE_BOOL:
681  size = sizeof(relopt_bool);
682  break;
683  case RELOPT_TYPE_INT:
684  size = sizeof(relopt_int);
685  break;
686  case RELOPT_TYPE_REAL:
687  size = sizeof(relopt_real);
688  break;
689  case RELOPT_TYPE_ENUM:
690  size = sizeof(relopt_enum);
691  break;
692  case RELOPT_TYPE_STRING:
693  size = sizeof(relopt_string);
694  break;
695  default:
696  elog(ERROR, "unsupported reloption type %d", type);
697  return NULL; /* keep compiler quiet */
698  }
699 
700  newoption = palloc(size);
701 
702  newoption->name = pstrdup(name);
703  if (desc)
704  newoption->desc = pstrdup(desc);
705  else
706  newoption->desc = NULL;
707  newoption->kinds = kinds;
708  newoption->namelen = strlen(name);
709  newoption->type = type;
710  newoption->lockmode = lockmode;
711 
712  MemoryContextSwitchTo(oldcxt);
713 
714  return newoption;
715 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:67
struct relopt_enum relopt_enum
LOCKMODE lockmode
Definition: reloptions.h:69
char * pstrdup(const char *in)
Definition: mcxt.c:1186
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct relopt_bool relopt_bool
struct relopt_real relopt_real
#define ERROR
Definition: elog.h:43
int namelen
Definition: reloptions.h:70
MemoryContext TopMemoryContext
Definition: mcxt.c:44
bits32 kinds
Definition: reloptions.h:68
relopt_type type
Definition: reloptions.h:71
struct relopt_int relopt_int
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:949
const char * name
Definition: reloptions.h:65
#define elog(elevel,...)
Definition: elog.h:228

◆ allocateReloptStruct()

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

Definition at line 1380 of file reloptions.c.

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

Referenced by build_reloptions().

1381 {
1382  Size size = base;
1383  int i;
1384 
1385  for (i = 0; i < numoptions; i++)
1386  if (options[i].gen->type == RELOPT_TYPE_STRING)
1387  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1388 
1389  return palloc0(size);
1390 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.c:504
void * palloc0(Size size)
Definition: mcxt.c:980
size_t Size
Definition: c.h:467
int i

◆ 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

◆ fillRelOptions()

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

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

1408 {
1409  int i;
1410  int offset = basesize;
1411 
1412  for (i = 0; i < numoptions; i++)
1413  {
1414  int j;
1415  bool found = false;
1416 
1417  for (j = 0; j < numelems; j++)
1418  {
1419  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1420  {
1421  relopt_string *optstring;
1422  char *itempos = ((char *) rdopts) + elems[j].offset;
1423  char *string_val;
1424 
1425  switch (options[i].gen->type)
1426  {
1427  case RELOPT_TYPE_BOOL:
1428  *(bool *) itempos = options[i].isset ?
1429  options[i].values.bool_val :
1430  ((relopt_bool *) options[i].gen)->default_val;
1431  break;
1432  case RELOPT_TYPE_INT:
1433  *(int *) itempos = options[i].isset ?
1434  options[i].values.int_val :
1435  ((relopt_int *) options[i].gen)->default_val;
1436  break;
1437  case RELOPT_TYPE_REAL:
1438  *(double *) itempos = options[i].isset ?
1439  options[i].values.real_val :
1440  ((relopt_real *) options[i].gen)->default_val;
1441  break;
1442  case RELOPT_TYPE_ENUM:
1443  *(int *) itempos = options[i].isset ?
1444  options[i].values.enum_val :
1445  ((relopt_enum *) options[i].gen)->default_val;
1446  break;
1447  case RELOPT_TYPE_STRING:
1448  optstring = (relopt_string *) options[i].gen;
1449  if (options[i].isset)
1450  string_val = options[i].values.string_val;
1451  else if (!optstring->default_isnull)
1452  string_val = optstring->default_val;
1453  else
1454  string_val = NULL;
1455 
1456  if (string_val == NULL)
1457  *(int *) itempos = 0;
1458  else
1459  {
1460  strcpy((char *) rdopts + offset, string_val);
1461  *(int *) itempos = offset;
1462  offset += strlen(string_val) + 1;
1463  }
1464  break;
1465  default:
1466  elog(ERROR, "unsupported reloption type %d",
1467  options[i].gen->type);
1468  break;
1469  }
1470  found = true;
1471  break;
1472  }
1473  }
1474  if (validate && !found)
1475  elog(ERROR, "reloption \"%s\" not found in parse table",
1476  options[i].gen->name);
1477  }
1478  SET_VARSIZE(rdopts, offset);
1479 }
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:228
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 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

◆ initialize_reloptions()

static void initialize_reloptions ( void  )
static

Definition at line 515 of file reloptions.c.

References Assert, DoLockModesConflict(), relopt_bool::gen, relopt_int::gen, relopt_real::gen, relopt_enum::gen, relopt_string::gen, i, relopt_gen::lockmode, MemoryContextAlloc(), relopt_gen::name, name, relopt_gen::namelen, need_initialization, num_custom_options, pfree(), RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, TopMemoryContext, and relopt_gen::type.

Referenced by AlterTableGetRelOptionsLockLevel(), and parseRelOptions().

516 {
517  int i;
518  int j;
519 
520  j = 0;
521  for (i = 0; boolRelOpts[i].gen.name; i++)
522  {
523  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
524  boolRelOpts[i].gen.lockmode));
525  j++;
526  }
527  for (i = 0; intRelOpts[i].gen.name; i++)
528  {
529  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
530  intRelOpts[i].gen.lockmode));
531  j++;
532  }
533  for (i = 0; realRelOpts[i].gen.name; i++)
534  {
535  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
536  realRelOpts[i].gen.lockmode));
537  j++;
538  }
539  for (i = 0; enumRelOpts[i].gen.name; i++)
540  {
541  Assert(DoLockModesConflict(enumRelOpts[i].gen.lockmode,
542  enumRelOpts[i].gen.lockmode));
543  j++;
544  }
545  for (i = 0; stringRelOpts[i].gen.name; i++)
546  {
547  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
549  j++;
550  }
551  j += num_custom_options;
552 
553  if (relOpts)
554  pfree(relOpts);
556  (j + 1) * sizeof(relopt_gen *));
557 
558  j = 0;
559  for (i = 0; boolRelOpts[i].gen.name; i++)
560  {
561  relOpts[j] = &boolRelOpts[i].gen;
563  relOpts[j]->namelen = strlen(relOpts[j]->name);
564  j++;
565  }
566 
567  for (i = 0; intRelOpts[i].gen.name; i++)
568  {
569  relOpts[j] = &intRelOpts[i].gen;
571  relOpts[j]->namelen = strlen(relOpts[j]->name);
572  j++;
573  }
574 
575  for (i = 0; realRelOpts[i].gen.name; i++)
576  {
577  relOpts[j] = &realRelOpts[i].gen;
579  relOpts[j]->namelen = strlen(relOpts[j]->name);
580  j++;
581  }
582 
583  for (i = 0; enumRelOpts[i].gen.name; i++)
584  {
585  relOpts[j] = &enumRelOpts[i].gen;
587  relOpts[j]->namelen = strlen(relOpts[j]->name);
588  j++;
589  }
590 
591  for (i = 0; stringRelOpts[i].gen.name; i++)
592  {
593  relOpts[j] = &stringRelOpts[i].gen;
595  relOpts[j]->namelen = strlen(relOpts[j]->name);
596  j++;
597  }
598 
599  for (i = 0; i < num_custom_options; i++)
600  {
601  relOpts[j] = custom_options[i];
602  j++;
603  }
604 
605  /* add a list terminator */
606  relOpts[j] = NULL;
607 
608  /* flag the work is complete */
609  need_initialization = false;
610 }
static relopt_gen ** custom_options
Definition: reloptions.c:492
relopt_gen gen
Definition: reloptions.h:124
LOCKMODE lockmode
Definition: reloptions.h:69
static relopt_bool boolRelOpts[]
Definition: reloptions.c:96
relopt_gen gen
Definition: reloptions.h:136
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_custom_options
Definition: reloptions.c:491
relopt_gen gen
Definition: reloptions.h:92
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:358
int namelen
Definition: reloptions.h:70
MemoryContext TopMemoryContext
Definition: mcxt.c:44
relopt_gen gen
Definition: reloptions.h:98
#define Assert(condition)
Definition: c.h:739
relopt_type type
Definition: reloptions.h:71
relopt_gen gen
Definition: reloptions.h:106
const char * name
Definition: encode.c:521
static relopt_string stringRelOpts[]
Definition: reloptions.c:482
const char * name
Definition: reloptions.h:65
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
int i
static bool need_initialization
Definition: reloptions.c:493
static relopt_enum enumRelOpts[]
Definition: reloptions.c:454
static relopt_int intRelOpts[]
Definition: reloptions.c:165
static relopt_gen ** relOpts
Definition: reloptions.c:488

◆ parse_one_reloption()

static void parse_one_reloption ( relopt_value option,
char *  text_str,
int  text_len,
bool  validate 
)
static

Definition at line 1247 of file reloptions.c.

References _, relopt_value::bool_val, relopt_enum::default_val, relopt_enum::detailmsg, elog, relopt_value::enum_val, ereport, errcode(), errdetail(), errdetail_internal(), errmsg(), ERROR, relopt_value::gen, relopt_value::int_val, relopt_value::isset, relopt_int::max, relopt_real::max, relopt_enum::members, relopt_int::min, relopt_real::min, relopt_gen::name, relopt_gen::namelen, palloc(), parse_bool(), parse_int(), parse_real(), pfree(), pg_strcasecmp(), relopt_value::real_val, RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, relopt_value::string_val, relopt_enum_elt_def::string_val, relopt_gen::type, relopt_string::validate_cb, value, and relopt_value::values.

Referenced by parseRelOptions().

1249 {
1250  char *value;
1251  int value_len;
1252  bool parsed;
1253  bool nofree = false;
1254 
1255  if (option->isset && validate)
1256  ereport(ERROR,
1257  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1258  errmsg("parameter \"%s\" specified more than once",
1259  option->gen->name)));
1260 
1261  value_len = text_len - option->gen->namelen - 1;
1262  value = (char *) palloc(value_len + 1);
1263  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1264  value[value_len] = '\0';
1265 
1266  switch (option->gen->type)
1267  {
1268  case RELOPT_TYPE_BOOL:
1269  {
1270  parsed = parse_bool(value, &option->values.bool_val);
1271  if (validate && !parsed)
1272  ereport(ERROR,
1273  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1274  errmsg("invalid value for boolean option \"%s\": %s",
1275  option->gen->name, value)));
1276  }
1277  break;
1278  case RELOPT_TYPE_INT:
1279  {
1280  relopt_int *optint = (relopt_int *) option->gen;
1281 
1282  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1283  if (validate && !parsed)
1284  ereport(ERROR,
1285  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1286  errmsg("invalid value for integer option \"%s\": %s",
1287  option->gen->name, value)));
1288  if (validate && (option->values.int_val < optint->min ||
1289  option->values.int_val > optint->max))
1290  ereport(ERROR,
1291  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1292  errmsg("value %s out of bounds for option \"%s\"",
1293  value, option->gen->name),
1294  errdetail("Valid values are between \"%d\" and \"%d\".",
1295  optint->min, optint->max)));
1296  }
1297  break;
1298  case RELOPT_TYPE_REAL:
1299  {
1300  relopt_real *optreal = (relopt_real *) option->gen;
1301 
1302  parsed = parse_real(value, &option->values.real_val, 0, NULL);
1303  if (validate && !parsed)
1304  ereport(ERROR,
1305  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1306  errmsg("invalid value for floating point option \"%s\": %s",
1307  option->gen->name, value)));
1308  if (validate && (option->values.real_val < optreal->min ||
1309  option->values.real_val > optreal->max))
1310  ereport(ERROR,
1311  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1312  errmsg("value %s out of bounds for option \"%s\"",
1313  value, option->gen->name),
1314  errdetail("Valid values are between \"%f\" and \"%f\".",
1315  optreal->min, optreal->max)));
1316  }
1317  break;
1318  case RELOPT_TYPE_ENUM:
1319  {
1320  relopt_enum *optenum = (relopt_enum *) option->gen;
1321  relopt_enum_elt_def *elt;
1322 
1323  parsed = false;
1324  for (elt = optenum->members; elt->string_val; elt++)
1325  {
1326  if (pg_strcasecmp(value, elt->string_val) == 0)
1327  {
1328  option->values.enum_val = elt->symbol_val;
1329  parsed = true;
1330  break;
1331  }
1332  }
1333  if (validate && !parsed)
1334  ereport(ERROR,
1335  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1336  errmsg("invalid value for enum option \"%s\": %s",
1337  option->gen->name, value),
1338  optenum->detailmsg ?
1339  errdetail_internal("%s", _(optenum->detailmsg)) : 0));
1340 
1341  /*
1342  * If value is not among the allowed string values, but we are
1343  * not asked to validate, just use the default numeric value.
1344  */
1345  if (!parsed)
1346  option->values.enum_val = optenum->default_val;
1347  }
1348  break;
1349  case RELOPT_TYPE_STRING:
1350  {
1351  relopt_string *optstring = (relopt_string *) option->gen;
1352 
1353  option->values.string_val = value;
1354  nofree = true;
1355  if (validate && optstring->validate_cb)
1356  (optstring->validate_cb) (value);
1357  parsed = true;
1358  }
1359  break;
1360  default:
1361  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1362  parsed = true; /* quiet compiler */
1363  break;
1364  }
1365 
1366  if (parsed)
1367  option->isset = true;
1368  if (!nofree)
1369  pfree(value);
1370 }
bool bool_val
Definition: reloptions.h:81
char * string_val
Definition: reloptions.h:85
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:608
bool parse_real(const char *value, double *result, int flags, const char **hintmsg)
Definition: guc.c:6409
bool parse_bool(const char *value, bool *result)
Definition: bool.c:30
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
relopt_gen * gen
Definition: reloptions.h:77
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
const char * detailmsg
Definition: reloptions.h:127
union relopt_value::@47 values
int errdetail(const char *fmt,...)
Definition: elog.c:955
int namelen
Definition: reloptions.h:70
relopt_enum_elt_def * members
Definition: reloptions.h:125
double real_val
Definition: reloptions.h:83
#define ereport(elevel, rest)
Definition: elog.h:141
validate_string_relopt validate_cb
Definition: reloptions.h:139
int default_val
Definition: reloptions.h:126
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:6319
relopt_type type
Definition: reloptions.h:71
const char * string_val
Definition: reloptions.h:118
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
const char * name
Definition: reloptions.h:65
#define elog(elevel,...)
Definition: elog.h:228
double max
Definition: reloptions.h:109
#define _(x)
Definition: elog.c:87
double min
Definition: reloptions.h:108

◆ parseRelOptions()

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

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

1157 {
1158  relopt_value *reloptions = NULL;
1159  int numoptions = 0;
1160  int i;
1161  int j;
1162 
1163  if (need_initialization)
1165 
1166  /* Build a list of expected options, based on kind */
1167 
1168  for (i = 0; relOpts[i]; i++)
1169  if (relOpts[i]->kinds & kind)
1170  numoptions++;
1171 
1172  if (numoptions > 0)
1173  {
1174  reloptions = palloc(numoptions * sizeof(relopt_value));
1175 
1176  for (i = 0, j = 0; relOpts[i]; i++)
1177  {
1178  if (relOpts[i]->kinds & kind)
1179  {
1180  reloptions[j].gen = relOpts[i];
1181  reloptions[j].isset = false;
1182  j++;
1183  }
1184  }
1185  }
1186 
1187  /* Done if no options */
1189  {
1191  Datum *optiondatums;
1192  int noptions;
1193 
1194  deconstruct_array(array, TEXTOID, -1, false, 'i',
1195  &optiondatums, NULL, &noptions);
1196 
1197  for (i = 0; i < noptions; i++)
1198  {
1199  char *text_str = VARDATA(optiondatums[i]);
1200  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1201  int j;
1202 
1203  /* Search for a match in reloptions */
1204  for (j = 0; j < numoptions; j++)
1205  {
1206  int kw_len = reloptions[j].gen->namelen;
1207 
1208  if (text_len > kw_len && text_str[kw_len] == '=' &&
1209  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1210  {
1211  parse_one_reloption(&reloptions[j], text_str, text_len,
1212  validate);
1213  break;
1214  }
1215  }
1216 
1217  if (j >= numoptions && validate)
1218  {
1219  char *s;
1220  char *p;
1221 
1222  s = TextDatumGetCString(optiondatums[i]);
1223  p = strchr(s, '=');
1224  if (p)
1225  *p = '\0';
1226  ereport(ERROR,
1227  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1228  errmsg("unrecognized parameter \"%s\"", s)));
1229  }
1230  }
1231 
1232  /* It's worth avoiding memory leaks in this function */
1233  pfree(optiondatums);
1234  if (((void *) array) != DatumGetPointer(options))
1235  pfree(array);
1236  }
1237 
1238  *numrelopts = numoptions;
1239  return reloptions;
1240 }
static void initialize_reloptions(void)
Definition: reloptions.c:515
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:562
int errcode(int sqlerrcode)
Definition: elog.c:608
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:1247
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:822
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:633
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ 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

Variable Documentation

◆ boolRelOpts

relopt_bool boolRelOpts[]
static

Definition at line 96 of file reloptions.c.

◆ custom_options

relopt_gen** custom_options = NULL
static

Definition at line 492 of file reloptions.c.

◆ enumRelOpts

relopt_enum enumRelOpts[]
static
Initial value:
=
{
{
{
"buffering",
"Enables buffering build for this GiST index",
},
gettext_noop("Valid values are \"on\", \"off\", and \"auto\".")
},
{
{
"check_option",
"View has WITH CHECK OPTION defined (local or cascaded).",
},
gettext_noop("Valid values are \"local\" and \"cascaded\".")
},
{{NULL}}
}
#define gettext_noop(x)
Definition: c.h:1148
relopt_enum_elt_def gistBufferingOptValues[]
Definition: reloptions.c:437
relopt_enum_elt_def viewCheckOptValues[]
Definition: reloptions.c:446
#define AccessExclusiveLock
Definition: lockdefs.h:45

Definition at line 454 of file reloptions.c.

◆ gistBufferingOptValues

relopt_enum_elt_def gistBufferingOptValues[]

◆ intRelOpts

relopt_int intRelOpts[]
static

Definition at line 165 of file reloptions.c.

◆ last_assigned_kind

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

Definition at line 489 of file reloptions.c.

Referenced by add_reloption_kind().

◆ need_initialization

bool need_initialization = true
static

◆ num_custom_options

int num_custom_options = 0
static

Definition at line 491 of file reloptions.c.

Referenced by add_reloption(), and initialize_reloptions().

◆ realRelOpts

relopt_real realRelOpts[]
static

Definition at line 358 of file reloptions.c.

◆ relOpts

relopt_gen** relOpts = NULL
static

Definition at line 488 of file reloptions.c.

◆ stringRelOpts

relopt_string stringRelOpts[]
static
Initial value:
=
{
{{NULL}}
}

Definition at line 482 of file reloptions.c.

◆ viewCheckOptValues

relopt_enum_elt_def viewCheckOptValues[]
Initial value:

Definition at line 446 of file reloptions.c.