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/htup_details.h"
#include "access/nbtree.h"
#include "access/reloptions.h"
#include "access/spgist.h"
#include "access/tuptoaster.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.

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)
 
void add_bool_reloption (bits32 kinds, const char *name, const char *desc, bool default_val)
 
void add_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val)
 
void add_real_reloption (bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val)
 
void add_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator)
 
Datum transformRelOptions (Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
 
ListuntransformRelOptions (Datum options)
 
byteaextractRelOptions (HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
 
relopt_valueparseRelOptions (Datum options, bool validate, relopt_kind kind, int *numrelopts)
 
void * allocateReloptStruct (Size base, relopt_value *options, int numoptions)
 
void fillRelOptions (void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
 
byteadefault_reloptions (Datum reloptions, bool validate, relopt_kind kind)
 
byteaview_reloptions (Datum reloptions, bool validate)
 
byteaheap_reloptions (char relkind, Datum reloptions, bool validate)
 
byteaindex_reloptions (amoptions_function amoptions, Datum reloptions, bool validate)
 
byteaindex_generic_reloptions (Datum reloptions, bool validate)
 
byteaattribute_reloptions (Datum reloptions, bool validate)
 
byteatablespace_reloptions (Datum reloptions, bool validate)
 
LOCKMODE AlterTableGetRelOptionsLockLevel (List *defList)
 

Variables

static relopt_bool boolRelOpts []
 
static relopt_int intRelOpts []
 
static relopt_real realRelOpts []
 
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
 

Function Documentation

◆ add_bool_reloption()

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

Definition at line 661 of file reloptions.c.

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

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

◆ add_int_reloption()

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

Definition at line 677 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_int::default_val, relopt_int::max, relopt_int::min, and RELOPT_TYPE_INT.

Referenced by _PG_init().

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

◆ add_real_reloption()

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

Definition at line 696 of file reloptions.c.

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

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

◆ add_reloption()

static void add_reloption ( relopt_gen newoption)
static

Definition at line 579 of file reloptions.c.

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

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

580 {
581  static int max_custom_options = 0;
582 
583  if (num_custom_options >= max_custom_options)
584  {
585  MemoryContext oldcxt;
586 
588 
589  if (max_custom_options == 0)
590  {
591  max_custom_options = 8;
592  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
593  }
594  else
595  {
596  max_custom_options *= 2;
598  max_custom_options * sizeof(relopt_gen *));
599  }
600  MemoryContextSwitchTo(oldcxt);
601  }
602  custom_options[num_custom_options++] = newoption;
603 
604  need_initialization = true;
605 }
static relopt_gen ** custom_options
Definition: reloptions.c:459
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:458
MemoryContext TopMemoryContext
Definition: mcxt.c:44
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1044
void * palloc(Size size)
Definition: mcxt.c:924
static bool need_initialization
Definition: reloptions.c:460

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 562 of file reloptions.c.

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

Referenced by _PG_init().

563 {
564  /* don't hand out the last bit so that the enum's behavior is portable */
566  ereport(ERROR,
567  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
568  errmsg("user-defined relation parameter types limit exceeded")));
569  last_assigned_kind <<= 1;
571 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
relopt_kind
Definition: reloptions.h:38
static bits32 last_assigned_kind
Definition: reloptions.c:456

◆ add_string_reloption()

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

Definition at line 720 of file reloptions.c.

References add_reloption(), allocate_reloption(), relopt_string::default_isnull, relopt_string::default_len, relopt_string::default_val, MemoryContextStrdup(), RELOPT_TYPE_STRING, TopMemoryContext, and relopt_string::validate_cb.

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

◆ allocate_reloption()

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

Definition at line 613 of file reloptions.c.

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

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

614 {
615  MemoryContext oldcxt;
616  size_t size;
617  relopt_gen *newoption;
618 
620 
621  switch (type)
622  {
623  case RELOPT_TYPE_BOOL:
624  size = sizeof(relopt_bool);
625  break;
626  case RELOPT_TYPE_INT:
627  size = sizeof(relopt_int);
628  break;
629  case RELOPT_TYPE_REAL:
630  size = sizeof(relopt_real);
631  break;
632  case RELOPT_TYPE_STRING:
633  size = sizeof(relopt_string);
634  break;
635  default:
636  elog(ERROR, "unsupported reloption type %d", type);
637  return NULL; /* keep compiler quiet */
638  }
639 
640  newoption = palloc(size);
641 
642  newoption->name = pstrdup(name);
643  if (desc)
644  newoption->desc = pstrdup(desc);
645  else
646  newoption->desc = NULL;
647  newoption->kinds = kinds;
648  newoption->namelen = strlen(name);
649  newoption->type = type;
650 
651  MemoryContextSwitchTo(oldcxt);
652 
653  return newoption;
654 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:67
char * pstrdup(const char *in)
Definition: mcxt.c:1161
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:924
const char * name
Definition: reloptions.h:65
#define elog
Definition: elog.h:219

◆ allocateReloptStruct()

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

Definition at line 1242 of file reloptions.c.

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

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

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

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 1593 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

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

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1527 of file reloptions.c.

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

Referenced by ATExecSetOptions(), and get_attribute_options().

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

◆ default_reloptions()

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

Definition at line 1343 of file reloptions.c.

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

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

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

◆ extractRelOptions()

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

Definition at line 983 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

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

◆ fillRelOptions()

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

Definition at line 1266 of file reloptions.c.

References relopt_string::default_isnull, relopt_string::default_val, elog, ERROR, relopt_value::gen, i, relopt_parse_elt::offset, relopt_parse_elt::optname, RELOPT_KIND_INDEX, RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, SET_VARSIZE, relopt_value::string_val, relopt_value::values, and values.

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

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

◆ heap_reloptions()

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

Definition at line 1440 of file reloptions.c.

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

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

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

◆ index_generic_reloptions()

bytea* index_generic_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1496 of file reloptions.c.

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

Referenced by IsProjectionFunctionalIndex().

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

◆ index_reloptions()

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

Definition at line 1478 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

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

◆ initialize_reloptions()

static void initialize_reloptions ( void  )
static

Definition at line 473 of file reloptions.c.

References Assert, DoLockModesConflict(), relopt_bool::gen, relopt_int::gen, relopt_real::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_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, TopMemoryContext, and relopt_gen::type.

Referenced by AlterTableGetRelOptionsLockLevel(), and parseRelOptions().

474 {
475  int i;
476  int j;
477 
478  j = 0;
479  for (i = 0; boolRelOpts[i].gen.name; i++)
480  {
481  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
482  boolRelOpts[i].gen.lockmode));
483  j++;
484  }
485  for (i = 0; intRelOpts[i].gen.name; i++)
486  {
487  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
488  intRelOpts[i].gen.lockmode));
489  j++;
490  }
491  for (i = 0; realRelOpts[i].gen.name; i++)
492  {
493  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
494  realRelOpts[i].gen.lockmode));
495  j++;
496  }
497  for (i = 0; stringRelOpts[i].gen.name; i++)
498  {
499  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
501  j++;
502  }
503  j += num_custom_options;
504 
505  if (relOpts)
506  pfree(relOpts);
508  (j + 1) * sizeof(relopt_gen *));
509 
510  j = 0;
511  for (i = 0; boolRelOpts[i].gen.name; i++)
512  {
513  relOpts[j] = &boolRelOpts[i].gen;
515  relOpts[j]->namelen = strlen(relOpts[j]->name);
516  j++;
517  }
518 
519  for (i = 0; intRelOpts[i].gen.name; i++)
520  {
521  relOpts[j] = &intRelOpts[i].gen;
523  relOpts[j]->namelen = strlen(relOpts[j]->name);
524  j++;
525  }
526 
527  for (i = 0; realRelOpts[i].gen.name; i++)
528  {
529  relOpts[j] = &realRelOpts[i].gen;
531  relOpts[j]->namelen = strlen(relOpts[j]->name);
532  j++;
533  }
534 
535  for (i = 0; stringRelOpts[i].gen.name; i++)
536  {
537  relOpts[j] = &stringRelOpts[i].gen;
539  relOpts[j]->namelen = strlen(relOpts[j]->name);
540  j++;
541  }
542 
543  for (i = 0; i < num_custom_options; i++)
544  {
545  relOpts[j] = custom_options[i];
546  j++;
547  }
548 
549  /* add a list terminator */
550  relOpts[j] = NULL;
551 
552  /* flag the work is complete */
553  need_initialization = false;
554 }
static relopt_gen ** custom_options
Definition: reloptions.c:459
LOCKMODE lockmode
Definition: reloptions.h:69
static relopt_bool boolRelOpts[]
Definition: reloptions.c:94
relopt_gen gen
Definition: reloptions.h:116
void pfree(void *pointer)
Definition: mcxt.c:1031
static int num_custom_options
Definition: reloptions.c:458
relopt_gen gen
Definition: reloptions.h:91
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:356
int namelen
Definition: reloptions.h:70
MemoryContext TopMemoryContext
Definition: mcxt.c:44
relopt_gen gen
Definition: reloptions.h:97
#define Assert(condition)
Definition: c.h:699
relopt_type type
Definition: reloptions.h:71
relopt_gen gen
Definition: reloptions.h:105
const char * name
Definition: encode.c:521
static relopt_string stringRelOpts[]
Definition: reloptions.c:425
const char * name
Definition: reloptions.h:65
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
int i
static bool need_initialization
Definition: reloptions.c:460
static relopt_int intRelOpts[]
Definition: reloptions.c:154
static relopt_gen ** relOpts
Definition: reloptions.c:455

◆ parse_one_reloption()

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

Definition at line 1140 of file reloptions.c.

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

Referenced by parseRelOptions().

1142 {
1143  char *value;
1144  int value_len;
1145  bool parsed;
1146  bool nofree = false;
1147 
1148  if (option->isset && validate)
1149  ereport(ERROR,
1150  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1151  errmsg("parameter \"%s\" specified more than once",
1152  option->gen->name)));
1153 
1154  value_len = text_len - option->gen->namelen - 1;
1155  value = (char *) palloc(value_len + 1);
1156  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1157  value[value_len] = '\0';
1158 
1159  switch (option->gen->type)
1160  {
1161  case RELOPT_TYPE_BOOL:
1162  {
1163  parsed = parse_bool(value, &option->values.bool_val);
1164  if (validate && !parsed)
1165  ereport(ERROR,
1166  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1167  errmsg("invalid value for boolean option \"%s\": %s",
1168  option->gen->name, value)));
1169  }
1170  break;
1171  case RELOPT_TYPE_INT:
1172  {
1173  relopt_int *optint = (relopt_int *) option->gen;
1174 
1175  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1176  if (validate && !parsed)
1177  ereport(ERROR,
1178  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1179  errmsg("invalid value for integer option \"%s\": %s",
1180  option->gen->name, value)));
1181  if (validate && (option->values.int_val < optint->min ||
1182  option->values.int_val > optint->max))
1183  ereport(ERROR,
1184  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1185  errmsg("value %s out of bounds for option \"%s\"",
1186  value, option->gen->name),
1187  errdetail("Valid values are between \"%d\" and \"%d\".",
1188  optint->min, optint->max)));
1189  }
1190  break;
1191  case RELOPT_TYPE_REAL:
1192  {
1193  relopt_real *optreal = (relopt_real *) option->gen;
1194 
1195  parsed = parse_real(value, &option->values.real_val);
1196  if (validate && !parsed)
1197  ereport(ERROR,
1198  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1199  errmsg("invalid value for floating point option \"%s\": %s",
1200  option->gen->name, value)));
1201  if (validate && (option->values.real_val < optreal->min ||
1202  option->values.real_val > optreal->max))
1203  ereport(ERROR,
1204  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1205  errmsg("value %s out of bounds for option \"%s\"",
1206  value, option->gen->name),
1207  errdetail("Valid values are between \"%f\" and \"%f\".",
1208  optreal->min, optreal->max)));
1209  }
1210  break;
1211  case RELOPT_TYPE_STRING:
1212  {
1213  relopt_string *optstring = (relopt_string *) option->gen;
1214 
1215  option->values.string_val = value;
1216  nofree = true;
1217  if (validate && optstring->validate_cb)
1218  (optstring->validate_cb) (value);
1219  parsed = true;
1220  }
1221  break;
1222  default:
1223  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1224  parsed = true; /* quiet compiler */
1225  break;
1226  }
1227 
1228  if (parsed)
1229  option->isset = true;
1230  if (!nofree)
1231  pfree(value);
1232 }
bool bool_val
Definition: reloptions.h:81
char * string_val
Definition: reloptions.h:84
int errcode(int sqlerrcode)
Definition: elog.c:575
bool parse_bool(const char *value, bool *result)
Definition: bool.c:30
relopt_gen * gen
Definition: reloptions.h:77
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
union relopt_value::@47 values
int errdetail(const char *fmt,...)
Definition: elog.c:873
int namelen
Definition: reloptions.h:70
bool parse_real(const char *value, double *result)
Definition: guc.c:5803
double real_val
Definition: reloptions.h:83
#define ereport(elevel, rest)
Definition: elog.h:122
validate_string_relopt validate_cb
Definition: reloptions.h:119
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:5717
static struct @131 value
relopt_type type
Definition: reloptions.h:71
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
const char * name
Definition: reloptions.h:65
#define elog
Definition: elog.h:219
double max
Definition: reloptions.h:108
double min
Definition: reloptions.h:107

◆ parseRelOptions()

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

Definition at line 1048 of file reloptions.c.

References DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), ereport, errcode(), errmsg(), ERROR, relopt_value::gen, i, initialize_reloptions(), relopt_value::isset, relopt_gen::namelen, need_initialization, noptions, palloc(), parse_one_reloption(), pfree(), PointerIsValid, TextDatumGetCString, VARDATA, VARHDRSZ, and VARSIZE.

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

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

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1558 of file reloptions.c.

References allocateReloptStruct(), effective_io_concurrency, fillRelOptions(), lengthof, offsetof, options, parseRelOptions(), pfree(), random_page_cost, RELOPT_KIND_TABLESPACE, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, and seq_page_cost.

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

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

◆ transformRelOptions()

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

Definition at line 773 of file reloptions.c.

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

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

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

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 934 of file reloptions.c.

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

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

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

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1408 of file reloptions.c.

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

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

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

Variable Documentation

◆ boolRelOpts

relopt_bool boolRelOpts[]
static

Definition at line 94 of file reloptions.c.

◆ custom_options

relopt_gen** custom_options = NULL
static

Definition at line 459 of file reloptions.c.

◆ intRelOpts

relopt_int intRelOpts[]
static

Definition at line 154 of file reloptions.c.

◆ last_assigned_kind

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

Definition at line 456 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 458 of file reloptions.c.

Referenced by add_reloption(), and initialize_reloptions().

◆ realRelOpts

relopt_real realRelOpts[]
static

Definition at line 356 of file reloptions.c.

◆ relOpts

relopt_gen** relOpts = NULL
static

Definition at line 455 of file reloptions.c.

◆ stringRelOpts

relopt_string stringRelOpts[]
static
Initial value:
=
{
{
{
"buffering",
"Enables buffering build for this GiST index",
},
4,
false,
"auto"
},
{
{
"check_option",
"View has WITH CHECK OPTION defined (local or cascaded).",
},
0,
true,
NULL
},
{{NULL}}
}
void gistValidateBufferingOption(const char *value)
Definition: gistbuild.c:241
void validateWithCheckOption(const char *value)
Definition: view.c:46
#define AccessExclusiveLock
Definition: lockdefs.h:45

Definition at line 425 of file reloptions.c.