PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 "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, char *name, char *desc)
 
void add_bool_reloption (bits32 kinds, char *name, char *desc, bool default_val)
 
void add_int_reloption (bits32 kinds, char *name, char *desc, int default_val, int min_val, int max_val)
 
void add_real_reloption (bits32 kinds, char *name, char *desc, double default_val, double min_val, double max_val)
 
void add_string_reloption (bits32 kinds, char *name, char *desc, char *default_val, validate_string_relopt validator)
 
Datum transformRelOptions (Datum oldOptions, List *defList, 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

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

Definition at line 624 of file reloptions.c.

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

625 {
626  relopt_bool *newoption;
627 
628  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
629  name, desc);
630  newoption->default_val = default_val;
631 
632  add_reloption((relopt_gen *) newoption);
633 }
bool default_val
Definition: reloptions.h:90
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
void add_int_reloption ( bits32  kinds,
char *  name,
char *  desc,
int  default_val,
int  min_val,
int  max_val 
)

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

642 {
643  relopt_int *newoption;
644 
645  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
646  name, desc);
647  newoption->default_val = default_val;
648  newoption->min = min_val;
649  newoption->max = max_val;
650 
651  add_reloption((relopt_gen *) newoption);
652 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
int default_val
Definition: reloptions.h:96
void add_real_reloption ( bits32  kinds,
char *  name,
char *  desc,
double  default_val,
double  min_val,
double  max_val 
)

Definition at line 659 of file reloptions.c.

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

661 {
662  relopt_real *newoption;
663 
664  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
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 }
double default_val
Definition: reloptions.h:104
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
double max
Definition: reloptions.h:106
double min
Definition: reloptions.h:105
static void add_reloption ( relopt_gen newoption)
static

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

543 {
544  static int max_custom_options = 0;
545 
546  if (num_custom_options >= max_custom_options)
547  {
548  MemoryContext oldcxt;
549 
551 
552  if (max_custom_options == 0)
553  {
554  max_custom_options = 8;
555  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
556  }
557  else
558  {
559  max_custom_options *= 2;
561  max_custom_options * sizeof(relopt_gen *));
562  }
563  MemoryContextSwitchTo(oldcxt);
564  }
565  custom_options[num_custom_options++] = newoption;
566 
567  need_initialization = true;
568 }
static relopt_gen ** custom_options
Definition: reloptions.c:422
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:421
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:963
void * palloc(Size size)
Definition: mcxt.c:849
static bool need_initialization
Definition: reloptions.c:423
relopt_kind add_reloption_kind ( void  )

Definition at line 525 of file reloptions.c.

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

Referenced by _PG_init().

526 {
527  /* don't hand out the last bit so that the enum's behavior is portable */
529  ereport(ERROR,
530  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
531  errmsg("user-defined relation parameter types limit exceeded")));
532  last_assigned_kind <<= 1;
534 }
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:419
void add_string_reloption ( bits32  kinds,
char *  name,
char *  desc,
char *  default_val,
validate_string_relopt  validator 
)

Definition at line 683 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.

685 {
686  relopt_string *newoption;
687 
688  /* make sure the validator/default combination is sane */
689  if (validator)
690  (validator) (default_val);
691 
692  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
693  name, desc);
694  newoption->validate_cb = validator;
695  if (default_val)
696  {
698  default_val);
699  newoption->default_len = strlen(default_val);
700  newoption->default_isnull = false;
701  }
702  else
703  {
704  newoption->default_val = "";
705  newoption->default_len = 0;
706  newoption->default_isnull = true;
707  }
708 
709  add_reloption((relopt_gen *) newoption);
710 }
bool default_isnull
Definition: reloptions.h:116
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
validate_string_relopt validate_cb
Definition: reloptions.h:117
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1064
char * default_val
Definition: reloptions.h:118
static relopt_gen* allocate_reloption ( bits32  kinds,
int  type,
char *  name,
char *  desc 
)
static

Definition at line 576 of file reloptions.c.

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

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

577 {
578  MemoryContext oldcxt;
579  size_t size;
580  relopt_gen *newoption;
581 
583 
584  switch (type)
585  {
586  case RELOPT_TYPE_BOOL:
587  size = sizeof(relopt_bool);
588  break;
589  case RELOPT_TYPE_INT:
590  size = sizeof(relopt_int);
591  break;
592  case RELOPT_TYPE_REAL:
593  size = sizeof(relopt_real);
594  break;
595  case RELOPT_TYPE_STRING:
596  size = sizeof(relopt_string);
597  break;
598  default:
599  elog(ERROR, "unsupported reloption type %d", type);
600  return NULL; /* keep compiler quiet */
601  }
602 
603  newoption = palloc(size);
604 
605  newoption->name = pstrdup(name);
606  if (desc)
607  newoption->desc = pstrdup(desc);
608  else
609  newoption->desc = NULL;
610  newoption->kinds = kinds;
611  newoption->namelen = strlen(name);
612  newoption->type = type;
613 
614  MemoryContextSwitchTo(oldcxt);
615 
616  return newoption;
617 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1077
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:68
MemoryContext TopMemoryContext
Definition: mcxt.c:43
bits32 kinds
Definition: reloptions.h:66
#define NULL
Definition: c.h:229
relopt_type type
Definition: reloptions.h:69
struct relopt_int relopt_int
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:849
const char * name
Definition: reloptions.h:63
#define elog
Definition: elog.h:219
void* allocateReloptStruct ( Size  base,
relopt_value options,
int  numoptions 
)

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

1209 {
1210  Size size = base;
1211  int i;
1212 
1213  for (i = 0; i < numoptions; i++)
1214  if (options[i].gen->type == RELOPT_TYPE_STRING)
1215  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1216 
1217  return palloc0(size);
1218 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:233
void * palloc0(Size size)
Definition: mcxt.c:878
size_t Size
Definition: c.h:356
int i
LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

1520 {
1521  LOCKMODE lockmode = NoLock;
1522  ListCell *cell;
1523 
1524  if (defList == NIL)
1525  return AccessExclusiveLock;
1526 
1527  if (need_initialization)
1529 
1530  foreach(cell, defList)
1531  {
1532  DefElem *def = (DefElem *) lfirst(cell);
1533  int i;
1534 
1535  for (i = 0; relOpts[i]; i++)
1536  {
1537  if (pg_strncasecmp(relOpts[i]->name,
1538  def->defname,
1539  relOpts[i]->namelen + 1) == 0)
1540  {
1541  if (lockmode < relOpts[i]->lockmode)
1542  lockmode = relOpts[i]->lockmode;
1543  }
1544  }
1545  }
1546 
1547  return lockmode;
1548 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:436
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:67
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:68
#define lfirst(lc)
Definition: pg_list.h:106
const char * name
Definition: encode.c:521
#define AccessExclusiveLock
Definition: lockdefs.h:46
int i
static bool need_initialization
Definition: reloptions.c:423
char * defname
Definition: parsenodes.h:708
static relopt_gen ** relOpts
Definition: reloptions.c:418
bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1453 of file reloptions.c.

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

Referenced by ATExecSetOptions(), and get_attribute_options().

1454 {
1456  AttributeOpts *aopts;
1457  int numoptions;
1458  static const relopt_parse_elt tab[] = {
1459  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1460  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1461  };
1462 
1463  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1464  &numoptions);
1465 
1466  /* if none set, we're done */
1467  if (numoptions == 0)
1468  return NULL;
1469 
1470  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1471 
1472  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1473  validate, tab, lengthof(tab));
1474 
1475  pfree(options);
1476 
1477  return (bytea *) aopts;
1478 }
#define lengthof(array)
Definition: c.h:562
void pfree(void *pointer)
Definition: mcxt.c:950
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
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:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
#define offsetof(type, field)
Definition: c.h:555
bytea* default_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind 
)

Definition at line 1309 of file reloptions.c.

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

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

1310 {
1312  StdRdOptions *rdopts;
1313  int numoptions;
1314  static const relopt_parse_elt tab[] = {
1315  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1316  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1317  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, enabled)},
1318  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1319  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_threshold)},
1320  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1321  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_threshold)},
1322  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1323  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_delay)},
1324  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1325  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_limit)},
1326  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1327  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_min_age)},
1328  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1329  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_max_age)},
1330  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1331  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_table_age)},
1332  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1333  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_min_age)},
1334  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1335  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_max_age)},
1336  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1337  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_table_age)},
1338  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1339  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, log_min_duration)},
1340  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1341  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
1342  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1343  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
1344  {"user_catalog_table", RELOPT_TYPE_BOOL,
1345  offsetof(StdRdOptions, user_catalog_table)},
1346  {"parallel_workers", RELOPT_TYPE_INT,
1347  offsetof(StdRdOptions, parallel_workers)}
1348  };
1349 
1350  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1351 
1352  /* if none set, we're done */
1353  if (numoptions == 0)
1354  return NULL;
1355 
1356  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1357 
1358  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1359  validate, tab, lengthof(tab));
1360 
1361  pfree(options);
1362 
1363  return (bytea *) rdopts;
1364 }
#define lengthof(array)
Definition: c.h:562
void pfree(void *pointer)
Definition: mcxt.c:950
int fillfactor
Definition: pgbench.c:112
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
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:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
#define offsetof(type, field)
Definition: c.h:555
bytea* extractRelOptions ( HeapTuple  tuple,
TupleDesc  tupdesc,
amoptions_function  amoptions 
)

Definition at line 947 of file reloptions.c.

References Anum_pg_class_reloptions, Assert, fastgetattr, GETSTRUCT, heap_reloptions(), index_reloptions(), NULL, 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().

949 {
950  bytea *options;
951  bool isnull;
952  Datum datum;
953  Form_pg_class classForm;
954 
955  datum = fastgetattr(tuple,
957  tupdesc,
958  &isnull);
959  if (isnull)
960  return NULL;
961 
962  classForm = (Form_pg_class) GETSTRUCT(tuple);
963 
964  /* Parse into appropriate format; don't error out here */
965  switch (classForm->relkind)
966  {
967  case RELKIND_RELATION:
968  case RELKIND_TOASTVALUE:
969  case RELKIND_MATVIEW:
971  options = heap_reloptions(classForm->relkind, datum, false);
972  break;
973  case RELKIND_VIEW:
974  options = view_reloptions(datum, false);
975  break;
976  case RELKIND_INDEX:
977  options = index_reloptions(amoptions, datum, false);
978  break;
980  options = NULL;
981  break;
982  default:
983  Assert(false); /* can't get here */
984  options = NULL; /* keep compiler quiet */
985  break;
986  }
987 
988  return options;
989 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1402
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:719
#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:1370
#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:1438
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
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:439
#define RELKIND_RELATION
Definition: pg_class.h:160
void fillRelOptions ( void *  rdopts,
Size  basesize,
relopt_value options,
int  numoptions,
bool  validate,
const relopt_parse_elt elems,
int  numelems 
)

Definition at line 1232 of file reloptions.c.

References relopt_string::default_isnull, relopt_string::default_val, elog, ERROR, relopt_value::gen, i, NULL, 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().

1236 {
1237  int i;
1238  int offset = basesize;
1239 
1240  for (i = 0; i < numoptions; i++)
1241  {
1242  int j;
1243  bool found = false;
1244 
1245  for (j = 0; j < numelems; j++)
1246  {
1247  if (pg_strcasecmp(options[i].gen->name, elems[j].optname) == 0)
1248  {
1249  relopt_string *optstring;
1250  char *itempos = ((char *) rdopts) + elems[j].offset;
1251  char *string_val;
1252 
1253  switch (options[i].gen->type)
1254  {
1255  case RELOPT_TYPE_BOOL:
1256  *(bool *) itempos = options[i].isset ?
1257  options[i].values.bool_val :
1258  ((relopt_bool *) options[i].gen)->default_val;
1259  break;
1260  case RELOPT_TYPE_INT:
1261  *(int *) itempos = options[i].isset ?
1262  options[i].values.int_val :
1263  ((relopt_int *) options[i].gen)->default_val;
1264  break;
1265  case RELOPT_TYPE_REAL:
1266  *(double *) itempos = options[i].isset ?
1267  options[i].values.real_val :
1268  ((relopt_real *) options[i].gen)->default_val;
1269  break;
1270  case RELOPT_TYPE_STRING:
1271  optstring = (relopt_string *) options[i].gen;
1272  if (options[i].isset)
1273  string_val = options[i].values.string_val;
1274  else if (!optstring->default_isnull)
1275  string_val = optstring->default_val;
1276  else
1277  string_val = NULL;
1278 
1279  if (string_val == NULL)
1280  *(int *) itempos = 0;
1281  else
1282  {
1283  strcpy((char *) rdopts + offset, string_val);
1284  *(int *) itempos = offset;
1285  offset += strlen(string_val) + 1;
1286  }
1287  break;
1288  default:
1289  elog(ERROR, "unsupported reloption type %d",
1290  options[i].gen->type);
1291  break;
1292  }
1293  found = true;
1294  break;
1295  }
1296  }
1297  if (validate && !found)
1298  elog(ERROR, "reloption \"%s\" not found in parse table",
1299  options[i].gen->name);
1300  }
1301  SET_VARSIZE(rdopts, offset);
1302 }
char * string_val
Definition: reloptions.h:82
union relopt_value::@41 values
bool default_isnull
Definition: reloptions.h:116
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
relopt_gen * gen
Definition: reloptions.h:75
#define ERROR
Definition: elog.h:43
const char * optname
Definition: reloptions.h:124
#define NULL
Definition: c.h:229
static Datum values[MAXATTR]
Definition: bootstrap.c:162
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define elog
Definition: elog.h:219
char * default_val
Definition: reloptions.h:118
bytea* heap_reloptions ( char  relkind,
Datum  reloptions,
bool  validate 
)

Definition at line 1402 of file reloptions.c.

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

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

1403 {
1404  StdRdOptions *rdopts;
1405 
1406  switch (relkind)
1407  {
1408  case RELKIND_TOASTVALUE:
1409  rdopts = (StdRdOptions *)
1410  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1411  if (rdopts != NULL)
1412  {
1413  /* adjust default-only parameters for TOAST relations */
1414  rdopts->fillfactor = 100;
1415  rdopts->autovacuum.analyze_threshold = -1;
1416  rdopts->autovacuum.analyze_scale_factor = -1;
1417  }
1418  return (bytea *) rdopts;
1419  case RELKIND_RELATION:
1420  case RELKIND_MATVIEW:
1422  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1423  default:
1424  /* other relkinds are not supported */
1425  return NULL;
1426  }
1427 }
#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
#define NULL
Definition: c.h:229
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1309
Definition: c.h:439
#define RELKIND_RELATION
Definition: pg_class.h:160
AutoVacOpts autovacuum
Definition: rel.h:280
bytea* index_reloptions ( amoptions_function  amoptions,
Datum  reloptions,
bool  validate 
)

Definition at line 1438 of file reloptions.c.

References Assert, DatumGetPointer, NULL, and PointerIsValid.

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

1439 {
1440  Assert(amoptions != NULL);
1441 
1442  /* Assume function is strict */
1443  if (!PointerIsValid(DatumGetPointer(reloptions)))
1444  return NULL;
1445 
1446  return amoptions(reloptions, validate);
1447 }
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define DatumGetPointer(X)
Definition: postgres.h:555
#define PointerIsValid(pointer)
Definition: c.h:526
static void initialize_reloptions ( void  )
static

Definition at line 436 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, NULL, 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().

437 {
438  int i;
439  int j;
440 
441  j = 0;
442  for (i = 0; boolRelOpts[i].gen.name; i++)
443  {
444  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
445  boolRelOpts[i].gen.lockmode));
446  j++;
447  }
448  for (i = 0; intRelOpts[i].gen.name; i++)
449  {
450  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
451  intRelOpts[i].gen.lockmode));
452  j++;
453  }
454  for (i = 0; realRelOpts[i].gen.name; i++)
455  {
456  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
457  realRelOpts[i].gen.lockmode));
458  j++;
459  }
460  for (i = 0; stringRelOpts[i].gen.name; i++)
461  {
462  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
464  j++;
465  }
466  j += num_custom_options;
467 
468  if (relOpts)
469  pfree(relOpts);
471  (j + 1) * sizeof(relopt_gen *));
472 
473  j = 0;
474  for (i = 0; boolRelOpts[i].gen.name; i++)
475  {
476  relOpts[j] = &boolRelOpts[i].gen;
478  relOpts[j]->namelen = strlen(relOpts[j]->name);
479  j++;
480  }
481 
482  for (i = 0; intRelOpts[i].gen.name; i++)
483  {
484  relOpts[j] = &intRelOpts[i].gen;
486  relOpts[j]->namelen = strlen(relOpts[j]->name);
487  j++;
488  }
489 
490  for (i = 0; realRelOpts[i].gen.name; i++)
491  {
492  relOpts[j] = &realRelOpts[i].gen;
494  relOpts[j]->namelen = strlen(relOpts[j]->name);
495  j++;
496  }
497 
498  for (i = 0; stringRelOpts[i].gen.name; i++)
499  {
500  relOpts[j] = &stringRelOpts[i].gen;
502  relOpts[j]->namelen = strlen(relOpts[j]->name);
503  j++;
504  }
505 
506  for (i = 0; i < num_custom_options; i++)
507  {
508  relOpts[j] = custom_options[i];
509  j++;
510  }
511 
512  /* add a list terminator */
513  relOpts[j] = NULL;
514 
515  /* flag the work is complete */
516  need_initialization = false;
517 }
static relopt_gen ** custom_options
Definition: reloptions.c:422
LOCKMODE lockmode
Definition: reloptions.h:67
static relopt_bool boolRelOpts[]
Definition: reloptions.c:93
relopt_gen gen
Definition: reloptions.h:114
void pfree(void *pointer)
Definition: mcxt.c:950
static int num_custom_options
Definition: reloptions.c:421
relopt_gen gen
Definition: reloptions.h:89
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:328
int namelen
Definition: reloptions.h:68
MemoryContext TopMemoryContext
Definition: mcxt.c:43
relopt_gen gen
Definition: reloptions.h:95
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
relopt_type type
Definition: reloptions.h:69
relopt_gen gen
Definition: reloptions.h:103
const char * name
Definition: encode.c:521
static relopt_string stringRelOpts[]
Definition: reloptions.c:388
const char * name
Definition: reloptions.h:63
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
int i
static bool need_initialization
Definition: reloptions.c:423
static relopt_int intRelOpts[]
Definition: reloptions.c:135
static relopt_gen ** relOpts
Definition: reloptions.c:418
static void parse_one_reloption ( relopt_value option,
char *  text_str,
int  text_len,
bool  validate 
)
static

Definition at line 1106 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, NULL, 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().

1108 {
1109  char *value;
1110  int value_len;
1111  bool parsed;
1112  bool nofree = false;
1113 
1114  if (option->isset && validate)
1115  ereport(ERROR,
1116  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1117  errmsg("parameter \"%s\" specified more than once",
1118  option->gen->name)));
1119 
1120  value_len = text_len - option->gen->namelen - 1;
1121  value = (char *) palloc(value_len + 1);
1122  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1123  value[value_len] = '\0';
1124 
1125  switch (option->gen->type)
1126  {
1127  case RELOPT_TYPE_BOOL:
1128  {
1129  parsed = parse_bool(value, &option->values.bool_val);
1130  if (validate && !parsed)
1131  ereport(ERROR,
1132  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1133  errmsg("invalid value for boolean option \"%s\": %s",
1134  option->gen->name, value)));
1135  }
1136  break;
1137  case RELOPT_TYPE_INT:
1138  {
1139  relopt_int *optint = (relopt_int *) option->gen;
1140 
1141  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1142  if (validate && !parsed)
1143  ereport(ERROR,
1144  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1145  errmsg("invalid value for integer option \"%s\": %s",
1146  option->gen->name, value)));
1147  if (validate && (option->values.int_val < optint->min ||
1148  option->values.int_val > optint->max))
1149  ereport(ERROR,
1150  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1151  errmsg("value %s out of bounds for option \"%s\"",
1152  value, option->gen->name),
1153  errdetail("Valid values are between \"%d\" and \"%d\".",
1154  optint->min, optint->max)));
1155  }
1156  break;
1157  case RELOPT_TYPE_REAL:
1158  {
1159  relopt_real *optreal = (relopt_real *) option->gen;
1160 
1161  parsed = parse_real(value, &option->values.real_val);
1162  if (validate && !parsed)
1163  ereport(ERROR,
1164  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1165  errmsg("invalid value for floating point option \"%s\": %s",
1166  option->gen->name, value)));
1167  if (validate && (option->values.real_val < optreal->min ||
1168  option->values.real_val > optreal->max))
1169  ereport(ERROR,
1170  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1171  errmsg("value %s out of bounds for option \"%s\"",
1172  value, option->gen->name),
1173  errdetail("Valid values are between \"%f\" and \"%f\".",
1174  optreal->min, optreal->max)));
1175  }
1176  break;
1177  case RELOPT_TYPE_STRING:
1178  {
1179  relopt_string *optstring = (relopt_string *) option->gen;
1180 
1181  option->values.string_val = value;
1182  nofree = true;
1183  if (validate && optstring->validate_cb)
1184  (optstring->validate_cb) (value);
1185  parsed = true;
1186  }
1187  break;
1188  default:
1189  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1190  parsed = true; /* quiet compiler */
1191  break;
1192  }
1193 
1194  if (parsed)
1195  option->isset = true;
1196  if (!nofree)
1197  pfree(value);
1198 }
bool bool_val
Definition: reloptions.h:79
char * string_val
Definition: reloptions.h:82
union relopt_value::@41 values
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:75
static struct @114 value
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:873
int namelen
Definition: reloptions.h:68
bool parse_real(const char *value, double *result)
Definition: guc.c:5562
double real_val
Definition: reloptions.h:81
#define ereport(elevel, rest)
Definition: elog.h:122
validate_string_relopt validate_cb
Definition: reloptions.h:117
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:5476
#define NULL
Definition: c.h:229
relopt_type type
Definition: reloptions.h:69
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
const char * name
Definition: reloptions.h:63
#define elog
Definition: elog.h:219
double max
Definition: reloptions.h:106
double min
Definition: reloptions.h:105
relopt_value* parseRelOptions ( Datum  options,
bool  validate,
relopt_kind  kind,
int *  numrelopts 
)

Definition at line 1010 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, NULL, 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().

1012 {
1013  relopt_value *reloptions;
1014  int numoptions = 0;
1015  int i;
1016  int j;
1017 
1018  if (need_initialization)
1020 
1021  /* Build a list of expected options, based on kind */
1022 
1023  for (i = 0; relOpts[i]; i++)
1024  if (relOpts[i]->kinds & kind)
1025  numoptions++;
1026 
1027  if (numoptions == 0)
1028  {
1029  *numrelopts = 0;
1030  return NULL;
1031  }
1032 
1033  reloptions = palloc(numoptions * sizeof(relopt_value));
1034 
1035  for (i = 0, j = 0; relOpts[i]; i++)
1036  {
1037  if (relOpts[i]->kinds & kind)
1038  {
1039  reloptions[j].gen = relOpts[i];
1040  reloptions[j].isset = false;
1041  j++;
1042  }
1043  }
1044 
1045  /* Done if no options */
1047  {
1049  Datum *optiondatums;
1050  int noptions;
1051 
1052  deconstruct_array(array, TEXTOID, -1, false, 'i',
1053  &optiondatums, NULL, &noptions);
1054 
1055  for (i = 0; i < noptions; i++)
1056  {
1057  char *text_str = VARDATA(optiondatums[i]);
1058  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1059  int j;
1060 
1061  /* Search for a match in reloptions */
1062  for (j = 0; j < numoptions; j++)
1063  {
1064  int kw_len = reloptions[j].gen->namelen;
1065 
1066  if (text_len > kw_len && text_str[kw_len] == '=' &&
1067  pg_strncasecmp(text_str, reloptions[j].gen->name,
1068  kw_len) == 0)
1069  {
1070  parse_one_reloption(&reloptions[j], text_str, text_len,
1071  validate);
1072  break;
1073  }
1074  }
1075 
1076  if (j >= numoptions && validate)
1077  {
1078  char *s;
1079  char *p;
1080 
1081  s = TextDatumGetCString(optiondatums[i]);
1082  p = strchr(s, '=');
1083  if (p)
1084  *p = '\0';
1085  ereport(ERROR,
1086  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1087  errmsg("unrecognized parameter \"%s\"", s)));
1088  }
1089  }
1090 
1091  /* It's worth avoiding memory leaks in this function */
1092  pfree(optiondatums);
1093  if (((void *) array) != DatumGetPointer(options))
1094  pfree(array);
1095  }
1096 
1097  *numrelopts = numoptions;
1098  return reloptions;
1099 }
static void initialize_reloptions(void)
Definition: reloptions.c:436
#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:445
int errcode(int sqlerrcode)
Definition: elog.c:575
relopt_gen * gen
Definition: reloptions.h:75
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
void pfree(void *pointer)
Definition: mcxt.c:950
#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:1106
int namelen
Definition: reloptions.h:68
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
#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:3475
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static bool need_initialization
Definition: reloptions.c:423
static relopt_gen ** relOpts
Definition: reloptions.c:418
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:526
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1484 of file reloptions.c.

References allocateReloptStruct(), effective_io_concurrency, fillRelOptions(), lengthof, NULL, 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().

1485 {
1487  TableSpaceOpts *tsopts;
1488  int numoptions;
1489  static const relopt_parse_elt tab[] = {
1490  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1491  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1492  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1493  };
1494 
1495  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1496  &numoptions);
1497 
1498  /* if none set, we're done */
1499  if (numoptions == 0)
1500  return NULL;
1501 
1502  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1503 
1504  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1505  validate, tab, lengthof(tab));
1506 
1507  pfree(options);
1508 
1509  return (bytea *) tsopts;
1510 }
#define lengthof(array)
Definition: c.h:562
int effective_io_concurrency
Definition: bufmgr.c:112
double random_page_cost
Definition: costsize.c:105
void pfree(void *pointer)
Definition: mcxt.c:950
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
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:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
double seq_page_cost
Definition: costsize.c:104
#define offsetof(type, field)
Definition: c.h:555
Datum transformRelOptions ( Datum  oldOptions,
List defList,
char *  namspace,
char *  validnsps[],
bool  ignoreOids,
bool  isReset 
)

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

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

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

Definition at line 898 of file reloptions.c.

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

899 {
900  List *result = NIL;
901  ArrayType *array;
902  Datum *optiondatums;
903  int noptions;
904  int i;
905 
906  /* Nothing to do if no options */
908  return result;
909 
910  array = DatumGetArrayTypeP(options);
911 
912  deconstruct_array(array, TEXTOID, -1, false, 'i',
913  &optiondatums, NULL, &noptions);
914 
915  for (i = 0; i < noptions; i++)
916  {
917  char *s;
918  char *p;
919  Node *val = NULL;
920 
921  s = TextDatumGetCString(optiondatums[i]);
922  p = strchr(s, '=');
923  if (p)
924  {
925  *p++ = '\0';
926  val = (Node *) makeString(pstrdup(p));
927  }
928  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
929  }
930 
931  return result;
932 }
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:1077
Definition: nodes.h:506
return result
Definition: formatting.c:1618
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:543
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 NULL
Definition: c.h:229
#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:3475
int i
static size_t noptions
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:526
long val
Definition: informix.c:689
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1370 of file reloptions.c.

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

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

1371 {
1373  ViewOptions *vopts;
1374  int numoptions;
1375  static const relopt_parse_elt tab[] = {
1376  {"security_barrier", RELOPT_TYPE_BOOL,
1377  offsetof(ViewOptions, security_barrier)},
1378  {"check_option", RELOPT_TYPE_STRING,
1379  offsetof(ViewOptions, check_option_offset)}
1380  };
1381 
1382  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1383 
1384  /* if none set, we're done */
1385  if (numoptions == 0)
1386  return NULL;
1387 
1388  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1389 
1390  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1391  validate, tab, lengthof(tab));
1392 
1393  pfree(options);
1394 
1395  return (bytea *) vopts;
1396 }
#define lengthof(array)
Definition: c.h:562
void pfree(void *pointer)
Definition: mcxt.c:950
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
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:1232
#define NULL
Definition: c.h:229
Definition: c.h:439
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
#define offsetof(type, field)
Definition: c.h:555

Variable Documentation

relopt_bool boolRelOpts[]
static

Definition at line 93 of file reloptions.c.

relopt_gen** custom_options = NULL
static

Definition at line 422 of file reloptions.c.

relopt_int intRelOpts[]
static

Definition at line 135 of file reloptions.c.

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

Definition at line 419 of file reloptions.c.

Referenced by add_reloption_kind().

bool need_initialization = true
static
int num_custom_options = 0
static

Definition at line 421 of file reloptions.c.

Referenced by add_reloption(), and initialize_reloptions().

relopt_real realRelOpts[]
static

Definition at line 328 of file reloptions.c.

relopt_gen** relOpts = NULL
static

Definition at line 418 of file reloptions.c.

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}}
}
void gistValidateBufferingOption(char *value)
Definition: gistbuild.c:241
void validateWithCheckOption(char *value)
Definition: view.c:46
#define NULL
Definition: c.h:229
#define AccessExclusiveLock
Definition: lockdefs.h:46

Definition at line 388 of file reloptions.c.