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

Macros

#define GET_STRING_RELOPTION_LEN(option)
 

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)
 
void init_local_reloptions (local_relopts *opts, Size relopt_struct_size)
 
void register_reloptions_validator (local_relopts *opts, relopts_validator validator)
 
static void add_local_reloption (local_relopts *relopts, relopt_gen *newoption, int offset)
 
static relopt_genallocate_reloption (bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
 
static relopt_boolinit_bool_reloption (bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
 
void add_bool_reloption (bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
 
void add_local_bool_reloption (local_relopts *relopts, const char *name, const char *desc, bool default_val, int offset)
 
static relopt_intinit_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
 
void add_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
 
void add_local_int_reloption (local_relopts *relopts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)
 
static relopt_realinit_real_reloption (bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
 
void add_real_reloption (bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
 
void add_local_real_reloption (local_relopts *relopts, const char *name, const char *desc, double default_val, double min_val, double max_val, int offset)
 
static relopt_enuminit_enum_reloption (bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
 
void add_enum_reloption (bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
 
void add_local_enum_reloption (local_relopts *relopts, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, int offset)
 
static relopt_stringinit_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, LOCKMODE lockmode)
 
void add_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
 
void add_local_string_reloption (local_relopts *relopts, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, int offset)
 
Datum transformRelOptions (Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
 
ListuntransformRelOptions (Datum options)
 
byteaextractRelOptions (HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
 
static void parseRelOptionsInternal (Datum options, bool validate, relopt_value *reloptions, int numoptions)
 
static relopt_valueparseRelOptions (Datum options, bool validate, relopt_kind kind, int *numrelopts)
 
static relopt_valueparseLocalRelOptions (local_relopts *relopts, Datum options, bool validate)
 
static void * allocateReloptStruct (Size base, relopt_value *options, int numoptions)
 
static 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)
 
void * build_reloptions (Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
 
void * build_local_reloptions (local_relopts *relopts, Datum options, bool validate)
 
byteapartitioned_table_reloptions (Datum reloptions, bool validate)
 
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 []
 
relopt_enum_elt_def gistBufferingOptValues []
 
relopt_enum_elt_def viewCheckOptValues []
 
static relopt_enum enumRelOpts []
 
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
 

Macro Definition Documentation

◆ GET_STRING_RELOPTION_LEN

#define GET_STRING_RELOPTION_LEN (   option)
Value:
((option).isset ? strlen((option).values.string_val) : \
((relopt_string *) (option).gen)->default_len)

Definition at line 545 of file reloptions.c.

Referenced by allocateReloptStruct().

Function Documentation

◆ add_bool_reloption()

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

Definition at line 825 of file reloptions.c.

References add_reloption(), and init_bool_reloption().

Referenced by create_reloptions_table().

827 {
828  relopt_bool *newoption = init_bool_reloption(kinds, name, desc,
829  default_val, lockmode);
830 
831  add_reloption((relopt_gen *) newoption);
832 }
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:808

◆ add_enum_reloption()

void add_enum_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
relopt_enum_elt_def members,
int  default_val,
const char *  detailmsg,
LOCKMODE  lockmode 
)

Definition at line 994 of file reloptions.c.

References add_reloption(), and init_enum_reloption().

Referenced by create_reloptions_table().

997 {
998  relopt_enum *newoption = init_enum_reloption(kinds, name, desc,
999  members, default_val,
1000  detailmsg, lockmode);
1001 
1002  add_reloption((relopt_gen *) newoption);
1003 }
static relopt_enum * init_enum_reloption(bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
Definition: reloptions.c:965
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561

◆ add_int_reloption()

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

Definition at line 877 of file reloptions.c.

References add_reloption(), and init_int_reloption().

Referenced by _PG_init(), and create_reloptions_table().

879 {
880  relopt_int *newoption = init_int_reloption(kinds, name, desc,
881  default_val, min_val,
882  max_val, lockmode);
883 
884  add_reloption((relopt_gen *) newoption);
885 }
static relopt_int * init_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:857
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561

◆ add_local_bool_reloption()

void add_local_bool_reloption ( local_relopts relopts,
const char *  name,
const char *  desc,
bool  default_val,
int  offset 
)

Definition at line 841 of file reloptions.c.

References add_local_reloption(), init_bool_reloption(), and RELOPT_KIND_LOCAL.

843 {
845  name, desc,
846  default_val, 0);
847 
848  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
849 }
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:808

◆ add_local_enum_reloption()

void add_local_enum_reloption ( local_relopts relopts,
const char *  name,
const char *  desc,
relopt_enum_elt_def members,
int  default_val,
const char *  detailmsg,
int  offset 
)

Definition at line 1012 of file reloptions.c.

References add_local_reloption(), init_enum_reloption(), and RELOPT_KIND_LOCAL.

1015 {
1017  name, desc,
1018  members, default_val,
1019  detailmsg, 0);
1020 
1021  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1022 }
static relopt_enum * init_enum_reloption(bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
Definition: reloptions.c:965
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561

◆ add_local_int_reloption()

void add_local_int_reloption ( local_relopts relopts,
const char *  name,
const char *  desc,
int  default_val,
int  min_val,
int  max_val,
int  offset 
)

Definition at line 894 of file reloptions.c.

References add_local_reloption(), init_int_reloption(), and RELOPT_KIND_LOCAL.

Referenced by _ltree_gist_options(), g_int_options(), g_intbig_options(), ghstore_options(), gtrgm_options(), gtsvector_options(), and ltree_gist_options().

897 {
899  name, desc, default_val,
900  min_val, max_val, 0);
901 
902  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
903 }
static relopt_int * init_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:857
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561

◆ add_local_real_reloption()

void add_local_real_reloption ( local_relopts relopts,
const char *  name,
const char *  desc,
double  default_val,
double  min_val,
double  max_val,
int  offset 
)

Definition at line 948 of file reloptions.c.

References add_local_reloption(), init_real_reloption(), and RELOPT_KIND_LOCAL.

951 {
953  name, desc,
954  default_val, min_val,
955  max_val, 0);
956 
957  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
958 }
static relopt_real * init_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:910
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
const char * name
Definition: encode.c:561

◆ add_local_reloption()

static void add_local_reloption ( local_relopts relopts,
relopt_gen newoption,
int  offset 
)
static

Definition at line 733 of file reloptions.c.

References Assert, lappend(), local_relopt::offset, local_relopt::option, local_relopts::options, and palloc().

Referenced by add_local_bool_reloption(), add_local_enum_reloption(), add_local_int_reloption(), add_local_real_reloption(), and add_local_string_reloption().

734 {
735  local_relopt *opt = palloc(sizeof(*opt));
736 
737  Assert(offset < relopts->relopt_struct_size);
738 
739  opt->option = newoption;
740  opt->offset = offset;
741 
742  relopts->options = lappend(relopts->options, opt);
743 }
List * options
Definition: reloptions.h:167
relopt_gen * option
Definition: reloptions.h:160
List * lappend(List *list, void *datum)
Definition: list.c:321
#define Assert(condition)
Definition: c.h:738
void * palloc(Size size)
Definition: mcxt.c:949

◆ add_local_string_reloption()

void add_local_string_reloption ( local_relopts relopts,
const char *  name,
const char *  desc,
const char *  default_val,
validate_string_relopt  validator,
fill_string_relopt  filler,
int  offset 
)

Definition at line 1094 of file reloptions.c.

References add_local_reloption(), init_string_reloption(), and RELOPT_KIND_LOCAL.

1098 {
1100  name, desc,
1101  default_val,
1102  validator, filler,
1103  0);
1104 
1105  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1106 }
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:733
static relopt_string * init_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, LOCKMODE lockmode)
Definition: reloptions.c:1029
const char * name
Definition: encode.c:561

◆ add_real_reloption()

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

Definition at line 930 of file reloptions.c.

References add_reloption(), and init_real_reloption().

Referenced by create_reloptions_table().

933 {
934  relopt_real *newoption = init_real_reloption(kinds, name, desc,
935  default_val, min_val,
936  max_val, lockmode);
937 
938  add_reloption((relopt_gen *) newoption);
939 }
static relopt_real * init_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:910
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
const char * name
Definition: encode.c:561

◆ add_reloption()

static void add_reloption ( relopt_gen newoption)
static

Definition at line 676 of file reloptions.c.

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

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

677 {
678  static int max_custom_options = 0;
679 
680  if (num_custom_options >= max_custom_options)
681  {
682  MemoryContext oldcxt;
683 
685 
686  if (max_custom_options == 0)
687  {
688  max_custom_options = 8;
689  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
690  }
691  else
692  {
693  max_custom_options *= 2;
695  max_custom_options * sizeof(relopt_gen *));
696  }
697  MemoryContextSwitchTo(oldcxt);
698  }
699  custom_options[num_custom_options++] = newoption;
700 
701  need_initialization = true;
702 }
static relopt_gen ** custom_options
Definition: reloptions.c:533
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static int num_custom_options
Definition: reloptions.c:532
MemoryContext TopMemoryContext
Definition: mcxt.c:44
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1069
void * palloc(Size size)
Definition: mcxt.c:949
static bool need_initialization
Definition: reloptions.c:534

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 659 of file reloptions.c.

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

Referenced by _PG_init(), and create_reloptions_table().

660 {
661  /* don't hand out the last bit so that the enum's behavior is portable */
663  ereport(ERROR,
664  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
665  errmsg("user-defined relation parameter types limit exceeded")));
666  last_assigned_kind <<= 1;
668 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
relopt_kind
Definition: reloptions.h:39
static bits32 last_assigned_kind
Definition: reloptions.c:530

◆ add_string_reloption()

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

Definition at line 1074 of file reloptions.c.

References add_reloption(), and init_string_reloption().

Referenced by create_reloptions_table().

1077 {
1078  relopt_string *newoption = init_string_reloption(kinds, name, desc,
1079  default_val,
1080  validator, NULL,
1081  lockmode);
1082 
1083  add_reloption((relopt_gen *) newoption);
1084 }
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:676
static relopt_string * init_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, LOCKMODE lockmode)
Definition: reloptions.c:1029
const char * name
Definition: encode.c:561

◆ allocate_reloption()

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

Definition at line 751 of file reloptions.c.

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

Referenced by init_bool_reloption(), init_enum_reloption(), init_int_reloption(), init_real_reloption(), and init_string_reloption().

753 {
754  MemoryContext oldcxt;
755  size_t size;
756  relopt_gen *newoption;
757 
758  if (kinds != RELOPT_KIND_LOCAL)
760  else
761  oldcxt = NULL;
762 
763  switch (type)
764  {
765  case RELOPT_TYPE_BOOL:
766  size = sizeof(relopt_bool);
767  break;
768  case RELOPT_TYPE_INT:
769  size = sizeof(relopt_int);
770  break;
771  case RELOPT_TYPE_REAL:
772  size = sizeof(relopt_real);
773  break;
774  case RELOPT_TYPE_ENUM:
775  size = sizeof(relopt_enum);
776  break;
777  case RELOPT_TYPE_STRING:
778  size = sizeof(relopt_string);
779  break;
780  default:
781  elog(ERROR, "unsupported reloption type %d", type);
782  return NULL; /* keep compiler quiet */
783  }
784 
785  newoption = palloc(size);
786 
787  newoption->name = pstrdup(name);
788  if (desc)
789  newoption->desc = pstrdup(desc);
790  else
791  newoption->desc = NULL;
792  newoption->kinds = kinds;
793  newoption->namelen = strlen(name);
794  newoption->type = type;
795  newoption->lockmode = lockmode;
796 
797  if (oldcxt != NULL)
798  MemoryContextSwitchTo(oldcxt);
799 
800  return newoption;
801 }
struct relopt_string relopt_string
const char * desc
Definition: reloptions.h:68
struct relopt_enum relopt_enum
LOCKMODE lockmode
Definition: reloptions.h:70
char * pstrdup(const char *in)
Definition: mcxt.c:1186
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:71
MemoryContext TopMemoryContext
Definition: mcxt.c:44
bits32 kinds
Definition: reloptions.h:69
relopt_type type
Definition: reloptions.h:72
struct relopt_int relopt_int
const char * name
Definition: encode.c:561
void * palloc(Size size)
Definition: mcxt.c:949
const char * name
Definition: reloptions.h:66
#define elog(elevel,...)
Definition: elog.h:214

◆ allocateReloptStruct()

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

Definition at line 1681 of file reloptions.c.

References relopt_string::default_isnull, relopt_string::default_val, relopt_string::fill_cb, relopt_value::gen, GET_STRING_RELOPTION_LEN, i, relopt_value::isset, palloc0(), RELOPT_TYPE_STRING, relopt_value::string_val, relopt_gen::type, val, and relopt_value::values.

Referenced by build_local_reloptions(), and build_reloptions().

1682 {
1683  Size size = base;
1684  int i;
1685 
1686  for (i = 0; i < numoptions; i++)
1687  {
1688  relopt_value *optval = &options[i];
1689 
1690  if (optval->gen->type == RELOPT_TYPE_STRING)
1691  {
1692  relopt_string *optstr = (relopt_string *) optval->gen;
1693 
1694  if (optstr->fill_cb)
1695  {
1696  const char *val = optval->isset ? optval->values.string_val :
1697  optstr->default_isnull ? NULL : optstr->default_val;
1698 
1699  size += optstr->fill_cb(val, NULL);
1700  }
1701  else
1702  size += GET_STRING_RELOPTION_LEN(*optval) + 1;
1703  }
1704  }
1705 
1706  return palloc0(size);
1707 }
union relopt_value::@46 values
char * string_val
Definition: reloptions.h:86
bool default_isnull
Definition: reloptions.h:143
relopt_gen * gen
Definition: reloptions.h:78
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.c:545
void * palloc0(Size size)
Definition: mcxt.c:980
relopt_type type
Definition: reloptions.h:72
size_t Size
Definition: c.h:466
fill_string_relopt fill_cb
Definition: reloptions.h:145
int i
char * default_val
Definition: reloptions.h:146
long val
Definition: informix.c:664

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 2085 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

2086 {
2087  LOCKMODE lockmode = NoLock;
2088  ListCell *cell;
2089 
2090  if (defList == NIL)
2091  return AccessExclusiveLock;
2092 
2093  if (need_initialization)
2095 
2096  foreach(cell, defList)
2097  {
2098  DefElem *def = (DefElem *) lfirst(cell);
2099  int i;
2100 
2101  for (i = 0; relOpts[i]; i++)
2102  {
2103  if (strncmp(relOpts[i]->name,
2104  def->defname,
2105  relOpts[i]->namelen + 1) == 0)
2106  {
2107  if (lockmode < relOpts[i]->lockmode)
2108  lockmode = relOpts[i]->lockmode;
2109  }
2110  }
2111  }
2112 
2113  return lockmode;
2114 }
#define NIL
Definition: pg_list.h:65
static void initialize_reloptions(void)
Definition: reloptions.c:556
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:70
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h:71
#define lfirst(lc)
Definition: pg_list.h:190
const char * name
Definition: encode.c:561
#define AccessExclusiveLock
Definition: lockdefs.h:45
int i
static bool need_initialization
Definition: reloptions.c:534
char * defname
Definition: parsenodes.h:732
static relopt_gen ** relOpts
Definition: reloptions.c:529

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2046 of file reloptions.c.

References build_reloptions(), lengthof, offsetof, RELOPT_KIND_ATTRIBUTE, and RELOPT_TYPE_REAL.

Referenced by ATExecSetOptions(), and get_attribute_options().

2047 {
2048  static const relopt_parse_elt tab[] = {
2049  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2050  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2051  };
2052 
2053  return (bytea *) build_reloptions(reloptions, validate,
2055  sizeof(AttributeOpts),
2056  tab, lengthof(tab));
2057 }
#define lengthof(array)
Definition: c.h:668
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1887
Definition: c.h:555
#define offsetof(type, field)
Definition: c.h:661

◆ build_local_reloptions()

void* build_local_reloptions ( local_relopts relopts,
Datum  options,
bool  validate 
)

Definition at line 1924 of file reloptions.c.

References allocateReloptStruct(), fillRelOptions(), i, lfirst, list_length(), relopt_gen::name, noptions, relopt_parse_elt::offset, local_relopt::offset, local_relopt::option, local_relopts::options, relopt_parse_elt::optname, relopt_parse_elt::opttype, palloc(), parseLocalRelOptions(), pfree(), local_relopts::relopt_struct_size, relopt_gen::type, and local_relopts::validators.

Referenced by index_opclass_options().

1925 {
1926  int noptions = list_length(relopts->options);
1927  relopt_parse_elt *elems = palloc(sizeof(*elems) * noptions);
1928  relopt_value *vals;
1929  void *opts;
1930  int i = 0;
1931  ListCell *lc;
1932 
1933  foreach(lc, relopts->options)
1934  {
1935  local_relopt *opt = lfirst(lc);
1936 
1937  elems[i].optname = opt->option->name;
1938  elems[i].opttype = opt->option->type;
1939  elems[i].offset = opt->offset;
1940 
1941  i++;
1942  }
1943 
1944  vals = parseLocalRelOptions(relopts, options, validate);
1945  opts = allocateReloptStruct(relopts->relopt_struct_size, vals, noptions);
1946  fillRelOptions(opts, relopts->relopt_struct_size, vals, noptions, validate,
1947  elems, noptions);
1948 
1949  foreach(lc, relopts->validators)
1950  ((relopts_validator) lfirst(lc)) (opts, vals, noptions);
1951 
1952  if (elems)
1953  pfree(elems);
1954 
1955  return opts;
1956 }
static relopt_value * parseLocalRelOptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1520
relopt_type opttype
Definition: reloptions.h:153
List * validators
Definition: reloptions.h:168
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1681
List * options
Definition: reloptions.h:167
void pfree(void *pointer)
Definition: mcxt.c:1056
Size relopt_struct_size
Definition: reloptions.h:169
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1721
relopt_gen * option
Definition: reloptions.h:160
const char * optname
Definition: reloptions.h:152
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition: reloptions.h:137
#define lfirst(lc)
Definition: pg_list.h:190
relopt_type type
Definition: reloptions.h:72
static int list_length(const List *l)
Definition: pg_list.h:169
void * palloc(Size size)
Definition: mcxt.c:949
const char * name
Definition: reloptions.h:66
int i
static size_t noptions

◆ build_reloptions()

void* build_reloptions ( Datum  reloptions,
bool  validate,
relopt_kind  kind,
Size  relopt_struct_size,
const relopt_parse_elt relopt_elems,
int  num_relopt_elems 
)

Definition at line 1887 of file reloptions.c.

References allocateReloptStruct(), Assert, fillRelOptions(), options, parseRelOptions(), and pfree().

Referenced by attribute_reloptions(), bloptions(), brinoptions(), btoptions(), default_reloptions(), dioptions(), ginoptions(), gistoptions(), hashoptions(), partitioned_table_reloptions(), spgoptions(), tablespace_reloptions(), and view_reloptions().

1892 {
1893  int numoptions;
1895  void *rdopts;
1896 
1897  /* parse options specific to given relation option kind */
1898  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1899  Assert(numoptions <= num_relopt_elems);
1900 
1901  /* if none set, we're done */
1902  if (numoptions == 0)
1903  {
1904  Assert(options == NULL);
1905  return NULL;
1906  }
1907 
1908  /* allocate and fill the structure */
1909  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1910  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1911  validate, relopt_elems, num_relopt_elems);
1912 
1913  pfree(options);
1914 
1915  return rdopts;
1916 }
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1681
void pfree(void *pointer)
Definition: mcxt.c:1056
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1721
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1478
static char ** options
#define Assert(condition)
Definition: c.h:738

◆ default_reloptions()

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

Definition at line 1817 of file reloptions.c.

References build_reloptions(), fillfactor, lengthof, offsetof, RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, and RELOPT_TYPE_REAL.

Referenced by heap_reloptions().

1818 {
1819  static const relopt_parse_elt tab[] = {
1820  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1821  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1822  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1823  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1824  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1825  {"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT,
1826  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)},
1827  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1828  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1829  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1830  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1831  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1832  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1833  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1834  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1835  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1836  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1837  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1838  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1839  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1840  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1841  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1842  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1843  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1844  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1845  {"toast_tuple_target", RELOPT_TYPE_INT,
1846  offsetof(StdRdOptions, toast_tuple_target)},
1847  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1848  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1849  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1850  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1851  {"autovacuum_vacuum_insert_scale_factor", RELOPT_TYPE_REAL,
1852  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
1853  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1854  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1855  {"user_catalog_table", RELOPT_TYPE_BOOL,
1856  offsetof(StdRdOptions, user_catalog_table)},
1857  {"parallel_workers", RELOPT_TYPE_INT,
1858  offsetof(StdRdOptions, parallel_workers)},
1859  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1860  offsetof(StdRdOptions, vacuum_index_cleanup)},
1861  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1862  offsetof(StdRdOptions, vacuum_truncate)}
1863  };
1864 
1865  return (bytea *) build_reloptions(reloptions, validate, kind,
1866  sizeof(StdRdOptions),
1867  tab, lengthof(tab));
1868 }
#define lengthof(array)
Definition: c.h:668
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1887
int fillfactor
Definition: pgbench.c:159
Definition: c.h:555
#define offsetof(type, field)
Definition: c.h:661

◆ extractRelOptions()

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

Definition at line 1357 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

1359 {
1360  bytea *options;
1361  bool isnull;
1362  Datum datum;
1363  Form_pg_class classForm;
1364 
1365  datum = fastgetattr(tuple,
1366  Anum_pg_class_reloptions,
1367  tupdesc,
1368  &isnull);
1369  if (isnull)
1370  return NULL;
1371 
1372  classForm = (Form_pg_class) GETSTRUCT(tuple);
1373 
1374  /* Parse into appropriate format; don't error out here */
1375  switch (classForm->relkind)
1376  {
1377  case RELKIND_RELATION:
1378  case RELKIND_TOASTVALUE:
1379  case RELKIND_MATVIEW:
1380  options = heap_reloptions(classForm->relkind, datum, false);
1381  break;
1382  case RELKIND_PARTITIONED_TABLE:
1383  options = partitioned_table_reloptions(datum, false);
1384  break;
1385  case RELKIND_VIEW:
1386  options = view_reloptions(datum, false);
1387  break;
1388  case RELKIND_INDEX:
1389  case RELKIND_PARTITIONED_INDEX:
1390  options = index_reloptions(amoptions, datum, false);
1391  break;
1392  case RELKIND_FOREIGN_TABLE:
1393  options = NULL;
1394  break;
1395  default:
1396  Assert(false); /* can't get here */
1397  options = NULL; /* keep compiler quiet */
1398  break;
1399  }
1400 
1401  return options;
1402 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1996
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:712
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1977
static char ** options
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1962
uintptr_t Datum
Definition: postgres.h:367
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:2031
#define Assert(condition)
Definition: c.h:738
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
Definition: c.h:555

◆ fillRelOptions()

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

Definition at line 1721 of file reloptions.c.

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

Referenced by build_local_reloptions(), and build_reloptions().

1725 {
1726  int i;
1727  int offset = basesize;
1728 
1729  for (i = 0; i < numoptions; i++)
1730  {
1731  int j;
1732  bool found = false;
1733 
1734  for (j = 0; j < numelems; j++)
1735  {
1736  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1737  {
1738  relopt_string *optstring;
1739  char *itempos = ((char *) rdopts) + elems[j].offset;
1740  char *string_val;
1741 
1742  switch (options[i].gen->type)
1743  {
1744  case RELOPT_TYPE_BOOL:
1745  *(bool *) itempos = options[i].isset ?
1746  options[i].values.bool_val :
1747  ((relopt_bool *) options[i].gen)->default_val;
1748  break;
1749  case RELOPT_TYPE_INT:
1750  *(int *) itempos = options[i].isset ?
1751  options[i].values.int_val :
1752  ((relopt_int *) options[i].gen)->default_val;
1753  break;
1754  case RELOPT_TYPE_REAL:
1755  *(double *) itempos = options[i].isset ?
1756  options[i].values.real_val :
1757  ((relopt_real *) options[i].gen)->default_val;
1758  break;
1759  case RELOPT_TYPE_ENUM:
1760  *(int *) itempos = options[i].isset ?
1761  options[i].values.enum_val :
1762  ((relopt_enum *) options[i].gen)->default_val;
1763  break;
1764  case RELOPT_TYPE_STRING:
1765  optstring = (relopt_string *) options[i].gen;
1766  if (options[i].isset)
1767  string_val = options[i].values.string_val;
1768  else if (!optstring->default_isnull)
1769  string_val = optstring->default_val;
1770  else
1771  string_val = NULL;
1772 
1773  if (optstring->fill_cb)
1774  {
1775  Size size =
1776  optstring->fill_cb(string_val,
1777  (char *) rdopts + offset);
1778 
1779  if (size)
1780  {
1781  *(int *) itempos = offset;
1782  offset += size;
1783  }
1784  else
1785  *(int *) itempos = 0;
1786  }
1787  else if (string_val == NULL)
1788  *(int *) itempos = 0;
1789  else
1790  {
1791  strcpy((char *) rdopts + offset, string_val);
1792  *(int *) itempos = offset;
1793  offset += strlen(string_val) + 1;
1794  }
1795  break;
1796  default:
1797  elog(ERROR, "unsupported reloption type %d",
1798  options[i].gen->type);
1799  break;
1800  }
1801  found = true;
1802  break;
1803  }
1804  }
1805  if (validate && !found)
1806  elog(ERROR, "reloption \"%s\" not found in parse table",
1807  options[i].gen->name);
1808  }
1809  SET_VARSIZE(rdopts, offset);
1810 }
union relopt_value::@46 values
char * string_val
Definition: reloptions.h:86
bool default_isnull
Definition: reloptions.h:143
relopt_gen * gen
Definition: reloptions.h:78
#define ERROR
Definition: elog.h:43
const char * optname
Definition: reloptions.h:152
size_t Size
Definition: c.h:466
static Datum values[MAXATTR]
Definition: bootstrap.c:167
fill_string_relopt fill_cb
Definition: reloptions.h:145
#define elog(elevel,...)
Definition: elog.h:214
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
char * default_val
Definition: reloptions.h:146

◆ heap_reloptions()

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

Definition at line 1996 of file reloptions.c.

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

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

1997 {
1998  StdRdOptions *rdopts;
1999 
2000  switch (relkind)
2001  {
2002  case RELKIND_TOASTVALUE:
2003  rdopts = (StdRdOptions *)
2004  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
2005  if (rdopts != NULL)
2006  {
2007  /* adjust default-only parameters for TOAST relations */
2008  rdopts->fillfactor = 100;
2009  rdopts->autovacuum.analyze_threshold = -1;
2010  rdopts->autovacuum.analyze_scale_factor = -1;
2011  }
2012  return (bytea *) rdopts;
2013  case RELKIND_RELATION:
2014  case RELKIND_MATVIEW:
2015  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
2016  default:
2017  /* other relkinds are not supported */
2018  return NULL;
2019  }
2020 }
int fillfactor
Definition: rel.h:300
int analyze_threshold
Definition: rel.h:282
float8 analyze_scale_factor
Definition: rel.h:294
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1817
Definition: c.h:555
AutoVacOpts autovacuum
Definition: rel.h:303

◆ index_reloptions()

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

Definition at line 2031 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

2032 {
2033  Assert(amoptions != NULL);
2034 
2035  /* Assume function is strict */
2036  if (!PointerIsValid(DatumGetPointer(reloptions)))
2037  return NULL;
2038 
2039  return amoptions(reloptions, validate);
2040 }
#define Assert(condition)
Definition: c.h:738
#define DatumGetPointer(X)
Definition: postgres.h:549
#define PointerIsValid(pointer)
Definition: c.h:632

◆ init_bool_reloption()

static relopt_bool* init_bool_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
bool  default_val,
LOCKMODE  lockmode 
)
static

Definition at line 808 of file reloptions.c.

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

Referenced by add_bool_reloption(), and add_local_bool_reloption().

810 {
811  relopt_bool *newoption;
812 
813  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
814  name, desc, lockmode);
815  newoption->default_val = default_val;
816 
817  return newoption;
818 }
bool default_val
Definition: reloptions.h:94
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:751
const char * name
Definition: encode.c:561

◆ init_enum_reloption()

static relopt_enum* init_enum_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
relopt_enum_elt_def members,
int  default_val,
const char *  detailmsg,
LOCKMODE  lockmode 
)
static

Definition at line 965 of file reloptions.c.

References allocate_reloption(), relopt_enum::default_val, relopt_enum::detailmsg, relopt_enum::members, and RELOPT_TYPE_ENUM.

Referenced by add_enum_reloption(), and add_local_enum_reloption().

968 {
969  relopt_enum *newoption;
970 
971  newoption = (relopt_enum *) allocate_reloption(kinds, RELOPT_TYPE_ENUM,
972  name, desc, lockmode);
973  newoption->members = members;
974  newoption->default_val = default_val;
975  newoption->detailmsg = detailmsg;
976 
977  return newoption;
978 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:751
const char * detailmsg
Definition: reloptions.h:128
relopt_enum_elt_def * members
Definition: reloptions.h:126
int default_val
Definition: reloptions.h:127
const char * name
Definition: encode.c:561

◆ init_int_reloption()

static relopt_int* init_int_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
int  default_val,
int  min_val,
int  max_val,
LOCKMODE  lockmode 
)
static

Definition at line 857 of file reloptions.c.

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

Referenced by add_int_reloption(), and add_local_int_reloption().

860 {
861  relopt_int *newoption;
862 
863  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
864  name, desc, lockmode);
865  newoption->default_val = default_val;
866  newoption->min = min_val;
867  newoption->max = max_val;
868 
869  return newoption;
870 }
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:751
const char * name
Definition: encode.c:561
int default_val
Definition: reloptions.h:100

◆ init_local_reloptions()

void init_local_reloptions ( local_relopts opts,
Size  relopt_struct_size 
)

Definition at line 710 of file reloptions.c.

References NIL, local_relopts::options, local_relopts::relopt_struct_size, and local_relopts::validators.

Referenced by _ltree_gist_options(), g_int_options(), g_intbig_options(), ghstore_options(), gtrgm_options(), gtsvector_options(), index_opclass_options(), and ltree_gist_options().

711 {
712  opts->options = NIL;
713  opts->validators = NIL;
714  opts->relopt_struct_size = relopt_struct_size;
715 }
#define NIL
Definition: pg_list.h:65
List * validators
Definition: reloptions.h:168
List * options
Definition: reloptions.h:167
Size relopt_struct_size
Definition: reloptions.h:169

◆ init_real_reloption()

static relopt_real* init_real_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
double  default_val,
double  min_val,
double  max_val,
LOCKMODE  lockmode 
)
static

Definition at line 910 of file reloptions.c.

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

Referenced by add_local_real_reloption(), and add_real_reloption().

913 {
914  relopt_real *newoption;
915 
916  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
917  name, desc, lockmode);
918  newoption->default_val = default_val;
919  newoption->min = min_val;
920  newoption->max = max_val;
921 
922  return newoption;
923 }
double default_val
Definition: reloptions.h:108
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:751
const char * name
Definition: encode.c:561
double max
Definition: reloptions.h:110
double min
Definition: reloptions.h:109

◆ init_string_reloption()

static relopt_string* init_string_reloption ( bits32  kinds,
const char *  name,
const char *  desc,
const char *  default_val,
validate_string_relopt  validator,
fill_string_relopt  filler,
LOCKMODE  lockmode 
)
static

Definition at line 1029 of file reloptions.c.

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

Referenced by add_local_string_reloption(), and add_string_reloption().

1034 {
1035  relopt_string *newoption;
1036 
1037  /* make sure the validator/default combination is sane */
1038  if (validator)
1039  (validator) (default_val);
1040 
1041  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
1042  name, desc, lockmode);
1043  newoption->validate_cb = validator;
1044  newoption->fill_cb = filler;
1045  if (default_val)
1046  {
1047  if (kinds == RELOPT_KIND_LOCAL)
1048  newoption->default_val = strdup(default_val);
1049  else
1050  newoption->default_val = MemoryContextStrdup(TopMemoryContext, default_val);
1051  newoption->default_len = strlen(default_val);
1052  newoption->default_isnull = false;
1053  }
1054  else
1055  {
1056  newoption->default_val = "";
1057  newoption->default_len = 0;
1058  newoption->default_isnull = true;
1059  }
1060 
1061  return newoption;
1062 }
bool default_isnull
Definition: reloptions.h:143
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:751
validate_string_relopt validate_cb
Definition: reloptions.h:144
MemoryContext TopMemoryContext
Definition: mcxt.c:44
const char * name
Definition: encode.c:561
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1173
fill_string_relopt fill_cb
Definition: reloptions.h:145
char * default_val
Definition: reloptions.h:146

◆ initialize_reloptions()

static void initialize_reloptions ( void  )
static

Definition at line 556 of file reloptions.c.

References Assert, DoLockModesConflict(), relopt_bool::gen, relopt_int::gen, relopt_real::gen, relopt_enum::gen, relopt_string::gen, i, relopt_gen::lockmode, MemoryContextAlloc(), relopt_gen::name, name, relopt_gen::namelen, need_initialization, num_custom_options, pfree(), RELOPT_TYPE_BOOL, RELOPT_TYPE_ENUM, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, TopMemoryContext, and relopt_gen::type.

Referenced by AlterTableGetRelOptionsLockLevel(), and parseRelOptions().

557 {
558  int i;
559  int j;
560 
561  j = 0;
562  for (i = 0; boolRelOpts[i].gen.name; i++)
563  {
564  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
565  boolRelOpts[i].gen.lockmode));
566  j++;
567  }
568  for (i = 0; intRelOpts[i].gen.name; i++)
569  {
570  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
571  intRelOpts[i].gen.lockmode));
572  j++;
573  }
574  for (i = 0; realRelOpts[i].gen.name; i++)
575  {
576  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
577  realRelOpts[i].gen.lockmode));
578  j++;
579  }
580  for (i = 0; enumRelOpts[i].gen.name; i++)
581  {
582  Assert(DoLockModesConflict(enumRelOpts[i].gen.lockmode,
583  enumRelOpts[i].gen.lockmode));
584  j++;
585  }
586  for (i = 0; stringRelOpts[i].gen.name; i++)
587  {
588  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
590  j++;
591  }
592  j += num_custom_options;
593 
594  if (relOpts)
595  pfree(relOpts);
597  (j + 1) * sizeof(relopt_gen *));
598 
599  j = 0;
600  for (i = 0; boolRelOpts[i].gen.name; i++)
601  {
602  relOpts[j] = &boolRelOpts[i].gen;
604  relOpts[j]->namelen = strlen(relOpts[j]->name);
605  j++;
606  }
607 
608  for (i = 0; intRelOpts[i].gen.name; i++)
609  {
610  relOpts[j] = &intRelOpts[i].gen;
612  relOpts[j]->namelen = strlen(relOpts[j]->name);
613  j++;
614  }
615 
616  for (i = 0; realRelOpts[i].gen.name; i++)
617  {
618  relOpts[j] = &realRelOpts[i].gen;
620  relOpts[j]->namelen = strlen(relOpts[j]->name);
621  j++;
622  }
623 
624  for (i = 0; enumRelOpts[i].gen.name; i++)
625  {
626  relOpts[j] = &enumRelOpts[i].gen;
628  relOpts[j]->namelen = strlen(relOpts[j]->name);
629  j++;
630  }
631 
632  for (i = 0; stringRelOpts[i].gen.name; i++)
633  {
634  relOpts[j] = &stringRelOpts[i].gen;
636  relOpts[j]->namelen = strlen(relOpts[j]->name);
637  j++;
638  }
639 
640  for (i = 0; i < num_custom_options; i++)
641  {
642  relOpts[j] = custom_options[i];
643  j++;
644  }
645 
646  /* add a list terminator */
647  relOpts[j] = NULL;
648 
649  /* flag the work is complete */
650  need_initialization = false;
651 }
static relopt_gen ** custom_options
Definition: reloptions.c:533
relopt_gen gen
Definition: reloptions.h:125
LOCKMODE lockmode
Definition: reloptions.h:70
static relopt_bool boolRelOpts[]
Definition: reloptions.c:96
relopt_gen gen
Definition: reloptions.h:141
void pfree(void *pointer)
Definition: mcxt.c:1056
static int num_custom_options
Definition: reloptions.c:532
relopt_gen gen
Definition: reloptions.h:93
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:583
static relopt_real realRelOpts[]
Definition: reloptions.c:390
int namelen
Definition: reloptions.h:71
MemoryContext TopMemoryContext
Definition: mcxt.c:44
relopt_gen gen
Definition: reloptions.h:99
#define Assert(condition)
Definition: c.h:738
relopt_type type
Definition: reloptions.h:72
relopt_gen gen
Definition: reloptions.h:107
const char * name
Definition: encode.c:561
static relopt_string stringRelOpts[]
Definition: reloptions.c:523
const char * name
Definition: reloptions.h:66
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
int i
static bool need_initialization
Definition: reloptions.c:534
static relopt_enum enumRelOpts[]
Definition: reloptions.c:495
static relopt_int intRelOpts[]
Definition: reloptions.c:175
static relopt_gen ** relOpts
Definition: reloptions.c:529

◆ parse_one_reloption()

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

Definition at line 1548 of file reloptions.c.

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

Referenced by parseRelOptionsInternal().

1550 {
1551  char *value;
1552  int value_len;
1553  bool parsed;
1554  bool nofree = false;
1555 
1556  if (option->isset && validate)
1557  ereport(ERROR,
1558  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1559  errmsg("parameter \"%s\" specified more than once",
1560  option->gen->name)));
1561 
1562  value_len = text_len - option->gen->namelen - 1;
1563  value = (char *) palloc(value_len + 1);
1564  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1565  value[value_len] = '\0';
1566 
1567  switch (option->gen->type)
1568  {
1569  case RELOPT_TYPE_BOOL:
1570  {
1571  parsed = parse_bool(value, &option->values.bool_val);
1572  if (validate && !parsed)
1573  ereport(ERROR,
1574  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1575  errmsg("invalid value for boolean option \"%s\": %s",
1576  option->gen->name, value)));
1577  }
1578  break;
1579  case RELOPT_TYPE_INT:
1580  {
1581  relopt_int *optint = (relopt_int *) option->gen;
1582 
1583  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1584  if (validate && !parsed)
1585  ereport(ERROR,
1586  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1587  errmsg("invalid value for integer option \"%s\": %s",
1588  option->gen->name, value)));
1589  if (validate && (option->values.int_val < optint->min ||
1590  option->values.int_val > optint->max))
1591  ereport(ERROR,
1592  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1593  errmsg("value %s out of bounds for option \"%s\"",
1594  value, option->gen->name),
1595  errdetail("Valid values are between \"%d\" and \"%d\".",
1596  optint->min, optint->max)));
1597  }
1598  break;
1599  case RELOPT_TYPE_REAL:
1600  {
1601  relopt_real *optreal = (relopt_real *) option->gen;
1602 
1603  parsed = parse_real(value, &option->values.real_val, 0, NULL);
1604  if (validate && !parsed)
1605  ereport(ERROR,
1606  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1607  errmsg("invalid value for floating point option \"%s\": %s",
1608  option->gen->name, value)));
1609  if (validate && (option->values.real_val < optreal->min ||
1610  option->values.real_val > optreal->max))
1611  ereport(ERROR,
1612  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1613  errmsg("value %s out of bounds for option \"%s\"",
1614  value, option->gen->name),
1615  errdetail("Valid values are between \"%f\" and \"%f\".",
1616  optreal->min, optreal->max)));
1617  }
1618  break;
1619  case RELOPT_TYPE_ENUM:
1620  {
1621  relopt_enum *optenum = (relopt_enum *) option->gen;
1622  relopt_enum_elt_def *elt;
1623 
1624  parsed = false;
1625  for (elt = optenum->members; elt->string_val; elt++)
1626  {
1627  if (pg_strcasecmp(value, elt->string_val) == 0)
1628  {
1629  option->values.enum_val = elt->symbol_val;
1630  parsed = true;
1631  break;
1632  }
1633  }
1634  if (validate && !parsed)
1635  ereport(ERROR,
1636  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1637  errmsg("invalid value for enum option \"%s\": %s",
1638  option->gen->name, value),
1639  optenum->detailmsg ?
1640  errdetail_internal("%s", _(optenum->detailmsg)) : 0));
1641 
1642  /*
1643  * If value is not among the allowed string values, but we are
1644  * not asked to validate, just use the default numeric value.
1645  */
1646  if (!parsed)
1647  option->values.enum_val = optenum->default_val;
1648  }
1649  break;
1650  case RELOPT_TYPE_STRING:
1651  {
1652  relopt_string *optstring = (relopt_string *) option->gen;
1653 
1654  option->values.string_val = value;
1655  nofree = true;
1656  if (validate && optstring->validate_cb)
1657  (optstring->validate_cb) (value);
1658  parsed = true;
1659  }
1660  break;
1661  default:
1662  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1663  parsed = true; /* quiet compiler */
1664  break;
1665  }
1666 
1667  if (parsed)
1668  option->isset = true;
1669  if (!nofree)
1670  pfree(value);
1671 }
union relopt_value::@46 values
bool bool_val
Definition: reloptions.h:82
char * string_val
Definition: reloptions.h:86
int errcode(int sqlerrcode)
Definition: elog.c:610
bool parse_real(const char *value, double *result, int flags, const char **hintmsg)
Definition: guc.c:6554
bool parse_bool(const char *value, bool *result)
Definition: bool.c:30
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
relopt_gen * gen
Definition: reloptions.h:78
int errdetail_internal(const char *fmt,...)
Definition: elog.c:984
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
const char * detailmsg
Definition: reloptions.h:128
int errdetail(const char *fmt,...)
Definition: elog.c:957
int namelen
Definition: reloptions.h:71
relopt_enum_elt_def * members
Definition: reloptions.h:126
double real_val
Definition: reloptions.h:84
validate_string_relopt validate_cb
Definition: reloptions.h:144
int default_val
Definition: reloptions.h:127
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:6464
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
relopt_type type
Definition: reloptions.h:72
const char * string_val
Definition: reloptions.h:119
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
const char * name
Definition: reloptions.h:66
#define elog(elevel,...)
Definition: elog.h:214
double max
Definition: reloptions.h:110
#define _(x)
Definition: elog.c:88
double min
Definition: reloptions.h:109

◆ parseLocalRelOptions()

static relopt_value* parseLocalRelOptions ( local_relopts relopts,
Datum  options,
bool  validate 
)
static

Definition at line 1520 of file reloptions.c.

References relopt_value::gen, i, relopt_value::isset, lfirst, list_length(), local_relopt::option, local_relopts::options, palloc(), parseRelOptionsInternal(), and values.

Referenced by build_local_reloptions().

1521 {
1522  int nopts = list_length(relopts->options);
1523  relopt_value *values = palloc(sizeof(*values) * nopts);
1524  ListCell *lc;
1525  int i = 0;
1526 
1527  foreach(lc, relopts->options)
1528  {
1529  local_relopt *opt = lfirst(lc);
1530 
1531  values[i].gen = opt->option;
1532  values[i].isset = false;
1533 
1534  i++;
1535  }
1536 
1537  if (options != (Datum) 0)
1538  parseRelOptionsInternal(options, validate, values, nopts);
1539 
1540  return values;
1541 }
relopt_gen * gen
Definition: reloptions.h:78
List * options
Definition: reloptions.h:167
relopt_gen * option
Definition: reloptions.h:160
uintptr_t Datum
Definition: postgres.h:367
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
static Datum values[MAXATTR]
Definition: bootstrap.c:167
static void parseRelOptionsInternal(Datum options, bool validate, relopt_value *reloptions, int numoptions)
Definition: reloptions.c:1405
void * palloc(Size size)
Definition: mcxt.c:949
int i

◆ parseRelOptions()

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

Definition at line 1478 of file reloptions.c.

References DatumGetPointer, relopt_value::gen, i, initialize_reloptions(), relopt_value::isset, need_initialization, palloc(), parseRelOptionsInternal(), and PointerIsValid.

Referenced by build_reloptions().

1480 {
1481  relopt_value *reloptions = NULL;
1482  int numoptions = 0;
1483  int i;
1484  int j;
1485 
1486  if (need_initialization)
1488 
1489  /* Build a list of expected options, based on kind */
1490 
1491  for (i = 0; relOpts[i]; i++)
1492  if (relOpts[i]->kinds & kind)
1493  numoptions++;
1494 
1495  if (numoptions > 0)
1496  {
1497  reloptions = palloc(numoptions * sizeof(relopt_value));
1498 
1499  for (i = 0, j = 0; relOpts[i]; i++)
1500  {
1501  if (relOpts[i]->kinds & kind)
1502  {
1503  reloptions[j].gen = relOpts[i];
1504  reloptions[j].isset = false;
1505  j++;
1506  }
1507  }
1508  }
1509 
1510  /* Done if no options */
1512  parseRelOptionsInternal(options, validate, reloptions, numoptions);
1513 
1514  *numrelopts = numoptions;
1515  return reloptions;
1516 }
static void initialize_reloptions(void)
Definition: reloptions.c:556
relopt_gen * gen
Definition: reloptions.h:78
#define DatumGetPointer(X)
Definition: postgres.h:549
static void parseRelOptionsInternal(Datum options, bool validate, relopt_value *reloptions, int numoptions)
Definition: reloptions.c:1405
void * palloc(Size size)
Definition: mcxt.c:949
int i
static bool need_initialization
Definition: reloptions.c:534
static relopt_gen ** relOpts
Definition: reloptions.c:529
#define PointerIsValid(pointer)
Definition: c.h:632

◆ parseRelOptionsInternal()

static void parseRelOptionsInternal ( Datum  options,
bool  validate,
relopt_value reloptions,
int  numoptions 
)
static

Definition at line 1405 of file reloptions.c.

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

Referenced by parseLocalRelOptions(), and parseRelOptions().

1407 {
1409  Datum *optiondatums;
1410  int noptions;
1411  int i;
1412 
1413  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1414  &optiondatums, NULL, &noptions);
1415 
1416  for (i = 0; i < noptions; i++)
1417  {
1418  char *text_str = VARDATA(optiondatums[i]);
1419  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1420  int j;
1421 
1422  /* Search for a match in reloptions */
1423  for (j = 0; j < numoptions; j++)
1424  {
1425  int kw_len = reloptions[j].gen->namelen;
1426 
1427  if (text_len > kw_len && text_str[kw_len] == '=' &&
1428  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1429  {
1430  parse_one_reloption(&reloptions[j], text_str, text_len,
1431  validate);
1432  break;
1433  }
1434  }
1435 
1436  if (j >= numoptions && validate)
1437  {
1438  char *s;
1439  char *p;
1440 
1441  s = TextDatumGetCString(optiondatums[i]);
1442  p = strchr(s, '=');
1443  if (p)
1444  *p = '\0';
1445  ereport(ERROR,
1446  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1447  errmsg("unrecognized parameter \"%s\"", s)));
1448  }
1449  }
1450 
1451  /* It's worth avoiding memory leaks in this function */
1452  pfree(optiondatums);
1453 
1454  if (((void *) array) != DatumGetPointer(options))
1455  pfree(array);
1456 }
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:561
int errcode(int sqlerrcode)
Definition: elog.c:610
relopt_gen * gen
Definition: reloptions.h:78
void pfree(void *pointer)
Definition: mcxt.c:1056
#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:1548
int namelen
Definition: reloptions.h:71
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
#define ereport(elevel,...)
Definition: elog.h:144
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3462
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i
static size_t noptions
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ partitioned_table_reloptions()

bytea* partitioned_table_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1962 of file reloptions.c.

References build_reloptions(), and RELOPT_KIND_PARTITIONED.

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

1963 {
1964  /*
1965  * There are no options for partitioned tables yet, but this is able to do
1966  * some validation.
1967  */
1968  return (bytea *) build_reloptions(reloptions, validate,
1970  0, NULL, 0);
1971 }
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1887
Definition: c.h:555

◆ register_reloptions_validator()

void register_reloptions_validator ( local_relopts opts,
relopts_validator  validator 
)

Definition at line 723 of file reloptions.c.

References lappend(), and local_relopts::validators.

724 {
725  opts->validators = lappend(opts->validators, validator);
726 }
List * validators
Definition: reloptions.h:168
List * lappend(List *list, void *datum)
Definition: list.c:321

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 2063 of file reloptions.c.

References build_reloptions(), effective_io_concurrency, lengthof, maintenance_io_concurrency, offsetof, random_page_cost, RELOPT_KIND_TABLESPACE, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, and seq_page_cost.

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

2064 {
2065  static const relopt_parse_elt tab[] = {
2066  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
2067  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
2068  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
2069  {"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
2070  };
2071 
2072  return (bytea *) build_reloptions(reloptions, validate,
2074  sizeof(TableSpaceOpts),
2075  tab, lengthof(tab));
2076 }
int maintenance_io_concurrency
Definition: bufmgr.c:141
#define lengthof(array)
Definition: c.h:668
int effective_io_concurrency
Definition: bufmgr.c:134
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1887
double random_page_cost
Definition: costsize.c:112
Definition: c.h:555
double seq_page_cost
Definition: costsize.c:111
#define offsetof(type, field)
Definition: c.h:661

◆ transformRelOptions()

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

Definition at line 1132 of file reloptions.c.

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

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

1134 {
1135  Datum result;
1136  ArrayBuildState *astate;
1137  ListCell *cell;
1138 
1139  /* no change if empty list */
1140  if (defList == NIL)
1141  return oldOptions;
1142 
1143  /* We build new array using accumArrayResult */
1144  astate = NULL;
1145 
1146  /* Copy any oldOptions that aren't to be replaced */
1147  if (PointerIsValid(DatumGetPointer(oldOptions)))
1148  {
1149  ArrayType *array = DatumGetArrayTypeP(oldOptions);
1150  Datum *oldoptions;
1151  int noldoptions;
1152  int i;
1153 
1154  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1155  &oldoptions, NULL, &noldoptions);
1156 
1157  for (i = 0; i < noldoptions; i++)
1158  {
1159  char *text_str = VARDATA(oldoptions[i]);
1160  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
1161 
1162  /* Search for a match in defList */
1163  foreach(cell, defList)
1164  {
1165  DefElem *def = (DefElem *) lfirst(cell);
1166  int kw_len;
1167 
1168  /* ignore if not in the same namespace */
1169  if (namspace == NULL)
1170  {
1171  if (def->defnamespace != NULL)
1172  continue;
1173  }
1174  else if (def->defnamespace == NULL)
1175  continue;
1176  else if (strcmp(def->defnamespace, namspace) != 0)
1177  continue;
1178 
1179  kw_len = strlen(def->defname);
1180  if (text_len > kw_len && text_str[kw_len] == '=' &&
1181  strncmp(text_str, def->defname, kw_len) == 0)
1182  break;
1183  }
1184  if (!cell)
1185  {
1186  /* No match, so keep old option */
1187  astate = accumArrayResult(astate, oldoptions[i],
1188  false, TEXTOID,
1190  }
1191  }
1192  }
1193 
1194  /*
1195  * If CREATE/SET, add new options to array; if RESET, just check that the
1196  * user didn't say RESET (option=val). (Must do this because the grammar
1197  * doesn't enforce it.)
1198  */
1199  foreach(cell, defList)
1200  {
1201  DefElem *def = (DefElem *) lfirst(cell);
1202 
1203  if (isReset)
1204  {
1205  if (def->arg != NULL)
1206  ereport(ERROR,
1207  (errcode(ERRCODE_SYNTAX_ERROR),
1208  errmsg("RESET must not include values for parameters")));
1209  }
1210  else
1211  {
1212  text *t;
1213  const char *value;
1214  Size len;
1215 
1216  /*
1217  * Error out if the namespace is not valid. A NULL namespace is
1218  * always valid.
1219  */
1220  if (def->defnamespace != NULL)
1221  {
1222  bool valid = false;
1223  int i;
1224 
1225  if (validnsps)
1226  {
1227  for (i = 0; validnsps[i]; i++)
1228  {
1229  if (strcmp(def->defnamespace, validnsps[i]) == 0)
1230  {
1231  valid = true;
1232  break;
1233  }
1234  }
1235  }
1236 
1237  if (!valid)
1238  ereport(ERROR,
1239  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1240  errmsg("unrecognized parameter namespace \"%s\"",
1241  def->defnamespace)));
1242  }
1243 
1244  /* ignore if not in the same namespace */
1245  if (namspace == NULL)
1246  {
1247  if (def->defnamespace != NULL)
1248  continue;
1249  }
1250  else if (def->defnamespace == NULL)
1251  continue;
1252  else if (strcmp(def->defnamespace, namspace) != 0)
1253  continue;
1254 
1255  /*
1256  * Flatten the DefElem into a text string like "name=arg". If we
1257  * have just "name", assume "name=true" is meant. Note: the
1258  * namespace is not output.
1259  */
1260  if (def->arg != NULL)
1261  value = defGetString(def);
1262  else
1263  value = "true";
1264 
1265  /*
1266  * This is not a great place for this test, but there's no other
1267  * convenient place to filter the option out. As WITH (oids =
1268  * false) will be removed someday, this seems like an acceptable
1269  * amount of ugly.
1270  */
1271  if (acceptOidsOff && def->defnamespace == NULL &&
1272  strcmp(def->defname, "oids") == 0)
1273  {
1274  if (defGetBoolean(def))
1275  ereport(ERROR,
1276  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1277  errmsg("tables declared WITH OIDS are not supported")));
1278  /* skip over option, reloptions machinery doesn't know it */
1279  continue;
1280  }
1281 
1282  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
1283  /* +1 leaves room for sprintf's trailing null */
1284  t = (text *) palloc(len + 1);
1285  SET_VARSIZE(t, len);
1286  sprintf(VARDATA(t), "%s=%s", def->defname, value);
1287 
1288  astate = accumArrayResult(astate, PointerGetDatum(t),
1289  false, TEXTOID,
1291  }
1292  }
1293 
1294  if (astate)
1295  result = makeArrayResult(astate, CurrentMemoryContext);
1296  else
1297  result = (Datum) 0;
1298 
1299  return result;
1300 }
#define NIL
Definition: pg_list.h:65
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARSIZE(PTR)
Definition: postgres.h:303
#define PointerGetDatum(X)
Definition: postgres.h:556
#define VARHDRSZ
Definition: c.h:561
char * defnamespace
Definition: parsenodes.h:731
int errcode(int sqlerrcode)
Definition: elog.c:610
#define sprintf
Definition: port.h:195
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5123
Node * arg
Definition: parsenodes.h:733
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
#define lfirst(lc)
Definition: pg_list.h:190
size_t Size
Definition: c.h:466
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3462
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5059
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i
Definition: c.h:555
char * defname
Definition: parsenodes.h:732
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define PointerIsValid(pointer)
Definition: c.h:632
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 1308 of file reloptions.c.

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

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

1309 {
1310  List *result = NIL;
1311  ArrayType *array;
1312  Datum *optiondatums;
1313  int noptions;
1314  int i;
1315 
1316  /* Nothing to do if no options */
1318  return result;
1319 
1320  array = DatumGetArrayTypeP(options);
1321 
1322  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1323  &optiondatums, NULL, &noptions);
1324 
1325  for (i = 0; i < noptions; i++)
1326  {
1327  char *s;
1328  char *p;
1329  Node *val = NULL;
1330 
1331  s = TextDatumGetCString(optiondatums[i]);
1332  p = strchr(s, '=');
1333  if (p)
1334  {
1335  *p++ = '\0';
1336  val = (Node *) makeString(pstrdup(p));
1337  }
1338  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1339  }
1340 
1341  return result;
1342 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1186
Definition: nodes.h:529
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
List * lappend(List *list, void *datum)
Definition: list.c:321
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
#define DatumGetPointer(X)
Definition: postgres.h:549
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3462
int i
static size_t noptions
Definition: pg_list.h:50
#define PointerIsValid(pointer)
Definition: c.h:632
long val
Definition: informix.c:664
#define DatumGetArrayTypeP(X)
Definition: array.h:249

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1977 of file reloptions.c.

References build_reloptions(), lengthof, offsetof, RELOPT_KIND_VIEW, RELOPT_TYPE_BOOL, and RELOPT_TYPE_ENUM.

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

1978 {
1979  static const relopt_parse_elt tab[] = {
1980  {"security_barrier", RELOPT_TYPE_BOOL,
1981  offsetof(ViewOptions, security_barrier)},
1982  {"check_option", RELOPT_TYPE_ENUM,
1983  offsetof(ViewOptions, check_option)}
1984  };
1985 
1986  return (bytea *) build_reloptions(reloptions, validate,
1988  sizeof(ViewOptions),
1989  tab, lengthof(tab));
1990 }
#define lengthof(array)
Definition: c.h:668
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1887
Definition: c.h:555
#define offsetof(type, field)
Definition: c.h:661

Variable Documentation

◆ boolRelOpts

relopt_bool boolRelOpts[]
static

Definition at line 96 of file reloptions.c.

◆ custom_options

relopt_gen** custom_options = NULL
static

Definition at line 533 of file reloptions.c.

◆ enumRelOpts

relopt_enum enumRelOpts[]
static
Initial value:
=
{
{
{
"buffering",
"Enables buffering build for this GiST index",
},
gettext_noop("Valid values are \"on\", \"off\", and \"auto\".")
},
{
{
"check_option",
"View has WITH CHECK OPTION defined (local or cascaded).",
},
gettext_noop("Valid values are \"local\" and \"cascaded\".")
},
{{NULL}}
}
#define gettext_noop(x)
Definition: c.h:1159
relopt_enum_elt_def gistBufferingOptValues[]
Definition: reloptions.c:478
relopt_enum_elt_def viewCheckOptValues[]
Definition: reloptions.c:487
#define AccessExclusiveLock
Definition: lockdefs.h:45

Definition at line 495 of file reloptions.c.

◆ gistBufferingOptValues

relopt_enum_elt_def gistBufferingOptValues[]

◆ intRelOpts

relopt_int intRelOpts[]
static

Definition at line 175 of file reloptions.c.

◆ last_assigned_kind

bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT
static

Definition at line 530 of file reloptions.c.

Referenced by add_reloption_kind().

◆ need_initialization

bool need_initialization = true
static

◆ num_custom_options

int num_custom_options = 0
static

Definition at line 532 of file reloptions.c.

Referenced by add_reloption(), and initialize_reloptions().

◆ realRelOpts

relopt_real realRelOpts[]
static

Definition at line 390 of file reloptions.c.

◆ relOpts

relopt_gen** relOpts = NULL
static

Definition at line 529 of file reloptions.c.

◆ stringRelOpts

relopt_string stringRelOpts[]
static
Initial value:
=
{
{{NULL}}
}

Definition at line 523 of file reloptions.c.

◆ viewCheckOptValues

relopt_enum_elt_def viewCheckOptValues[]
Initial value:

Definition at line 487 of file reloptions.c.