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

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

644 {
645  relopt_bool *newoption;
646 
647  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
648  name, desc);
649  newoption->default_val = default_val;
650 
651  add_reloption((relopt_gen *) newoption);
652 }
bool default_val
Definition: reloptions.h:91
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:595
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:561
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 659 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().

661 {
662  relopt_int *newoption;
663 
664  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
665  name, desc);
666  newoption->default_val = default_val;
667  newoption->min = min_val;
668  newoption->max = max_val;
669 
670  add_reloption((relopt_gen *) newoption);
671 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:595
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:561
const char * name
Definition: encode.c:521
int default_val
Definition: reloptions.h:97

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

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

680 {
681  relopt_real *newoption;
682 
683  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
684  name, desc);
685  newoption->default_val = default_val;
686  newoption->min = min_val;
687  newoption->max = max_val;
688 
689  add_reloption((relopt_gen *) newoption);
690 }
double default_val
Definition: reloptions.h:105
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:595
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:561
const char * name
Definition: encode.c:521
double max
Definition: reloptions.h:107
double min
Definition: reloptions.h:106

◆ add_reloption()

static void add_reloption ( relopt_gen newoption)
static

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

562 {
563  static int max_custom_options = 0;
564 
565  if (num_custom_options >= max_custom_options)
566  {
567  MemoryContext oldcxt;
568 
570 
571  if (max_custom_options == 0)
572  {
573  max_custom_options = 8;
574  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
575  }
576  else
577  {
578  max_custom_options *= 2;
580  max_custom_options * sizeof(relopt_gen *));
581  }
582  MemoryContextSwitchTo(oldcxt);
583  }
584  custom_options[num_custom_options++] = newoption;
585 
586  need_initialization = true;
587 }
static relopt_gen ** custom_options
Definition: reloptions.c:441
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:440
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:962
void * palloc(Size size)
Definition: mcxt.c:848
static bool need_initialization
Definition: reloptions.c:442

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 544 of file reloptions.c.

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

Referenced by _PG_init().

545 {
546  /* don't hand out the last bit so that the enum's behavior is portable */
548  ereport(ERROR,
549  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
550  errmsg("user-defined relation parameter types limit exceeded")));
551  last_assigned_kind <<= 1;
553 }
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:438

◆ 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 702 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.

704 {
705  relopt_string *newoption;
706 
707  /* make sure the validator/default combination is sane */
708  if (validator)
709  (validator) (default_val);
710 
711  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
712  name, desc);
713  newoption->validate_cb = validator;
714  if (default_val)
715  {
717  default_val);
718  newoption->default_len = strlen(default_val);
719  newoption->default_isnull = false;
720  }
721  else
722  {
723  newoption->default_val = "";
724  newoption->default_len = 0;
725  newoption->default_isnull = true;
726  }
727 
728  add_reloption((relopt_gen *) newoption);
729 }
bool default_isnull
Definition: reloptions.h:117
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:595
validate_string_relopt validate_cb
Definition: reloptions.h:118
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:561
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1063
char * default_val
Definition: reloptions.h:119

◆ allocate_reloption()

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

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

596 {
597  MemoryContext oldcxt;
598  size_t size;
599  relopt_gen *newoption;
600 
602 
603  switch (type)
604  {
605  case RELOPT_TYPE_BOOL:
606  size = sizeof(relopt_bool);
607  break;
608  case RELOPT_TYPE_INT:
609  size = sizeof(relopt_int);
610  break;
611  case RELOPT_TYPE_REAL:
612  size = sizeof(relopt_real);
613  break;
614  case RELOPT_TYPE_STRING:
615  size = sizeof(relopt_string);
616  break;
617  default:
618  elog(ERROR, "unsupported reloption type %d", type);
619  return NULL; /* keep compiler quiet */
620  }
621 
622  newoption = palloc(size);
623 
624  newoption->name = pstrdup(name);
625  if (desc)
626  newoption->desc = pstrdup(desc);
627  else
628  newoption->desc = NULL;
629  newoption->kinds = kinds;
630  newoption->namelen = strlen(name);
631  newoption->type = type;
632 
633  MemoryContextSwitchTo(oldcxt);
634 
635  return newoption;
636 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:66
char * pstrdup(const char *in)
Definition: mcxt.c:1076
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:69
MemoryContext TopMemoryContext
Definition: mcxt.c:43
bits32 kinds
Definition: reloptions.h:67
relopt_type type
Definition: reloptions.h:70
struct relopt_int relopt_int
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:848
const char * name
Definition: reloptions.h:64
#define elog
Definition: elog.h:219

◆ allocateReloptStruct()

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

Definition at line 1225 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(), tablespace_reloptions(), and view_reloptions().

1226 {
1227  Size size = base;
1228  int i;
1229 
1230  for (i = 0; i < numoptions; i++)
1231  if (options[i].gen->type == RELOPT_TYPE_STRING)
1232  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1233 
1234  return palloc0(size);
1235 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:234
void * palloc0(Size size)
Definition: mcxt.c:877
size_t Size
Definition: c.h:404
int i

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 1540 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

1541 {
1542  LOCKMODE lockmode = NoLock;
1543  ListCell *cell;
1544 
1545  if (defList == NIL)
1546  return AccessExclusiveLock;
1547 
1548  if (need_initialization)
1550 
1551  foreach(cell, defList)
1552  {
1553  DefElem *def = (DefElem *) lfirst(cell);
1554  int i;
1555 
1556  for (i = 0; relOpts[i]; i++)
1557  {
1558  if (pg_strncasecmp(relOpts[i]->name,
1559  def->defname,
1560  relOpts[i]->namelen + 1) == 0)
1561  {
1562  if (lockmode < relOpts[i]->lockmode)
1563  lockmode = relOpts[i]->lockmode;
1564  }
1565  }
1566  }
1567 
1568  return lockmode;
1569 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:455
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:68
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h:69
#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:442
char * defname
Definition: parsenodes.h:719
static relopt_gen ** relOpts
Definition: reloptions.c:437

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

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

1475 {
1477  AttributeOpts *aopts;
1478  int numoptions;
1479  static const relopt_parse_elt tab[] = {
1480  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1481  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1482  };
1483 
1484  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1485  &numoptions);
1486 
1487  /* if none set, we're done */
1488  if (numoptions == 0)
1489  return NULL;
1490 
1491  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1492 
1493  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1494  validate, tab, lengthof(tab));
1495 
1496  pfree(options);
1497 
1498  return (bytea *) aopts;
1499 }
#define lengthof(array)
Definition: c.h:600
void pfree(void *pointer)
Definition: mcxt.c:949
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1225
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:1249
Definition: c.h:487
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1030
#define offsetof(type, field)
Definition: c.h:593

◆ default_reloptions()

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

Definition at line 1326 of file reloptions.c.

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

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

1327 {
1329  StdRdOptions *rdopts;
1330  int numoptions;
1331  static const relopt_parse_elt tab[] = {
1332  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1333  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1334  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1335  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1336  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1337  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1338  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1339  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1340  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1341  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1342  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1343  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1344  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1345  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1346  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1347  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1348  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1349  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1350  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1351  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1352  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1353  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1354  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1355  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1356  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1357  {"toast_tuple_target", RELOPT_TYPE_INT,
1358  offsetof(StdRdOptions, toast_tuple_target)},
1359  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1360  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1361  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1362  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1363  {"user_catalog_table", RELOPT_TYPE_BOOL,
1364  offsetof(StdRdOptions, user_catalog_table)},
1365  {"parallel_workers", RELOPT_TYPE_INT,
1366  offsetof(StdRdOptions, parallel_workers)}
1367  };
1368 
1369  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1370 
1371  /* if none set, we're done */
1372  if (numoptions == 0)
1373  return NULL;
1374 
1375  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1376 
1377  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1378  validate, tab, lengthof(tab));
1379 
1380  pfree(options);
1381 
1382  return (bytea *) rdopts;
1383 }
#define lengthof(array)
Definition: c.h:600
void pfree(void *pointer)
Definition: mcxt.c:949
int fillfactor
Definition: pgbench.c:114
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1225
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:1249
Definition: c.h:487
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1030
#define offsetof(type, field)
Definition: c.h:593

◆ extractRelOptions()

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

Definition at line 966 of file reloptions.c.

References Anum_pg_class_reloptions, Assert, fastgetattr, GETSTRUCT, heap_reloptions(), index_reloptions(), options, RELKIND_FOREIGN_TABLE, RELKIND_INDEX, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_TOASTVALUE, RELKIND_VIEW, and view_reloptions().

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

968 {
969  bytea *options;
970  bool isnull;
971  Datum datum;
972  Form_pg_class classForm;
973 
974  datum = fastgetattr(tuple,
976  tupdesc,
977  &isnull);
978  if (isnull)
979  return NULL;
980 
981  classForm = (Form_pg_class) GETSTRUCT(tuple);
982 
983  /* Parse into appropriate format; don't error out here */
984  switch (classForm->relkind)
985  {
986  case RELKIND_RELATION:
987  case RELKIND_TOASTVALUE:
988  case RELKIND_MATVIEW:
990  options = heap_reloptions(classForm->relkind, datum, false);
991  break;
992  case RELKIND_VIEW:
993  options = view_reloptions(datum, false);
994  break;
995  case RELKIND_INDEX:
996  options = index_reloptions(amoptions, datum, false);
997  break;
999  options = NULL;
1000  break;
1001  default:
1002  Assert(false); /* can't get here */
1003  options = NULL; /* keep compiler quiet */
1004  break;
1005  }
1006 
1007  return options;
1008 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1421
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:724
#define Anum_pg_class_reloptions
Definition: pg_class.h:134
#define RELKIND_MATVIEW
Definition: pg_class.h:165
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1389
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
static char ** options
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
uintptr_t Datum
Definition: postgres.h:372
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1459
#define Assert(condition)
Definition: c.h:670
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RELKIND_INDEX
Definition: pg_class.h:161
Definition: c.h:487
#define RELKIND_RELATION
Definition: pg_class.h:160

◆ fillRelOptions()

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

Definition at line 1249 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, pg_strcasecmp(), 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(), tablespace_reloptions(), and view_reloptions().

1253 {
1254  int i;
1255  int offset = basesize;
1256 
1257  for (i = 0; i < numoptions; i++)
1258  {
1259  int j;
1260  bool found = false;
1261 
1262  for (j = 0; j < numelems; j++)
1263  {
1264  if (pg_strcasecmp(options[i].gen->name, elems[j].optname) == 0)
1265  {
1266  relopt_string *optstring;
1267  char *itempos = ((char *) rdopts) + elems[j].offset;
1268  char *string_val;
1269 
1270  switch (options[i].gen->type)
1271  {
1272  case RELOPT_TYPE_BOOL:
1273  *(bool *) itempos = options[i].isset ?
1274  options[i].values.bool_val :
1275  ((relopt_bool *) options[i].gen)->default_val;
1276  break;
1277  case RELOPT_TYPE_INT:
1278  *(int *) itempos = options[i].isset ?
1279  options[i].values.int_val :
1280  ((relopt_int *) options[i].gen)->default_val;
1281  break;
1282  case RELOPT_TYPE_REAL:
1283  *(double *) itempos = options[i].isset ?
1284  options[i].values.real_val :
1285  ((relopt_real *) options[i].gen)->default_val;
1286  break;
1287  case RELOPT_TYPE_STRING:
1288  optstring = (relopt_string *) options[i].gen;
1289  if (options[i].isset)
1290  string_val = options[i].values.string_val;
1291  else if (!optstring->default_isnull)
1292  string_val = optstring->default_val;
1293  else
1294  string_val = NULL;
1295 
1296  if (string_val == NULL)
1297  *(int *) itempos = 0;
1298  else
1299  {
1300  strcpy((char *) rdopts + offset, string_val);
1301  *(int *) itempos = offset;
1302  offset += strlen(string_val) + 1;
1303  }
1304  break;
1305  default:
1306  elog(ERROR, "unsupported reloption type %d",
1307  options[i].gen->type);
1308  break;
1309  }
1310  found = true;
1311  break;
1312  }
1313  }
1314  if (validate && !found)
1315  elog(ERROR, "reloption \"%s\" not found in parse table",
1316  options[i].gen->name);
1317  }
1318  SET_VARSIZE(rdopts, offset);
1319 }
char * string_val
Definition: reloptions.h:83
bool default_isnull
Definition: reloptions.h:117
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
relopt_gen * gen
Definition: reloptions.h:76
#define ERROR
Definition: elog.h:43
union relopt_value::@47 values
const char * optname
Definition: reloptions.h:125
static Datum values[MAXATTR]
Definition: bootstrap.c:164
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define elog
Definition: elog.h:219
char * default_val
Definition: reloptions.h:119

◆ heap_reloptions()

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

Definition at line 1421 of file reloptions.c.

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

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

1422 {
1423  StdRdOptions *rdopts;
1424 
1425  switch (relkind)
1426  {
1427  case RELKIND_TOASTVALUE:
1428  rdopts = (StdRdOptions *)
1429  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1430  if (rdopts != NULL)
1431  {
1432  /* adjust default-only parameters for TOAST relations */
1433  rdopts->fillfactor = 100;
1434  rdopts->autovacuum.analyze_threshold = -1;
1435  rdopts->autovacuum.analyze_scale_factor = -1;
1436  }
1437  return (bytea *) rdopts;
1438  case RELKIND_RELATION:
1439  case RELKIND_MATVIEW:
1440  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1442  return default_reloptions(reloptions, validate,
1444  default:
1445  /* other relkinds are not supported */
1446  return NULL;
1447  }
1448 }
#define RELKIND_MATVIEW
Definition: pg_class.h:165
int fillfactor
Definition: rel.h:279
int analyze_threshold
Definition: rel.h:262
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
float8 analyze_scale_factor
Definition: rel.h:273
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1326
Definition: c.h:487
#define RELKIND_RELATION
Definition: pg_class.h:160
AutoVacOpts autovacuum
Definition: rel.h:281

◆ index_reloptions()

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

Definition at line 1459 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

1460 {
1461  Assert(amoptions != NULL);
1462 
1463  /* Assume function is strict */
1464  if (!PointerIsValid(DatumGetPointer(reloptions)))
1465  return NULL;
1466 
1467  return amoptions(reloptions, validate);
1468 }
#define Assert(condition)
Definition: c.h:670
#define DatumGetPointer(X)
Definition: postgres.h:555
#define PointerIsValid(pointer)
Definition: c.h:564

◆ initialize_reloptions()

static void initialize_reloptions ( void  )
static

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

456 {
457  int i;
458  int j;
459 
460  j = 0;
461  for (i = 0; boolRelOpts[i].gen.name; i++)
462  {
463  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
464  boolRelOpts[i].gen.lockmode));
465  j++;
466  }
467  for (i = 0; intRelOpts[i].gen.name; i++)
468  {
469  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
470  intRelOpts[i].gen.lockmode));
471  j++;
472  }
473  for (i = 0; realRelOpts[i].gen.name; i++)
474  {
475  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
476  realRelOpts[i].gen.lockmode));
477  j++;
478  }
479  for (i = 0; stringRelOpts[i].gen.name; i++)
480  {
481  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
483  j++;
484  }
485  j += num_custom_options;
486 
487  if (relOpts)
488  pfree(relOpts);
490  (j + 1) * sizeof(relopt_gen *));
491 
492  j = 0;
493  for (i = 0; boolRelOpts[i].gen.name; i++)
494  {
495  relOpts[j] = &boolRelOpts[i].gen;
497  relOpts[j]->namelen = strlen(relOpts[j]->name);
498  j++;
499  }
500 
501  for (i = 0; intRelOpts[i].gen.name; i++)
502  {
503  relOpts[j] = &intRelOpts[i].gen;
505  relOpts[j]->namelen = strlen(relOpts[j]->name);
506  j++;
507  }
508 
509  for (i = 0; realRelOpts[i].gen.name; i++)
510  {
511  relOpts[j] = &realRelOpts[i].gen;
513  relOpts[j]->namelen = strlen(relOpts[j]->name);
514  j++;
515  }
516 
517  for (i = 0; stringRelOpts[i].gen.name; i++)
518  {
519  relOpts[j] = &stringRelOpts[i].gen;
521  relOpts[j]->namelen = strlen(relOpts[j]->name);
522  j++;
523  }
524 
525  for (i = 0; i < num_custom_options; i++)
526  {
527  relOpts[j] = custom_options[i];
528  j++;
529  }
530 
531  /* add a list terminator */
532  relOpts[j] = NULL;
533 
534  /* flag the work is complete */
535  need_initialization = false;
536 }
static relopt_gen ** custom_options
Definition: reloptions.c:441
LOCKMODE lockmode
Definition: reloptions.h:68
static relopt_bool boolRelOpts[]
Definition: reloptions.c:94
relopt_gen gen
Definition: reloptions.h:115
void pfree(void *pointer)
Definition: mcxt.c:949
static int num_custom_options
Definition: reloptions.c:440
relopt_gen gen
Definition: reloptions.h:90
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:347
int namelen
Definition: reloptions.h:69
MemoryContext TopMemoryContext
Definition: mcxt.c:43
relopt_gen gen
Definition: reloptions.h:96
#define Assert(condition)
Definition: c.h:670
relopt_type type
Definition: reloptions.h:70
relopt_gen gen
Definition: reloptions.h:104
const char * name
Definition: encode.c:521
static relopt_string stringRelOpts[]
Definition: reloptions.c:407
const char * name
Definition: reloptions.h:64
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:706
int i
static bool need_initialization
Definition: reloptions.c:442
static relopt_int intRelOpts[]
Definition: reloptions.c:145
static relopt_gen ** relOpts
Definition: reloptions.c:437

◆ parse_one_reloption()

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

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

1125 {
1126  char *value;
1127  int value_len;
1128  bool parsed;
1129  bool nofree = false;
1130 
1131  if (option->isset && validate)
1132  ereport(ERROR,
1133  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1134  errmsg("parameter \"%s\" specified more than once",
1135  option->gen->name)));
1136 
1137  value_len = text_len - option->gen->namelen - 1;
1138  value = (char *) palloc(value_len + 1);
1139  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1140  value[value_len] = '\0';
1141 
1142  switch (option->gen->type)
1143  {
1144  case RELOPT_TYPE_BOOL:
1145  {
1146  parsed = parse_bool(value, &option->values.bool_val);
1147  if (validate && !parsed)
1148  ereport(ERROR,
1149  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1150  errmsg("invalid value for boolean option \"%s\": %s",
1151  option->gen->name, value)));
1152  }
1153  break;
1154  case RELOPT_TYPE_INT:
1155  {
1156  relopt_int *optint = (relopt_int *) option->gen;
1157 
1158  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1159  if (validate && !parsed)
1160  ereport(ERROR,
1161  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1162  errmsg("invalid value for integer option \"%s\": %s",
1163  option->gen->name, value)));
1164  if (validate && (option->values.int_val < optint->min ||
1165  option->values.int_val > optint->max))
1166  ereport(ERROR,
1167  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1168  errmsg("value %s out of bounds for option \"%s\"",
1169  value, option->gen->name),
1170  errdetail("Valid values are between \"%d\" and \"%d\".",
1171  optint->min, optint->max)));
1172  }
1173  break;
1174  case RELOPT_TYPE_REAL:
1175  {
1176  relopt_real *optreal = (relopt_real *) option->gen;
1177 
1178  parsed = parse_real(value, &option->values.real_val);
1179  if (validate && !parsed)
1180  ereport(ERROR,
1181  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1182  errmsg("invalid value for floating point option \"%s\": %s",
1183  option->gen->name, value)));
1184  if (validate && (option->values.real_val < optreal->min ||
1185  option->values.real_val > optreal->max))
1186  ereport(ERROR,
1187  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1188  errmsg("value %s out of bounds for option \"%s\"",
1189  value, option->gen->name),
1190  errdetail("Valid values are between \"%f\" and \"%f\".",
1191  optreal->min, optreal->max)));
1192  }
1193  break;
1194  case RELOPT_TYPE_STRING:
1195  {
1196  relopt_string *optstring = (relopt_string *) option->gen;
1197 
1198  option->values.string_val = value;
1199  nofree = true;
1200  if (validate && optstring->validate_cb)
1201  (optstring->validate_cb) (value);
1202  parsed = true;
1203  }
1204  break;
1205  default:
1206  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1207  parsed = true; /* quiet compiler */
1208  break;
1209  }
1210 
1211  if (parsed)
1212  option->isset = true;
1213  if (!nofree)
1214  pfree(value);
1215 }
bool bool_val
Definition: reloptions.h:80
char * string_val
Definition: reloptions.h:83
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:76
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
static struct @121 value
union relopt_value::@47 values
int errdetail(const char *fmt,...)
Definition: elog.c:873
int namelen
Definition: reloptions.h:69
bool parse_real(const char *value, double *result)
Definition: guc.c:5602
double real_val
Definition: reloptions.h:82
#define ereport(elevel, rest)
Definition: elog.h:122
validate_string_relopt validate_cb
Definition: reloptions.h:118
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:5516
relopt_type type
Definition: reloptions.h:70
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
const char * name
Definition: reloptions.h:64
#define elog
Definition: elog.h:219
double max
Definition: reloptions.h:107
double min
Definition: reloptions.h:106

◆ parseRelOptions()

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

Definition at line 1030 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(), pg_strncasecmp(), PointerIsValid, TextDatumGetCString, TEXTOID, VARDATA, VARHDRSZ, and VARSIZE.

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

1032 {
1033  relopt_value *reloptions = NULL;
1034  int numoptions = 0;
1035  int i;
1036  int j;
1037 
1038  if (need_initialization)
1040 
1041  /* Build a list of expected options, based on kind */
1042 
1043  for (i = 0; relOpts[i]; i++)
1044  if (relOpts[i]->kinds & kind)
1045  numoptions++;
1046 
1047  if (numoptions > 0)
1048  {
1049  reloptions = palloc(numoptions * sizeof(relopt_value));
1050 
1051  for (i = 0, j = 0; relOpts[i]; i++)
1052  {
1053  if (relOpts[i]->kinds & kind)
1054  {
1055  reloptions[j].gen = relOpts[i];
1056  reloptions[j].isset = false;
1057  j++;
1058  }
1059  }
1060  }
1061 
1062  /* Done if no options */
1064  {
1066  Datum *optiondatums;
1067  int noptions;
1068 
1069  deconstruct_array(array, TEXTOID, -1, false, 'i',
1070  &optiondatums, NULL, &noptions);
1071 
1072  for (i = 0; i < noptions; i++)
1073  {
1074  char *text_str = VARDATA(optiondatums[i]);
1075  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1076  int j;
1077 
1078  /* Search for a match in reloptions */
1079  for (j = 0; j < numoptions; j++)
1080  {
1081  int kw_len = reloptions[j].gen->namelen;
1082 
1083  if (text_len > kw_len && text_str[kw_len] == '=' &&
1084  pg_strncasecmp(text_str, reloptions[j].gen->name,
1085  kw_len) == 0)
1086  {
1087  parse_one_reloption(&reloptions[j], text_str, text_len,
1088  validate);
1089  break;
1090  }
1091  }
1092 
1093  if (j >= numoptions && validate)
1094  {
1095  char *s;
1096  char *p;
1097 
1098  s = TextDatumGetCString(optiondatums[i]);
1099  p = strchr(s, '=');
1100  if (p)
1101  *p = '\0';
1102  ereport(ERROR,
1103  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1104  errmsg("unrecognized parameter \"%s\"", s)));
1105  }
1106  }
1107 
1108  /* It's worth avoiding memory leaks in this function */
1109  pfree(optiondatums);
1110  if (((void *) array) != DatumGetPointer(options))
1111  pfree(array);
1112  }
1113 
1114  *numrelopts = numoptions;
1115  return reloptions;
1116 }
static void initialize_reloptions(void)
Definition: reloptions.c:455
#define VARDATA(PTR)
Definition: postgres.h:303
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define VARHDRSZ
Definition: c.h:493
int errcode(int sqlerrcode)
Definition: elog.c:575
relopt_gen * gen
Definition: reloptions.h:76
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
void pfree(void *pointer)
Definition: mcxt.c:949
#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:1123
int namelen
Definition: reloptions.h:69
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define DatumGetPointer(X)
Definition: postgres.h:555
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:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static bool need_initialization
Definition: reloptions.c:442
static relopt_gen ** relOpts
Definition: reloptions.c:437
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:564
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

1506 {
1508  TableSpaceOpts *tsopts;
1509  int numoptions;
1510  static const relopt_parse_elt tab[] = {
1511  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1512  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1513  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1514  };
1515 
1516  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1517  &numoptions);
1518 
1519  /* if none set, we're done */
1520  if (numoptions == 0)
1521  return NULL;
1522 
1523  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1524 
1525  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1526  validate, tab, lengthof(tab));
1527 
1528  pfree(options);
1529 
1530  return (bytea *) tsopts;
1531 }
#define lengthof(array)
Definition: c.h:600
int effective_io_concurrency
Definition: bufmgr.c:112
double random_page_cost
Definition: costsize.c:105
void pfree(void *pointer)
Definition: mcxt.c:949
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1225
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:1249
Definition: c.h:487
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1030
double seq_page_cost
Definition: costsize.c:104
#define offsetof(type, field)
Definition: c.h:593

◆ transformRelOptions()

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

Definition at line 755 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(), pg_strcasecmp(), pg_strncasecmp(), PointerGetDatum, PointerIsValid, SET_VARSIZE, TEXTOID, value, VARDATA, VARHDRSZ, and VARSIZE.

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

757 {
758  Datum result;
759  ArrayBuildState *astate;
760  ListCell *cell;
761 
762  /* no change if empty list */
763  if (defList == NIL)
764  return oldOptions;
765 
766  /* We build new array using accumArrayResult */
767  astate = NULL;
768 
769  /* Copy any oldOptions that aren't to be replaced */
770  if (PointerIsValid(DatumGetPointer(oldOptions)))
771  {
772  ArrayType *array = DatumGetArrayTypeP(oldOptions);
773  Datum *oldoptions;
774  int noldoptions;
775  int i;
776 
777  deconstruct_array(array, TEXTOID, -1, false, 'i',
778  &oldoptions, NULL, &noldoptions);
779 
780  for (i = 0; i < noldoptions; i++)
781  {
782  char *text_str = VARDATA(oldoptions[i]);
783  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
784 
785  /* Search for a match in defList */
786  foreach(cell, defList)
787  {
788  DefElem *def = (DefElem *) lfirst(cell);
789  int kw_len;
790 
791  /* ignore if not in the same namespace */
792  if (namspace == NULL)
793  {
794  if (def->defnamespace != NULL)
795  continue;
796  }
797  else if (def->defnamespace == NULL)
798  continue;
799  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
800  continue;
801 
802  kw_len = strlen(def->defname);
803  if (text_len > kw_len && text_str[kw_len] == '=' &&
804  pg_strncasecmp(text_str, def->defname, kw_len) == 0)
805  break;
806  }
807  if (!cell)
808  {
809  /* No match, so keep old option */
810  astate = accumArrayResult(astate, oldoptions[i],
811  false, TEXTOID,
813  }
814  }
815  }
816 
817  /*
818  * If CREATE/SET, add new options to array; if RESET, just check that the
819  * user didn't say RESET (option=val). (Must do this because the grammar
820  * doesn't enforce it.)
821  */
822  foreach(cell, defList)
823  {
824  DefElem *def = (DefElem *) lfirst(cell);
825 
826  if (isReset)
827  {
828  if (def->arg != NULL)
829  ereport(ERROR,
830  (errcode(ERRCODE_SYNTAX_ERROR),
831  errmsg("RESET must not include values for parameters")));
832  }
833  else
834  {
835  text *t;
836  const char *value;
837  Size len;
838 
839  /*
840  * Error out if the namespace is not valid. A NULL namespace is
841  * always valid.
842  */
843  if (def->defnamespace != NULL)
844  {
845  bool valid = false;
846  int i;
847 
848  if (validnsps)
849  {
850  for (i = 0; validnsps[i]; i++)
851  {
852  if (pg_strcasecmp(def->defnamespace,
853  validnsps[i]) == 0)
854  {
855  valid = true;
856  break;
857  }
858  }
859  }
860 
861  if (!valid)
862  ereport(ERROR,
863  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
864  errmsg("unrecognized parameter namespace \"%s\"",
865  def->defnamespace)));
866  }
867 
868  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
869  continue;
870 
871  /* ignore if not in the same namespace */
872  if (namspace == NULL)
873  {
874  if (def->defnamespace != NULL)
875  continue;
876  }
877  else if (def->defnamespace == NULL)
878  continue;
879  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
880  continue;
881 
882  /*
883  * Flatten the DefElem into a text string like "name=arg". If we
884  * have just "name", assume "name=true" is meant. Note: the
885  * namespace is not output.
886  */
887  if (def->arg != NULL)
888  value = defGetString(def);
889  else
890  value = "true";
891  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
892  /* +1 leaves room for sprintf's trailing null */
893  t = (text *) palloc(len + 1);
894  SET_VARSIZE(t, len);
895  sprintf(VARDATA(t), "%s=%s", def->defname, value);
896 
897  astate = accumArrayResult(astate, PointerGetDatum(t),
898  false, TEXTOID,
900  }
901  }
902 
903  if (astate)
904  result = makeArrayResult(astate, CurrentMemoryContext);
905  else
906  result = (Datum) 0;
907 
908  return result;
909 }
#define NIL
Definition: pg_list.h:69
#define VARDATA(PTR)
Definition: postgres.h:303
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define PointerGetDatum(X)
Definition: postgres.h:562
#define VARHDRSZ
Definition: c.h:493
char * defnamespace
Definition: parsenodes.h:718
int errcode(int sqlerrcode)
Definition: elog.c:575
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
static struct @121 value
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define ereport(elevel, rest)
Definition: elog.h:122
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5106
Node * arg
Definition: parsenodes.h:720
uintptr_t Datum
Definition: postgres.h:372
#define lfirst(lc)
Definition: pg_list.h:106
size_t Size
Definition: c.h:404
#define DatumGetPointer(X)
Definition: postgres.h:555
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:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: c.h:487
char * defname
Definition: parsenodes.h:719
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define PointerIsValid(pointer)
Definition: c.h:564
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 917 of file reloptions.c.

References DatumGetArrayTypeP, DatumGetPointer, deconstruct_array(), i, lappend(), makeDefElem(), makeString(), NIL, noptions, PointerIsValid, pstrdup(), TextDatumGetCString, TEXTOID, 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().

918 {
919  List *result = NIL;
920  ArrayType *array;
921  Datum *optiondatums;
922  int noptions;
923  int i;
924 
925  /* Nothing to do if no options */
927  return result;
928 
929  array = DatumGetArrayTypeP(options);
930 
931  deconstruct_array(array, TEXTOID, -1, false, 'i',
932  &optiondatums, NULL, &noptions);
933 
934  for (i = 0; i < noptions; i++)
935  {
936  char *s;
937  char *p;
938  Node *val = NULL;
939 
940  s = TextDatumGetCString(optiondatums[i]);
941  p = strchr(s, '=');
942  if (p)
943  {
944  *p++ = '\0';
945  val = (Node *) makeString(pstrdup(p));
946  }
947  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
948  }
949 
950  return result;
951 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:69
#define TEXTOID
Definition: pg_type.h:324
char * pstrdup(const char *in)
Definition: mcxt.c:1076
Definition: nodes.h:510
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:92
uintptr_t Datum
Definition: postgres.h:372
#define DatumGetPointer(X)
Definition: postgres.h:555
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:564
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 1389 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().

1390 {
1392  ViewOptions *vopts;
1393  int numoptions;
1394  static const relopt_parse_elt tab[] = {
1395  {"security_barrier", RELOPT_TYPE_BOOL,
1396  offsetof(ViewOptions, security_barrier)},
1397  {"check_option", RELOPT_TYPE_STRING,
1398  offsetof(ViewOptions, check_option_offset)}
1399  };
1400 
1401  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1402 
1403  /* if none set, we're done */
1404  if (numoptions == 0)
1405  return NULL;
1406 
1407  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1408 
1409  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1410  validate, tab, lengthof(tab));
1411 
1412  pfree(options);
1413 
1414  return (bytea *) vopts;
1415 }
#define lengthof(array)
Definition: c.h:600
void pfree(void *pointer)
Definition: mcxt.c:949
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1225
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:1249
Definition: c.h:487
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1030
#define offsetof(type, field)
Definition: c.h:593

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

◆ intRelOpts

relopt_int intRelOpts[]
static

Definition at line 145 of file reloptions.c.

◆ last_assigned_kind

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

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

Referenced by add_reloption(), and initialize_reloptions().

◆ realRelOpts

relopt_real realRelOpts[]
static

Definition at line 347 of file reloptions.c.

◆ relOpts

relopt_gen** relOpts = NULL
static

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