PostgreSQL Source Code  git master
reloptions.c File Reference
#include "postgres.h"
#include <float.h>
#include "access/gist_private.h"
#include "access/hash.h"
#include "access/heaptoast.h"
#include "access/htup_details.h"
#include "access/nbtree.h"
#include "access/reloptions.h"
#include "access/spgist.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 acceptOidsOff, 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 672 of file reloptions.c.

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

673 {
674  relopt_bool *newoption;
675 
676  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
677  name, desc);
678  newoption->default_val = default_val;
679 
680  add_reloption((relopt_gen *) newoption);
681 }
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:624
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:590
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 688 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().

690 {
691  relopt_int *newoption;
692 
693  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
694  name, desc);
695  newoption->default_val = default_val;
696  newoption->min = min_val;
697  newoption->max = max_val;
698 
699  add_reloption((relopt_gen *) newoption);
700 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
Definition: reloptions.c:624
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:590
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 707 of file reloptions.c.

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

709 {
710  relopt_real *newoption;
711 
712  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
713  name, desc);
714  newoption->default_val = default_val;
715  newoption->min = min_val;
716  newoption->max = max_val;
717 
718  add_reloption((relopt_gen *) newoption);
719 }
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:624
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:590
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 590 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().

591 {
592  static int max_custom_options = 0;
593 
594  if (num_custom_options >= max_custom_options)
595  {
596  MemoryContext oldcxt;
597 
599 
600  if (max_custom_options == 0)
601  {
602  max_custom_options = 8;
603  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
604  }
605  else
606  {
607  max_custom_options *= 2;
609  max_custom_options * sizeof(relopt_gen *));
610  }
611  MemoryContextSwitchTo(oldcxt);
612  }
613  custom_options[num_custom_options++] = newoption;
614 
615  need_initialization = true;
616 }
static relopt_gen ** custom_options
Definition: reloptions.c:470
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:469
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:471

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 573 of file reloptions.c.

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

Referenced by _PG_init().

574 {
575  /* don't hand out the last bit so that the enum's behavior is portable */
577  ereport(ERROR,
578  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
579  errmsg("user-defined relation parameter types limit exceeded")));
580  last_assigned_kind <<= 1;
582 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
relopt_kind
Definition: reloptions.h:38
static bits32 last_assigned_kind
Definition: reloptions.c:467

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

733 {
734  relopt_string *newoption;
735 
736  /* make sure the validator/default combination is sane */
737  if (validator)
738  (validator) (default_val);
739 
740  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
741  name, desc);
742  newoption->validate_cb = validator;
743  if (default_val)
744  {
746  default_val);
747  newoption->default_len = strlen(default_val);
748  newoption->default_isnull = false;
749  }
750  else
751  {
752  newoption->default_val = "";
753  newoption->default_len = 0;
754  newoption->default_isnull = true;
755  }
756 
757  add_reloption((relopt_gen *) newoption);
758 }
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:624
validate_string_relopt validate_cb
Definition: reloptions.h:118
MemoryContext TopMemoryContext
Definition: mcxt.c:44
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:590
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1148
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 624 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().

625 {
626  MemoryContext oldcxt;
627  size_t size;
628  relopt_gen *newoption;
629 
631 
632  switch (type)
633  {
634  case RELOPT_TYPE_BOOL:
635  size = sizeof(relopt_bool);
636  break;
637  case RELOPT_TYPE_INT:
638  size = sizeof(relopt_int);
639  break;
640  case RELOPT_TYPE_REAL:
641  size = sizeof(relopt_real);
642  break;
643  case RELOPT_TYPE_STRING:
644  size = sizeof(relopt_string);
645  break;
646  default:
647  elog(ERROR, "unsupported reloption type %d", type);
648  return NULL; /* keep compiler quiet */
649  }
650 
651  newoption = palloc(size);
652 
653  newoption->name = pstrdup(name);
654  if (desc)
655  newoption->desc = pstrdup(desc);
656  else
657  newoption->desc = NULL;
658  newoption->kinds = kinds;
659  newoption->namelen = strlen(name);
660  newoption->type = type;
661 
662  MemoryContextSwitchTo(oldcxt);
663 
664  return newoption;
665 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:66
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:69
MemoryContext TopMemoryContext
Definition: mcxt.c:44
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:924
const char * name
Definition: reloptions.h:64
#define elog(elevel,...)
Definition: elog.h:226

◆ allocateReloptStruct()

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

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

1269 {
1270  Size size = base;
1271  int i;
1272 
1273  for (i = 0; i < numoptions; i++)
1274  if (options[i].gen->type == RELOPT_TYPE_STRING)
1275  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1276 
1277  return palloc0(size);
1278 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:234
void * palloc0(Size size)
Definition: mcxt.c:955
size_t Size
Definition: c.h:466
int i

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

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

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

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

1524 {
1526  AttributeOpts *aopts;
1527  int numoptions;
1528  static const relopt_parse_elt tab[] = {
1529  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1530  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1531  };
1532 
1533  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1534  &numoptions);
1535 
1536  /* if none set, we're done */
1537  if (numoptions == 0)
1538  return NULL;
1539 
1540  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1541 
1542  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1543  validate, tab, lengthof(tab));
1544 
1545  pfree(options);
1546 
1547  return (bytea *) aopts;
1548 }
#define lengthof(array)
Definition: c.h:662
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1268
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:1292
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1074
#define offsetof(type, field)
Definition: c.h:655

◆ default_reloptions()

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

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

1370 {
1372  StdRdOptions *rdopts;
1373  int numoptions;
1374  static const relopt_parse_elt tab[] = {
1375  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1376  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1377  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1378  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1379  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1380  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1381  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1382  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1383  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1384  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1385  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1386  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1387  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1388  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1389  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1390  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1391  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1392  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1393  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1394  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1395  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1396  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1397  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1398  {"toast_tuple_target", RELOPT_TYPE_INT,
1399  offsetof(StdRdOptions, toast_tuple_target)},
1400  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1401  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1402  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1403  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1404  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1405  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1406  {"user_catalog_table", RELOPT_TYPE_BOOL,
1407  offsetof(StdRdOptions, user_catalog_table)},
1408  {"parallel_workers", RELOPT_TYPE_INT,
1409  offsetof(StdRdOptions, parallel_workers)},
1410  {"vacuum_cleanup_index_scale_factor", RELOPT_TYPE_REAL,
1412  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1413  offsetof(StdRdOptions, vacuum_index_cleanup)},
1414  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1415  offsetof(StdRdOptions, vacuum_truncate)}
1416  };
1417 
1418  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1419 
1420  /* if none set, we're done */
1421  if (numoptions == 0)
1422  return NULL;
1423 
1424  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1425 
1426  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1427  validate, tab, lengthof(tab));
1428 
1429  pfree(options);
1430 
1431  return (bytea *) rdopts;
1432 }
double vacuum_cleanup_index_scale_factor
Definition: globals.c:150
#define lengthof(array)
Definition: c.h:662
void pfree(void *pointer)
Definition: mcxt.c:1031
int fillfactor
Definition: pgbench.c:157
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1268
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:1292
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1074
#define offsetof(type, field)
Definition: c.h:655

◆ extractRelOptions()

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

Definition at line 1009 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

1011 {
1012  bytea *options;
1013  bool isnull;
1014  Datum datum;
1015  Form_pg_class classForm;
1016 
1017  datum = fastgetattr(tuple,
1018  Anum_pg_class_reloptions,
1019  tupdesc,
1020  &isnull);
1021  if (isnull)
1022  return NULL;
1023 
1024  classForm = (Form_pg_class) GETSTRUCT(tuple);
1025 
1026  /* Parse into appropriate format; don't error out here */
1027  switch (classForm->relkind)
1028  {
1029  case RELKIND_RELATION:
1030  case RELKIND_TOASTVALUE:
1031  case RELKIND_MATVIEW:
1032  case RELKIND_PARTITIONED_TABLE:
1033  options = heap_reloptions(classForm->relkind, datum, false);
1034  break;
1035  case RELKIND_VIEW:
1036  options = view_reloptions(datum, false);
1037  break;
1038  case RELKIND_INDEX:
1039  case RELKIND_PARTITIONED_INDEX:
1040  options = index_reloptions(amoptions, datum, false);
1041  break;
1042  case RELKIND_FOREIGN_TABLE:
1043  options = NULL;
1044  break;
1045  default:
1046  Assert(false); /* can't get here */
1047  options = NULL; /* keep compiler quiet */
1048  break;
1049  }
1050 
1051  return options;
1052 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1470
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:712
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1438
static char ** options
uintptr_t Datum
Definition: postgres.h:367
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1508
#define Assert(condition)
Definition: c.h:732
FormData_pg_class * Form_pg_class
Definition: pg_class.h:150
Definition: c.h:549

◆ fillRelOptions()

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

Definition at line 1292 of file reloptions.c.

References relopt_string::default_isnull, relopt_string::default_val, elog, ERROR, relopt_value::gen, i, relopt_parse_elt::offset, relopt_parse_elt::optname, RELOPT_TYPE_BOOL, RELOPT_TYPE_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().

1296 {
1297  int i;
1298  int offset = basesize;
1299 
1300  for (i = 0; i < numoptions; i++)
1301  {
1302  int j;
1303  bool found = false;
1304 
1305  for (j = 0; j < numelems; j++)
1306  {
1307  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1308  {
1309  relopt_string *optstring;
1310  char *itempos = ((char *) rdopts) + elems[j].offset;
1311  char *string_val;
1312 
1313  switch (options[i].gen->type)
1314  {
1315  case RELOPT_TYPE_BOOL:
1316  *(bool *) itempos = options[i].isset ?
1317  options[i].values.bool_val :
1318  ((relopt_bool *) options[i].gen)->default_val;
1319  break;
1320  case RELOPT_TYPE_INT:
1321  *(int *) itempos = options[i].isset ?
1322  options[i].values.int_val :
1323  ((relopt_int *) options[i].gen)->default_val;
1324  break;
1325  case RELOPT_TYPE_REAL:
1326  *(double *) itempos = options[i].isset ?
1327  options[i].values.real_val :
1328  ((relopt_real *) options[i].gen)->default_val;
1329  break;
1330  case RELOPT_TYPE_STRING:
1331  optstring = (relopt_string *) options[i].gen;
1332  if (options[i].isset)
1333  string_val = options[i].values.string_val;
1334  else if (!optstring->default_isnull)
1335  string_val = optstring->default_val;
1336  else
1337  string_val = NULL;
1338 
1339  if (string_val == NULL)
1340  *(int *) itempos = 0;
1341  else
1342  {
1343  strcpy((char *) rdopts + offset, string_val);
1344  *(int *) itempos = offset;
1345  offset += strlen(string_val) + 1;
1346  }
1347  break;
1348  default:
1349  elog(ERROR, "unsupported reloption type %d",
1350  options[i].gen->type);
1351  break;
1352  }
1353  found = true;
1354  break;
1355  }
1356  }
1357  if (validate && !found)
1358  elog(ERROR, "reloption \"%s\" not found in parse table",
1359  options[i].gen->name);
1360  }
1361  SET_VARSIZE(rdopts, offset);
1362 }
char * string_val
Definition: reloptions.h:83
bool default_isnull
Definition: reloptions.h:117
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:167
#define elog(elevel,...)
Definition: elog.h:226
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * default_val
Definition: reloptions.h:119

◆ heap_reloptions()

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

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

1471 {
1472  StdRdOptions *rdopts;
1473 
1474  switch (relkind)
1475  {
1476  case RELKIND_TOASTVALUE:
1477  rdopts = (StdRdOptions *)
1478  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1479  if (rdopts != NULL)
1480  {
1481  /* adjust default-only parameters for TOAST relations */
1482  rdopts->fillfactor = 100;
1483  rdopts->autovacuum.analyze_threshold = -1;
1484  rdopts->autovacuum.analyze_scale_factor = -1;
1485  }
1486  return (bytea *) rdopts;
1487  case RELKIND_RELATION:
1488  case RELKIND_MATVIEW:
1489  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1490  case RELKIND_PARTITIONED_TABLE:
1491  return default_reloptions(reloptions, validate,
1493  default:
1494  /* other relkinds are not supported */
1495  return NULL;
1496  }
1497 }
int fillfactor
Definition: rel.h:266
char relkind
Definition: pg_class.h:81
int analyze_threshold
Definition: rel.h:249
float8 analyze_scale_factor
Definition: rel.h:260
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1369
Definition: c.h:549
AutoVacOpts autovacuum
Definition: rel.h:270

◆ index_reloptions()

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

Definition at line 1508 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

1509 {
1510  Assert(amoptions != NULL);
1511 
1512  /* Assume function is strict */
1513  if (!PointerIsValid(DatumGetPointer(reloptions)))
1514  return NULL;
1515 
1516  return amoptions(reloptions, validate);
1517 }
#define Assert(condition)
Definition: c.h:732
#define DatumGetPointer(X)
Definition: postgres.h:549
#define PointerIsValid(pointer)
Definition: c.h:626

◆ initialize_reloptions()

static void initialize_reloptions ( void  )
static

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

485 {
486  int i;
487  int j;
488 
489  j = 0;
490  for (i = 0; boolRelOpts[i].gen.name; i++)
491  {
492  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
493  boolRelOpts[i].gen.lockmode));
494  j++;
495  }
496  for (i = 0; intRelOpts[i].gen.name; i++)
497  {
498  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
499  intRelOpts[i].gen.lockmode));
500  j++;
501  }
502  for (i = 0; realRelOpts[i].gen.name; i++)
503  {
504  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
505  realRelOpts[i].gen.lockmode));
506  j++;
507  }
508  for (i = 0; stringRelOpts[i].gen.name; i++)
509  {
510  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
512  j++;
513  }
514  j += num_custom_options;
515 
516  if (relOpts)
517  pfree(relOpts);
519  (j + 1) * sizeof(relopt_gen *));
520 
521  j = 0;
522  for (i = 0; boolRelOpts[i].gen.name; i++)
523  {
524  relOpts[j] = &boolRelOpts[i].gen;
526  relOpts[j]->namelen = strlen(relOpts[j]->name);
527  j++;
528  }
529 
530  for (i = 0; intRelOpts[i].gen.name; i++)
531  {
532  relOpts[j] = &intRelOpts[i].gen;
534  relOpts[j]->namelen = strlen(relOpts[j]->name);
535  j++;
536  }
537 
538  for (i = 0; realRelOpts[i].gen.name; i++)
539  {
540  relOpts[j] = &realRelOpts[i].gen;
542  relOpts[j]->namelen = strlen(relOpts[j]->name);
543  j++;
544  }
545 
546  for (i = 0; stringRelOpts[i].gen.name; i++)
547  {
548  relOpts[j] = &stringRelOpts[i].gen;
550  relOpts[j]->namelen = strlen(relOpts[j]->name);
551  j++;
552  }
553 
554  for (i = 0; i < num_custom_options; i++)
555  {
556  relOpts[j] = custom_options[i];
557  j++;
558  }
559 
560  /* add a list terminator */
561  relOpts[j] = NULL;
562 
563  /* flag the work is complete */
564  need_initialization = false;
565 }
static relopt_gen ** custom_options
Definition: reloptions.c:470
LOCKMODE lockmode
Definition: reloptions.h:68
static relopt_bool boolRelOpts[]
Definition: reloptions.c:96
relopt_gen gen
Definition: reloptions.h:115
void pfree(void *pointer)
Definition: mcxt.c:1031
static int num_custom_options
Definition: reloptions.c:469
relopt_gen gen
Definition: reloptions.h:90
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:358
int namelen
Definition: reloptions.h:69
MemoryContext TopMemoryContext
Definition: mcxt.c:44
relopt_gen gen
Definition: reloptions.h:96
#define Assert(condition)
Definition: c.h:732
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:436
const char * name
Definition: reloptions.h:64
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
int i
static bool need_initialization
Definition: reloptions.c:471
static relopt_int intRelOpts[]
Definition: reloptions.c:165
static relopt_gen ** relOpts
Definition: reloptions.c:466

◆ parse_one_reloption()

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

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

1168 {
1169  char *value;
1170  int value_len;
1171  bool parsed;
1172  bool nofree = false;
1173 
1174  if (option->isset && validate)
1175  ereport(ERROR,
1176  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1177  errmsg("parameter \"%s\" specified more than once",
1178  option->gen->name)));
1179 
1180  value_len = text_len - option->gen->namelen - 1;
1181  value = (char *) palloc(value_len + 1);
1182  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1183  value[value_len] = '\0';
1184 
1185  switch (option->gen->type)
1186  {
1187  case RELOPT_TYPE_BOOL:
1188  {
1189  parsed = parse_bool(value, &option->values.bool_val);
1190  if (validate && !parsed)
1191  ereport(ERROR,
1192  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1193  errmsg("invalid value for boolean option \"%s\": %s",
1194  option->gen->name, value)));
1195  }
1196  break;
1197  case RELOPT_TYPE_INT:
1198  {
1199  relopt_int *optint = (relopt_int *) option->gen;
1200 
1201  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1202  if (validate && !parsed)
1203  ereport(ERROR,
1204  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1205  errmsg("invalid value for integer option \"%s\": %s",
1206  option->gen->name, value)));
1207  if (validate && (option->values.int_val < optint->min ||
1208  option->values.int_val > optint->max))
1209  ereport(ERROR,
1210  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1211  errmsg("value %s out of bounds for option \"%s\"",
1212  value, option->gen->name),
1213  errdetail("Valid values are between \"%d\" and \"%d\".",
1214  optint->min, optint->max)));
1215  }
1216  break;
1217  case RELOPT_TYPE_REAL:
1218  {
1219  relopt_real *optreal = (relopt_real *) option->gen;
1220 
1221  parsed = parse_real(value, &option->values.real_val, 0, NULL);
1222  if (validate && !parsed)
1223  ereport(ERROR,
1224  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1225  errmsg("invalid value for floating point option \"%s\": %s",
1226  option->gen->name, value)));
1227  if (validate && (option->values.real_val < optreal->min ||
1228  option->values.real_val > optreal->max))
1229  ereport(ERROR,
1230  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1231  errmsg("value %s out of bounds for option \"%s\"",
1232  value, option->gen->name),
1233  errdetail("Valid values are between \"%f\" and \"%f\".",
1234  optreal->min, optreal->max)));
1235  }
1236  break;
1237  case RELOPT_TYPE_STRING:
1238  {
1239  relopt_string *optstring = (relopt_string *) option->gen;
1240 
1241  option->values.string_val = value;
1242  nofree = true;
1243  if (validate && optstring->validate_cb)
1244  (optstring->validate_cb) (value);
1245  parsed = true;
1246  }
1247  break;
1248  default:
1249  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1250  parsed = true; /* quiet compiler */
1251  break;
1252  }
1253 
1254  if (parsed)
1255  option->isset = true;
1256  if (!nofree)
1257  pfree(value);
1258 }
bool bool_val
Definition: reloptions.h:80
char * string_val
Definition: reloptions.h:83
static struct @144 value
int errcode(int sqlerrcode)
Definition: elog.c:570
bool parse_real(const char *value, double *result, int flags, const char **hintmsg)
Definition: guc.c:6356
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:1031
#define ERROR
Definition: elog.h:43
union relopt_value::@47 values
int errdetail(const char *fmt,...)
Definition: elog.c:860
int namelen
Definition: reloptions.h:69
double real_val
Definition: reloptions.h:82
#define ereport(elevel, rest)
Definition: elog.h:141
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:6266
relopt_type type
Definition: reloptions.h:70
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
const char * name
Definition: reloptions.h:64
#define elog(elevel,...)
Definition: elog.h:226
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 1074 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(), tablespace_reloptions(), and view_reloptions().

1076 {
1077  relopt_value *reloptions = NULL;
1078  int numoptions = 0;
1079  int i;
1080  int j;
1081 
1082  if (need_initialization)
1084 
1085  /* Build a list of expected options, based on kind */
1086 
1087  for (i = 0; relOpts[i]; i++)
1088  if (relOpts[i]->kinds & kind)
1089  numoptions++;
1090 
1091  if (numoptions > 0)
1092  {
1093  reloptions = palloc(numoptions * sizeof(relopt_value));
1094 
1095  for (i = 0, j = 0; relOpts[i]; i++)
1096  {
1097  if (relOpts[i]->kinds & kind)
1098  {
1099  reloptions[j].gen = relOpts[i];
1100  reloptions[j].isset = false;
1101  j++;
1102  }
1103  }
1104  }
1105 
1106  /* Done if no options */
1108  {
1110  Datum *optiondatums;
1111  int noptions;
1112 
1113  deconstruct_array(array, TEXTOID, -1, false, 'i',
1114  &optiondatums, NULL, &noptions);
1115 
1116  for (i = 0; i < noptions; i++)
1117  {
1118  char *text_str = VARDATA(optiondatums[i]);
1119  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1120  int j;
1121 
1122  /* Search for a match in reloptions */
1123  for (j = 0; j < numoptions; j++)
1124  {
1125  int kw_len = reloptions[j].gen->namelen;
1126 
1127  if (text_len > kw_len && text_str[kw_len] == '=' &&
1128  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1129  {
1130  parse_one_reloption(&reloptions[j], text_str, text_len,
1131  validate);
1132  break;
1133  }
1134  }
1135 
1136  if (j >= numoptions && validate)
1137  {
1138  char *s;
1139  char *p;
1140 
1141  s = TextDatumGetCString(optiondatums[i]);
1142  p = strchr(s, '=');
1143  if (p)
1144  *p = '\0';
1145  ereport(ERROR,
1146  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1147  errmsg("unrecognized parameter \"%s\"", s)));
1148  }
1149  }
1150 
1151  /* It's worth avoiding memory leaks in this function */
1152  pfree(optiondatums);
1153  if (((void *) array) != DatumGetPointer(options))
1154  pfree(array);
1155  }
1156 
1157  *numrelopts = numoptions;
1158  return reloptions;
1159 }
static void initialize_reloptions(void)
Definition: reloptions.c:484
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:555
int errcode(int sqlerrcode)
Definition: elog.c:570
relopt_gen * gen
Definition: reloptions.h:76
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:1166
int namelen
Definition: reloptions.h:69
#define ereport(elevel, rest)
Definition: elog.h:141
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
static bool need_initialization
Definition: reloptions.c:471
static relopt_gen ** relOpts
Definition: reloptions.c:466
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:626
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

1555 {
1557  TableSpaceOpts *tsopts;
1558  int numoptions;
1559  static const relopt_parse_elt tab[] = {
1560  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1561  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1562  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1563  };
1564 
1565  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1566  &numoptions);
1567 
1568  /* if none set, we're done */
1569  if (numoptions == 0)
1570  return NULL;
1571 
1572  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1573 
1574  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1575  validate, tab, lengthof(tab));
1576 
1577  pfree(options);
1578 
1579  return (bytea *) tsopts;
1580 }
#define lengthof(array)
Definition: c.h:662
int effective_io_concurrency
Definition: bufmgr.c:113
double random_page_cost
Definition: costsize.c:111
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1268
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:1292
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1074
double seq_page_cost
Definition: costsize.c:110
#define offsetof(type, field)
Definition: c.h:655

◆ transformRelOptions()

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

Definition at line 784 of file reloptions.c.

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

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

786 {
787  Datum result;
788  ArrayBuildState *astate;
789  ListCell *cell;
790 
791  /* no change if empty list */
792  if (defList == NIL)
793  return oldOptions;
794 
795  /* We build new array using accumArrayResult */
796  astate = NULL;
797 
798  /* Copy any oldOptions that aren't to be replaced */
799  if (PointerIsValid(DatumGetPointer(oldOptions)))
800  {
801  ArrayType *array = DatumGetArrayTypeP(oldOptions);
802  Datum *oldoptions;
803  int noldoptions;
804  int i;
805 
806  deconstruct_array(array, TEXTOID, -1, false, 'i',
807  &oldoptions, NULL, &noldoptions);
808 
809  for (i = 0; i < noldoptions; i++)
810  {
811  char *text_str = VARDATA(oldoptions[i]);
812  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
813 
814  /* Search for a match in defList */
815  foreach(cell, defList)
816  {
817  DefElem *def = (DefElem *) lfirst(cell);
818  int kw_len;
819 
820  /* ignore if not in the same namespace */
821  if (namspace == NULL)
822  {
823  if (def->defnamespace != NULL)
824  continue;
825  }
826  else if (def->defnamespace == NULL)
827  continue;
828  else if (strcmp(def->defnamespace, namspace) != 0)
829  continue;
830 
831  kw_len = strlen(def->defname);
832  if (text_len > kw_len && text_str[kw_len] == '=' &&
833  strncmp(text_str, def->defname, kw_len) == 0)
834  break;
835  }
836  if (!cell)
837  {
838  /* No match, so keep old option */
839  astate = accumArrayResult(astate, oldoptions[i],
840  false, TEXTOID,
842  }
843  }
844  }
845 
846  /*
847  * If CREATE/SET, add new options to array; if RESET, just check that the
848  * user didn't say RESET (option=val). (Must do this because the grammar
849  * doesn't enforce it.)
850  */
851  foreach(cell, defList)
852  {
853  DefElem *def = (DefElem *) lfirst(cell);
854 
855  if (isReset)
856  {
857  if (def->arg != NULL)
858  ereport(ERROR,
859  (errcode(ERRCODE_SYNTAX_ERROR),
860  errmsg("RESET must not include values for parameters")));
861  }
862  else
863  {
864  text *t;
865  const char *value;
866  Size len;
867 
868  /*
869  * Error out if the namespace is not valid. A NULL namespace is
870  * always valid.
871  */
872  if (def->defnamespace != NULL)
873  {
874  bool valid = false;
875  int i;
876 
877  if (validnsps)
878  {
879  for (i = 0; validnsps[i]; i++)
880  {
881  if (strcmp(def->defnamespace, validnsps[i]) == 0)
882  {
883  valid = true;
884  break;
885  }
886  }
887  }
888 
889  if (!valid)
890  ereport(ERROR,
891  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
892  errmsg("unrecognized parameter namespace \"%s\"",
893  def->defnamespace)));
894  }
895 
896  /* ignore if not in the same namespace */
897  if (namspace == NULL)
898  {
899  if (def->defnamespace != NULL)
900  continue;
901  }
902  else if (def->defnamespace == NULL)
903  continue;
904  else if (strcmp(def->defnamespace, namspace) != 0)
905  continue;
906 
907  /*
908  * Flatten the DefElem into a text string like "name=arg". If we
909  * have just "name", assume "name=true" is meant. Note: the
910  * namespace is not output.
911  */
912  if (def->arg != NULL)
913  value = defGetString(def);
914  else
915  value = "true";
916 
917  /*
918  * This is not a great place for this test, but there's no other
919  * convenient place to filter the option out. As WITH (oids =
920  * false) will be removed someday, this seems like an acceptable
921  * amount of ugly.
922  */
923  if (acceptOidsOff && def->defnamespace == NULL &&
924  strcmp(def->defname, "oids") == 0)
925  {
926  if (defGetBoolean(def))
927  ereport(ERROR,
928  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
929  errmsg("tables declared WITH OIDS are not supported")));
930  /* skip over option, reloptions machinery doesn't know it */
931  continue;
932  }
933 
934  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
935  /* +1 leaves room for sprintf's trailing null */
936  t = (text *) palloc(len + 1);
937  SET_VARSIZE(t, len);
938  sprintf(VARDATA(t), "%s=%s", def->defname, value);
939 
940  astate = accumArrayResult(astate, PointerGetDatum(t),
941  false, TEXTOID,
943  }
944  }
945 
946  if (astate)
947  result = makeArrayResult(astate, CurrentMemoryContext);
948  else
949  result = (Datum) 0;
950 
951  return result;
952 }
#define NIL
Definition: pg_list.h:65
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
#define VARHDRSZ
Definition: c.h:555
static struct @144 value
char * defnamespace
Definition: parsenodes.h:729
int errcode(int sqlerrcode)
Definition: elog.c:570
#define sprintf
Definition: port.h:194
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define ereport(elevel, rest)
Definition: elog.h:141
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5117
Node * arg
Definition: parsenodes.h:731
uintptr_t Datum
Definition: postgres.h:367
#define lfirst(lc)
Definition: pg_list.h:190
size_t Size
Definition: c.h:466
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5053
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
Definition: c.h:549
char * defname
Definition: parsenodes.h:730
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define PointerIsValid(pointer)
Definition: c.h:626
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 960 of file reloptions.c.

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

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

961 {
962  List *result = NIL;
963  ArrayType *array;
964  Datum *optiondatums;
965  int noptions;
966  int i;
967 
968  /* Nothing to do if no options */
970  return result;
971 
972  array = DatumGetArrayTypeP(options);
973 
974  deconstruct_array(array, TEXTOID, -1, false, 'i',
975  &optiondatums, NULL, &noptions);
976 
977  for (i = 0; i < noptions; i++)
978  {
979  char *s;
980  char *p;
981  Node *val = NULL;
982 
983  s = TextDatumGetCString(optiondatums[i]);
984  p = strchr(s, '=');
985  if (p)
986  {
987  *p++ = '\0';
988  val = (Node *) makeString(pstrdup(p));
989  }
990  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
991  }
992 
993  return result;
994 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1161
Definition: nodes.h:525
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:544
List * lappend(List *list, void *datum)
Definition: list.c:321
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
int i
static size_t noptions
Definition: pg_list.h:50
#define PointerIsValid(pointer)
Definition: c.h:626
long val
Definition: informix.c:684
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

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

1439 {
1441  ViewOptions *vopts;
1442  int numoptions;
1443  static const relopt_parse_elt tab[] = {
1444  {"security_barrier", RELOPT_TYPE_BOOL,
1445  offsetof(ViewOptions, security_barrier)},
1446  {"check_option", RELOPT_TYPE_STRING,
1447  offsetof(ViewOptions, check_option_offset)}
1448  };
1449 
1450  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1451 
1452  /* if none set, we're done */
1453  if (numoptions == 0)
1454  return NULL;
1455 
1456  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1457 
1458  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1459  validate, tab, lengthof(tab));
1460 
1461  pfree(options);
1462 
1463  return (bytea *) vopts;
1464 }
#define lengthof(array)
Definition: c.h:662
void pfree(void *pointer)
Definition: mcxt.c:1031
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1268
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:1292
Definition: c.h:549
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1074
#define offsetof(type, field)
Definition: c.h:655

Variable Documentation

◆ boolRelOpts

relopt_bool boolRelOpts[]
static

Definition at line 96 of file reloptions.c.

◆ custom_options

relopt_gen** custom_options = NULL
static

Definition at line 470 of file reloptions.c.

◆ intRelOpts

relopt_int intRelOpts[]
static

Definition at line 165 of file reloptions.c.

◆ last_assigned_kind

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

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

Referenced by add_reloption(), and initialize_reloptions().

◆ realRelOpts

relopt_real realRelOpts[]
static

Definition at line 358 of file reloptions.c.

◆ relOpts

relopt_gen** relOpts = NULL
static

Definition at line 466 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:244
void validateWithCheckOption(const char *value)
Definition: view.c:46
#define AccessExclusiveLock
Definition: lockdefs.h:45

Definition at line 436 of file reloptions.c.