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

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

589 {
590  relopt_bool *newoption;
591 
592  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
593  name, desc);
594  newoption->default_val = default_val;
595 
596  add_reloption((relopt_gen *) newoption);
597 }
bool default_val
Definition: reloptions.h:90
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:506
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 604 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().

606 {
607  relopt_int *newoption;
608 
609  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
610  name, desc);
611  newoption->default_val = default_val;
612  newoption->min = min_val;
613  newoption->max = max_val;
614 
615  add_reloption((relopt_gen *) newoption);
616 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:506
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 623 of file reloptions.c.

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

625 {
626  relopt_real *newoption;
627 
628  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
629  name, desc);
630  newoption->default_val = default_val;
631  newoption->min = min_val;
632  newoption->max = max_val;
633 
634  add_reloption((relopt_gen *) newoption);
635 }
double default_val
Definition: reloptions.h:104
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:506
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 506 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().

507 {
508  static int max_custom_options = 0;
509 
510  if (num_custom_options >= max_custom_options)
511  {
512  MemoryContext oldcxt;
513 
515 
516  if (max_custom_options == 0)
517  {
518  max_custom_options = 8;
519  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
520  }
521  else
522  {
523  max_custom_options *= 2;
525  max_custom_options * sizeof(relopt_gen *));
526  }
527  MemoryContextSwitchTo(oldcxt);
528  }
529  custom_options[num_custom_options++] = newoption;
530 
531  need_initialization = true;
532 }
static relopt_gen ** custom_options
Definition: reloptions.c:386
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:385
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1021
void * palloc(Size size)
Definition: mcxt.c:891
static bool need_initialization
Definition: reloptions.c:387
relopt_kind add_reloption_kind ( void  )

Definition at line 489 of file reloptions.c.

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

Referenced by _PG_init().

490 {
491  /* don't hand out the last bit so that the enum's behavior is portable */
493  ereport(ERROR,
494  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
495  errmsg("user-defined relation parameter types limit exceeded")));
496  last_assigned_kind <<= 1;
498 }
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:383
void add_string_reloption ( bits32  kinds,
char *  name,
char *  desc,
char *  default_val,
validate_string_relopt  validator 
)

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

649 {
650  relopt_string *newoption;
651 
652  /* make sure the validator/default combination is sane */
653  if (validator)
654  (validator) (default_val);
655 
656  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
657  name, desc);
658  newoption->validate_cb = validator;
659  if (default_val)
660  {
662  default_val);
663  newoption->default_len = strlen(default_val);
664  newoption->default_isnull = false;
665  }
666  else
667  {
668  newoption->default_val = "";
669  newoption->default_len = 0;
670  newoption->default_isnull = true;
671  }
672 
673  add_reloption((relopt_gen *) newoption);
674 }
bool default_isnull
Definition: reloptions.h:116
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:540
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:506
const char * name
Definition: encode.c:521
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1152
char * default_val
Definition: reloptions.h:118
static relopt_gen* allocate_reloption ( bits32  kinds,
int  type,
char *  name,
char *  desc 
)
static

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

541 {
542  MemoryContext oldcxt;
543  size_t size;
544  relopt_gen *newoption;
545 
547 
548  switch (type)
549  {
550  case RELOPT_TYPE_BOOL:
551  size = sizeof(relopt_bool);
552  break;
553  case RELOPT_TYPE_INT:
554  size = sizeof(relopt_int);
555  break;
556  case RELOPT_TYPE_REAL:
557  size = sizeof(relopt_real);
558  break;
559  case RELOPT_TYPE_STRING:
560  size = sizeof(relopt_string);
561  break;
562  default:
563  elog(ERROR, "unsupported reloption type %d", type);
564  return NULL; /* keep compiler quiet */
565  }
566 
567  newoption = palloc(size);
568 
569  newoption->name = pstrdup(name);
570  if (desc)
571  newoption->desc = pstrdup(desc);
572  else
573  newoption->desc = NULL;
574  newoption->kinds = kinds;
575  newoption->namelen = strlen(name);
576  newoption->type = type;
577 
578  MemoryContextSwitchTo(oldcxt);
579 
580  return newoption;
581 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1165
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:226
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:891
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 1174 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().

1175 {
1176  Size size = base;
1177  int i;
1178 
1179  for (i = 0; i < numoptions; i++)
1180  if (options[i].gen->type == RELOPT_TYPE_STRING)
1181  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1182 
1183  return palloc0(size);
1184 }
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:233
void * palloc0(Size size)
Definition: mcxt.c:920
size_t Size
Definition: c.h:353
int i
LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

1486 {
1487  LOCKMODE lockmode = NoLock;
1488  ListCell *cell;
1489 
1490  if (defList == NIL)
1491  return AccessExclusiveLock;
1492 
1493  if (need_initialization)
1495 
1496  foreach(cell, defList)
1497  {
1498  DefElem *def = (DefElem *) lfirst(cell);
1499  int i;
1500 
1501  for (i = 0; relOpts[i]; i++)
1502  {
1503  if (pg_strncasecmp(relOpts[i]->name,
1504  def->defname,
1505  relOpts[i]->namelen + 1) == 0)
1506  {
1507  if (lockmode < relOpts[i]->lockmode)
1508  lockmode = relOpts[i]->lockmode;
1509  }
1510  }
1511  }
1512 
1513  return lockmode;
1514 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:400
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:387
char * defname
Definition: parsenodes.h:675
static relopt_gen ** relOpts
Definition: reloptions.c:382
bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

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

1420 {
1422  AttributeOpts *aopts;
1423  int numoptions;
1424  static const relopt_parse_elt tab[] = {
1425  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1426  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1427  };
1428 
1429  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1430  &numoptions);
1431 
1432  /* if none set, we're done */
1433  if (numoptions == 0)
1434  return NULL;
1435 
1436  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1437 
1438  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1439  validate, tab, lengthof(tab));
1440 
1441  pfree(options);
1442 
1443  return (bytea *) aopts;
1444 }
#define lengthof(array)
Definition: c.h:558
void pfree(void *pointer)
Definition: mcxt.c:992
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
#define offsetof(type, field)
Definition: c.h:551
bytea* default_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind 
)

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

1276 {
1278  StdRdOptions *rdopts;
1279  int numoptions;
1280  static const relopt_parse_elt tab[] = {
1281  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1282  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1283  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, enabled)},
1284  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1285  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_threshold)},
1286  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1287  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_threshold)},
1288  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1289  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_delay)},
1290  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1291  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_limit)},
1292  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1293  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_min_age)},
1294  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1295  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_max_age)},
1296  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1297  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_table_age)},
1298  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1299  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_min_age)},
1300  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1301  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_max_age)},
1302  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1303  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_table_age)},
1304  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1305  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, log_min_duration)},
1306  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1307  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
1308  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1309  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
1310  {"user_catalog_table", RELOPT_TYPE_BOOL,
1311  offsetof(StdRdOptions, user_catalog_table)},
1312  {"parallel_workers", RELOPT_TYPE_INT,
1313  offsetof(StdRdOptions, parallel_workers)}
1314  };
1315 
1316  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1317 
1318  /* if none set, we're done */
1319  if (numoptions == 0)
1320  return NULL;
1321 
1322  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1323 
1324  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1325  validate, tab, lengthof(tab));
1326 
1327  pfree(options);
1328 
1329  return (bytea *) rdopts;
1330 }
#define lengthof(array)
Definition: c.h:558
void pfree(void *pointer)
Definition: mcxt.c:992
int fillfactor
Definition: pgbench.c:112
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
#define offsetof(type, field)
Definition: c.h:551
bytea* extractRelOptions ( HeapTuple  tuple,
TupleDesc  tupdesc,
amoptions_function  amoptions 
)

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

914 {
915  bytea *options;
916  bool isnull;
917  Datum datum;
918  Form_pg_class classForm;
919 
920  datum = fastgetattr(tuple,
922  tupdesc,
923  &isnull);
924  if (isnull)
925  return NULL;
926 
927  classForm = (Form_pg_class) GETSTRUCT(tuple);
928 
929  /* Parse into appropriate format; don't error out here */
930  switch (classForm->relkind)
931  {
932  case RELKIND_RELATION:
933  case RELKIND_TOASTVALUE:
934  case RELKIND_MATVIEW:
936  options = heap_reloptions(classForm->relkind, datum, false);
937  break;
938  case RELKIND_VIEW:
939  options = view_reloptions(datum, false);
940  break;
941  case RELKIND_INDEX:
942  options = index_reloptions(amoptions, datum, false);
943  break;
945  options = NULL;
946  break;
947  default:
948  Assert(false); /* can't get here */
949  options = NULL; /* keep compiler quiet */
950  break;
951  }
952 
953  return options;
954 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1368
#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:167
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1336
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:166
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:374
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1404
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
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:435
#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 1198 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().

1202 {
1203  int i;
1204  int offset = basesize;
1205 
1206  for (i = 0; i < numoptions; i++)
1207  {
1208  int j;
1209  bool found = false;
1210 
1211  for (j = 0; j < numelems; j++)
1212  {
1213  if (pg_strcasecmp(options[i].gen->name, elems[j].optname) == 0)
1214  {
1215  relopt_string *optstring;
1216  char *itempos = ((char *) rdopts) + elems[j].offset;
1217  char *string_val;
1218 
1219  switch (options[i].gen->type)
1220  {
1221  case RELOPT_TYPE_BOOL:
1222  *(bool *) itempos = options[i].isset ?
1223  options[i].values.bool_val :
1224  ((relopt_bool *) options[i].gen)->default_val;
1225  break;
1226  case RELOPT_TYPE_INT:
1227  *(int *) itempos = options[i].isset ?
1228  options[i].values.int_val :
1229  ((relopt_int *) options[i].gen)->default_val;
1230  break;
1231  case RELOPT_TYPE_REAL:
1232  *(double *) itempos = options[i].isset ?
1233  options[i].values.real_val :
1234  ((relopt_real *) options[i].gen)->default_val;
1235  break;
1236  case RELOPT_TYPE_STRING:
1237  optstring = (relopt_string *) options[i].gen;
1238  if (options[i].isset)
1239  string_val = options[i].values.string_val;
1240  else if (!optstring->default_isnull)
1241  string_val = optstring->default_val;
1242  else
1243  string_val = NULL;
1244 
1245  if (string_val == NULL)
1246  *(int *) itempos = 0;
1247  else
1248  {
1249  strcpy((char *) rdopts + offset, string_val);
1250  *(int *) itempos = offset;
1251  offset += strlen(string_val) + 1;
1252  }
1253  break;
1254  default:
1255  elog(ERROR, "unsupported reloption type %d",
1256  options[i].gen->type);
1257  break;
1258  }
1259  found = true;
1260  break;
1261  }
1262  }
1263  if (validate && !found)
1264  elog(ERROR, "reloption \"%s\" not found in parse table",
1265  options[i].gen->name);
1266  }
1267  SET_VARSIZE(rdopts, offset);
1268 }
char * string_val
Definition: reloptions.h:82
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
union relopt_value::@40 values
#define ERROR
Definition: elog.h:43
const char * optname
Definition: reloptions.h:124
#define NULL
Definition: c.h:226
static Datum values[MAXATTR]
Definition: bootstrap.c:162
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#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 1368 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().

1369 {
1370  StdRdOptions *rdopts;
1371 
1372  switch (relkind)
1373  {
1374  case RELKIND_TOASTVALUE:
1375  rdopts = (StdRdOptions *)
1376  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1377  if (rdopts != NULL)
1378  {
1379  /* adjust default-only parameters for TOAST relations */
1380  rdopts->fillfactor = 100;
1381  rdopts->autovacuum.analyze_threshold = -1;
1382  rdopts->autovacuum.analyze_scale_factor = -1;
1383  }
1384  return (bytea *) rdopts;
1385  case RELKIND_RELATION:
1386  case RELKIND_MATVIEW:
1388  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1389  default:
1390  /* other relkinds are not supported */
1391  return NULL;
1392  }
1393 }
#define RELKIND_MATVIEW
Definition: pg_class.h:167
int fillfactor
Definition: rel.h:275
int analyze_threshold
Definition: rel.h:258
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
float8 analyze_scale_factor
Definition: rel.h:269
#define NULL
Definition: c.h:226
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1275
Definition: c.h:435
#define RELKIND_RELATION
Definition: pg_class.h:160
AutoVacOpts autovacuum
Definition: rel.h:276
bytea* index_reloptions ( amoptions_function  amoptions,
Datum  reloptions,
bool  validate 
)

Definition at line 1404 of file reloptions.c.

References Assert, DatumGetPointer, NULL, and PointerIsValid.

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

1405 {
1406  Assert(amoptions != NULL);
1407 
1408  /* Assume function is strict */
1409  if (!PointerIsValid(DatumGetPointer(reloptions)))
1410  return NULL;
1411 
1412  return amoptions(reloptions, validate);
1413 }
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define DatumGetPointer(X)
Definition: postgres.h:557
#define PointerIsValid(pointer)
Definition: c.h:522
static void initialize_reloptions ( void  )
static

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

401 {
402  int i;
403  int j;
404 
405  j = 0;
406  for (i = 0; boolRelOpts[i].gen.name; i++)
407  {
408  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
409  boolRelOpts[i].gen.lockmode));
410  j++;
411  }
412  for (i = 0; intRelOpts[i].gen.name; i++)
413  {
414  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
415  intRelOpts[i].gen.lockmode));
416  j++;
417  }
418  for (i = 0; realRelOpts[i].gen.name; i++)
419  {
420  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
421  realRelOpts[i].gen.lockmode));
422  j++;
423  }
424  for (i = 0; stringRelOpts[i].gen.name; i++)
425  {
426  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
428  j++;
429  }
430  j += num_custom_options;
431 
432  if (relOpts)
433  pfree(relOpts);
435  (j + 1) * sizeof(relopt_gen *));
436 
437  j = 0;
438  for (i = 0; boolRelOpts[i].gen.name; i++)
439  {
440  relOpts[j] = &boolRelOpts[i].gen;
442  relOpts[j]->namelen = strlen(relOpts[j]->name);
443  j++;
444  }
445 
446  for (i = 0; intRelOpts[i].gen.name; i++)
447  {
448  relOpts[j] = &intRelOpts[i].gen;
450  relOpts[j]->namelen = strlen(relOpts[j]->name);
451  j++;
452  }
453 
454  for (i = 0; realRelOpts[i].gen.name; i++)
455  {
456  relOpts[j] = &realRelOpts[i].gen;
458  relOpts[j]->namelen = strlen(relOpts[j]->name);
459  j++;
460  }
461 
462  for (i = 0; stringRelOpts[i].gen.name; i++)
463  {
464  relOpts[j] = &stringRelOpts[i].gen;
466  relOpts[j]->namelen = strlen(relOpts[j]->name);
467  j++;
468  }
469 
470  for (i = 0; i < num_custom_options; i++)
471  {
472  relOpts[j] = custom_options[i];
473  j++;
474  }
475 
476  /* add a list terminator */
477  relOpts[j] = NULL;
478 
479  /* flag the work is complete */
480  need_initialization = false;
481 }
static relopt_gen ** custom_options
Definition: reloptions.c:386
LOCKMODE lockmode
Definition: reloptions.h:67
static relopt_bool boolRelOpts[]
Definition: reloptions.c:57
relopt_gen gen
Definition: reloptions.h:114
void pfree(void *pointer)
Definition: mcxt.c:992
static int num_custom_options
Definition: reloptions.c:385
relopt_gen gen
Definition: reloptions.h:89
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:292
int namelen
Definition: reloptions.h:68
MemoryContext TopMemoryContext
Definition: mcxt.c:43
relopt_gen gen
Definition: reloptions.h:95
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
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:352
const char * name
Definition: reloptions.h:63
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:749
int i
static bool need_initialization
Definition: reloptions.c:387
static relopt_int intRelOpts[]
Definition: reloptions.c:99
static relopt_gen ** relOpts
Definition: reloptions.c:382
static void parse_one_reloption ( relopt_value option,
char *  text_str,
int  text_len,
bool  validate 
)
static

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

1074 {
1075  char *value;
1076  int value_len;
1077  bool parsed;
1078  bool nofree = false;
1079 
1080  if (option->isset && validate)
1081  ereport(ERROR,
1082  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1083  errmsg("parameter \"%s\" specified more than once",
1084  option->gen->name)));
1085 
1086  value_len = text_len - option->gen->namelen - 1;
1087  value = (char *) palloc(value_len + 1);
1088  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1089  value[value_len] = '\0';
1090 
1091  switch (option->gen->type)
1092  {
1093  case RELOPT_TYPE_BOOL:
1094  {
1095  parsed = parse_bool(value, &option->values.bool_val);
1096  if (validate && !parsed)
1097  ereport(ERROR,
1098  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1099  errmsg("invalid value for boolean option \"%s\": %s",
1100  option->gen->name, value)));
1101  }
1102  break;
1103  case RELOPT_TYPE_INT:
1104  {
1105  relopt_int *optint = (relopt_int *) option->gen;
1106 
1107  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1108  if (validate && !parsed)
1109  ereport(ERROR,
1110  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1111  errmsg("invalid value for integer option \"%s\": %s",
1112  option->gen->name, value)));
1113  if (validate && (option->values.int_val < optint->min ||
1114  option->values.int_val > optint->max))
1115  ereport(ERROR,
1116  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1117  errmsg("value %s out of bounds for option \"%s\"",
1118  value, option->gen->name),
1119  errdetail("Valid values are between \"%d\" and \"%d\".",
1120  optint->min, optint->max)));
1121  }
1122  break;
1123  case RELOPT_TYPE_REAL:
1124  {
1125  relopt_real *optreal = (relopt_real *) option->gen;
1126 
1127  parsed = parse_real(value, &option->values.real_val);
1128  if (validate && !parsed)
1129  ereport(ERROR,
1130  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1131  errmsg("invalid value for floating point option \"%s\": %s",
1132  option->gen->name, value)));
1133  if (validate && (option->values.real_val < optreal->min ||
1134  option->values.real_val > optreal->max))
1135  ereport(ERROR,
1136  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1137  errmsg("value %s out of bounds for option \"%s\"",
1138  value, option->gen->name),
1139  errdetail("Valid values are between \"%f\" and \"%f\".",
1140  optreal->min, optreal->max)));
1141  }
1142  break;
1143  case RELOPT_TYPE_STRING:
1144  {
1145  relopt_string *optstring = (relopt_string *) option->gen;
1146 
1147  option->values.string_val = value;
1148  nofree = true;
1149  if (validate && optstring->validate_cb)
1150  (optstring->validate_cb) (value);
1151  parsed = true;
1152  }
1153  break;
1154  default:
1155  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1156  parsed = true; /* quiet compiler */
1157  break;
1158  }
1159 
1160  if (parsed)
1161  option->isset = true;
1162  if (!nofree)
1163  pfree(value);
1164 }
bool bool_val
Definition: reloptions.h:79
static struct @76 value
char * string_val
Definition: reloptions.h:82
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
void pfree(void *pointer)
Definition: mcxt.c:992
union relopt_value::@40 values
#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:5540
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:5454
#define NULL
Definition: c.h:226
relopt_type type
Definition: reloptions.h:69
void * palloc(Size size)
Definition: mcxt.c:891
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 975 of file reloptions.c.

References DatumGetArrayTypeP, DatumGetPointer, DatumGetTextP, 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().

977 {
978  relopt_value *reloptions;
979  int numoptions = 0;
980  int i;
981  int j;
982 
985 
986  /* Build a list of expected options, based on kind */
987 
988  for (i = 0; relOpts[i]; i++)
989  if (relOpts[i]->kinds & kind)
990  numoptions++;
991 
992  if (numoptions == 0)
993  {
994  *numrelopts = 0;
995  return NULL;
996  }
997 
998  reloptions = palloc(numoptions * sizeof(relopt_value));
999 
1000  for (i = 0, j = 0; relOpts[i]; i++)
1001  {
1002  if (relOpts[i]->kinds & kind)
1003  {
1004  reloptions[j].gen = relOpts[i];
1005  reloptions[j].isset = false;
1006  j++;
1007  }
1008  }
1009 
1010  /* Done if no options */
1012  {
1014  Datum *optiondatums;
1015  int noptions;
1016 
1017  deconstruct_array(array, TEXTOID, -1, false, 'i',
1018  &optiondatums, NULL, &noptions);
1019 
1020  for (i = 0; i < noptions; i++)
1021  {
1022  text *optiontext = DatumGetTextP(optiondatums[i]);
1023  char *text_str = VARDATA(optiontext);
1024  int text_len = VARSIZE(optiontext) - VARHDRSZ;
1025  int j;
1026 
1027  /* Search for a match in reloptions */
1028  for (j = 0; j < numoptions; j++)
1029  {
1030  int kw_len = reloptions[j].gen->namelen;
1031 
1032  if (text_len > kw_len && text_str[kw_len] == '=' &&
1033  pg_strncasecmp(text_str, reloptions[j].gen->name,
1034  kw_len) == 0)
1035  {
1036  parse_one_reloption(&reloptions[j], text_str, text_len,
1037  validate);
1038  break;
1039  }
1040  }
1041 
1042  if (j >= numoptions && validate)
1043  {
1044  char *s;
1045  char *p;
1046 
1047  s = TextDatumGetCString(optiondatums[i]);
1048  p = strchr(s, '=');
1049  if (p)
1050  *p = '\0';
1051  ereport(ERROR,
1052  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1053  errmsg("unrecognized parameter \"%s\"", s)));
1054  }
1055  }
1056 
1057  /* It's worth avoiding memory leaks in this function */
1058  pfree(optiondatums);
1059  if (((void *) array) != DatumGetPointer(options))
1060  pfree(array);
1061  }
1062 
1063  *numrelopts = numoptions;
1064  return reloptions;
1065 }
static void initialize_reloptions(void)
Definition: reloptions.c:400
#define VARDATA(PTR)
Definition: postgres.h:305
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:306
#define VARHDRSZ
Definition: c.h:441
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:992
#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:1072
int namelen
Definition: reloptions.h:68
#define ereport(elevel, rest)
Definition: elog.h:122
#define TextDatumGetCString(d)
Definition: builtins.h:91
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define DatumGetTextP(X)
Definition: fmgr.h:248
#define DatumGetPointer(X)
Definition: postgres.h:557
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:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
static bool need_initialization
Definition: reloptions.c:387
Definition: c.h:435
static relopt_gen ** relOpts
Definition: reloptions.c:382
static size_t noptions
#define PointerIsValid(pointer)
Definition: c.h:522
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

1451 {
1453  TableSpaceOpts *tsopts;
1454  int numoptions;
1455  static const relopt_parse_elt tab[] = {
1456  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1457  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1458  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1459  };
1460 
1461  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1462  &numoptions);
1463 
1464  /* if none set, we're done */
1465  if (numoptions == 0)
1466  return NULL;
1467 
1468  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1469 
1470  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1471  validate, tab, lengthof(tab));
1472 
1473  pfree(options);
1474 
1475  return (bytea *) tsopts;
1476 }
#define lengthof(array)
Definition: c.h:558
int effective_io_concurrency
Definition: bufmgr.c:112
double random_page_cost
Definition: costsize.c:105
void pfree(void *pointer)
Definition: mcxt.c:992
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
double seq_page_cost
Definition: costsize.c:104
#define offsetof(type, field)
Definition: c.h:551
Datum transformRelOptions ( Datum  oldOptions,
List defList,
char *  namspace,
char *  validnsps[],
bool  ignoreOids,
bool  isReset 
)

Definition at line 700 of file reloptions.c.

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

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

702 {
703  Datum result;
704  ArrayBuildState *astate;
705  ListCell *cell;
706 
707  /* no change if empty list */
708  if (defList == NIL)
709  return oldOptions;
710 
711  /* We build new array using accumArrayResult */
712  astate = NULL;
713 
714  /* Copy any oldOptions that aren't to be replaced */
715  if (PointerIsValid(DatumGetPointer(oldOptions)))
716  {
717  ArrayType *array = DatumGetArrayTypeP(oldOptions);
718  Datum *oldoptions;
719  int noldoptions;
720  int i;
721 
722  deconstruct_array(array, TEXTOID, -1, false, 'i',
723  &oldoptions, NULL, &noldoptions);
724 
725  for (i = 0; i < noldoptions; i++)
726  {
727  text *oldoption = DatumGetTextP(oldoptions[i]);
728  char *text_str = VARDATA(oldoption);
729  int text_len = VARSIZE(oldoption) - VARHDRSZ;
730 
731  /* Search for a match in defList */
732  foreach(cell, defList)
733  {
734  DefElem *def = (DefElem *) lfirst(cell);
735  int kw_len;
736 
737  /* ignore if not in the same namespace */
738  if (namspace == NULL)
739  {
740  if (def->defnamespace != NULL)
741  continue;
742  }
743  else if (def->defnamespace == NULL)
744  continue;
745  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
746  continue;
747 
748  kw_len = strlen(def->defname);
749  if (text_len > kw_len && text_str[kw_len] == '=' &&
750  pg_strncasecmp(text_str, def->defname, kw_len) == 0)
751  break;
752  }
753  if (!cell)
754  {
755  /* No match, so keep old option */
756  astate = accumArrayResult(astate, oldoptions[i],
757  false, TEXTOID,
759  }
760  }
761  }
762 
763  /*
764  * If CREATE/SET, add new options to array; if RESET, just check that the
765  * user didn't say RESET (option=val). (Must do this because the grammar
766  * doesn't enforce it.)
767  */
768  foreach(cell, defList)
769  {
770  DefElem *def = (DefElem *) lfirst(cell);
771 
772  if (isReset)
773  {
774  if (def->arg != NULL)
775  ereport(ERROR,
776  (errcode(ERRCODE_SYNTAX_ERROR),
777  errmsg("RESET must not include values for parameters")));
778  }
779  else
780  {
781  text *t;
782  const char *value;
783  Size len;
784 
785  /*
786  * Error out if the namespace is not valid. A NULL namespace is
787  * always valid.
788  */
789  if (def->defnamespace != NULL)
790  {
791  bool valid = false;
792  int i;
793 
794  if (validnsps)
795  {
796  for (i = 0; validnsps[i]; i++)
797  {
798  if (pg_strcasecmp(def->defnamespace,
799  validnsps[i]) == 0)
800  {
801  valid = true;
802  break;
803  }
804  }
805  }
806 
807  if (!valid)
808  ereport(ERROR,
809  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
810  errmsg("unrecognized parameter namespace \"%s\"",
811  def->defnamespace)));
812  }
813 
814  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
815  continue;
816 
817  /* ignore if not in the same namespace */
818  if (namspace == NULL)
819  {
820  if (def->defnamespace != NULL)
821  continue;
822  }
823  else if (def->defnamespace == NULL)
824  continue;
825  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
826  continue;
827 
828  /*
829  * Flatten the DefElem into a text string like "name=arg". If we
830  * have just "name", assume "name=true" is meant. Note: the
831  * namespace is not output.
832  */
833  if (def->arg != NULL)
834  value = defGetString(def);
835  else
836  value = "true";
837  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
838  /* +1 leaves room for sprintf's trailing null */
839  t = (text *) palloc(len + 1);
840  SET_VARSIZE(t, len);
841  sprintf(VARDATA(t), "%s=%s", def->defname, value);
842 
843  astate = accumArrayResult(astate, PointerGetDatum(t),
844  false, TEXTOID,
846  }
847  }
848 
849  if (astate)
850  result = makeArrayResult(astate, CurrentMemoryContext);
851  else
852  result = (Datum) 0;
853 
854  return result;
855 }
#define NIL
Definition: pg_list.h:69
static struct @76 value
#define VARDATA(PTR)
Definition: postgres.h:305
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:306
#define PointerGetDatum(X)
Definition: postgres.h:564
#define VARHDRSZ
Definition: c.h:441
char * defnamespace
Definition: parsenodes.h:674
int errcode(int sqlerrcode)
Definition: elog.c:575
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
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:676
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
size_t Size
Definition: c.h:353
#define DatumGetTextP(X)
Definition: fmgr.h:248
#define DatumGetPointer(X)
Definition: postgres.h:557
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:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: c.h:435
char * defname
Definition: parsenodes.h:675
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#define PointerIsValid(pointer)
Definition: c.h:522
#define DatumGetArrayTypeP(X)
Definition: array.h:242
List* untransformRelOptions ( Datum  options)

Definition at line 863 of file reloptions.c.

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

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

864 {
865  List *result = NIL;
866  ArrayType *array;
867  Datum *optiondatums;
868  int noptions;
869  int i;
870 
871  /* Nothing to do if no options */
873  return result;
874 
875  array = DatumGetArrayTypeP(options);
876 
877  deconstruct_array(array, TEXTOID, -1, false, 'i',
878  &optiondatums, NULL, &noptions);
879 
880  for (i = 0; i < noptions; i++)
881  {
882  char *s;
883  char *p;
884  Node *val = NULL;
885 
886  s = TextDatumGetCString(optiondatums[i]);
887  p = strchr(s, '=');
888  if (p)
889  {
890  *p++ = '\0';
891  val = (Node *) makeString(pstrdup(p));
892  }
893  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
894  }
895 
896  return result;
897 }
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:1165
Definition: nodes.h:509
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:91
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define DatumGetPointer(X)
Definition: postgres.h:557
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:522
long val
Definition: informix.c:689
#define DatumGetArrayTypeP(X)
Definition: array.h:242
bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

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

1337 {
1339  ViewOptions *vopts;
1340  int numoptions;
1341  static const relopt_parse_elt tab[] = {
1342  {"security_barrier", RELOPT_TYPE_BOOL,
1343  offsetof(ViewOptions, security_barrier)},
1344  {"check_option", RELOPT_TYPE_STRING,
1345  offsetof(ViewOptions, check_option_offset)}
1346  };
1347 
1348  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1349 
1350  /* if none set, we're done */
1351  if (numoptions == 0)
1352  return NULL;
1353 
1354  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1355 
1356  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1357  validate, tab, lengthof(tab));
1358 
1359  pfree(options);
1360 
1361  return (bytea *) vopts;
1362 }
#define lengthof(array)
Definition: c.h:558
void pfree(void *pointer)
Definition: mcxt.c:992
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1174
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:1198
#define NULL
Definition: c.h:226
Definition: c.h:435
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:975
#define offsetof(type, field)
Definition: c.h:551

Variable Documentation

relopt_bool boolRelOpts[]
static

Definition at line 57 of file reloptions.c.

relopt_gen** custom_options = NULL
static

Definition at line 386 of file reloptions.c.

relopt_int intRelOpts[]
static

Definition at line 99 of file reloptions.c.

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

Definition at line 383 of file reloptions.c.

Referenced by add_reloption_kind().

bool need_initialization = true
static
int num_custom_options = 0
static

Definition at line 385 of file reloptions.c.

Referenced by add_reloption(), and initialize_reloptions().

relopt_real realRelOpts[]
static

Definition at line 292 of file reloptions.c.

relopt_gen** relOpts = NULL
static

Definition at line 382 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:226
#define AccessExclusiveLock
Definition: lockdefs.h:46

Definition at line 352 of file reloptions.c.