PostgreSQL Source Code  git master
reloptions.h File Reference
#include "access/amapi.h"
#include "access/htup.h"
#include "access/tupdesc.h"
#include "nodes/pg_list.h"
#include "storage/lock.h"
Include dependency graph for reloptions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  relopt_gen
 
struct  relopt_value
 
struct  relopt_bool
 
struct  relopt_int
 
struct  relopt_real
 
struct  relopt_string
 
struct  relopt_parse_elt
 

Macros

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }
 
#define HAVE_RELOPTION(optname, option)   (strncmp(option.gen->name, optname, option.gen->namelen + 1) == 0)
 
#define HANDLE_INT_RELOPTION(optname, var, option, wasset)
 
#define HANDLE_BOOL_RELOPTION(optname, var, option, wasset)
 
#define HANDLE_REAL_RELOPTION(optname, var, option, wasset)
 
#define HANDLE_STRING_RELOPTION(optname, var, option, base, offset, wasset)
 
#define GET_STRING_RELOPTION_LEN(option)
 
#define GET_STRING_RELOPTION(optstruct, member)
 

Typedefs

typedef enum relopt_type relopt_type
 
typedef enum relopt_kind relopt_kind
 
typedef struct relopt_gen relopt_gen
 
typedef struct relopt_value relopt_value
 
typedef struct relopt_bool relopt_bool
 
typedef struct relopt_int relopt_int
 
typedef struct relopt_real relopt_real
 
typedef void(* validate_string_relopt) (const char *value)
 
typedef struct relopt_string relopt_string
 

Enumerations

enum  relopt_type { RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING }
 
enum  relopt_kind {
  RELOPT_KIND_HEAP = (1 << 0), RELOPT_KIND_TOAST = (1 << 1), RELOPT_KIND_BTREE = (1 << 2), RELOPT_KIND_HASH = (1 << 3),
  RELOPT_KIND_GIN = (1 << 4), RELOPT_KIND_GIST = (1 << 5), RELOPT_KIND_ATTRIBUTE = (1 << 6), RELOPT_KIND_TABLESPACE = (1 << 7),
  RELOPT_KIND_SPGIST = (1 << 8), RELOPT_KIND_VIEW = (1 << 9), RELOPT_KIND_BRIN = (1 << 10), RELOPT_KIND_PARTITIONED = (1 << 11),
  RELOPT_KIND_LAST_DEFAULT = RELOPT_KIND_PARTITIONED, RELOPT_KIND_MAX = (1 << 30)
}
 

Functions

relopt_kind add_reloption_kind (void)
 
void add_bool_reloption (bits32 kinds, const char *name, const char *desc, bool default_val)
 
void add_int_reloption (bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val)
 
void add_real_reloption (bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val)
 
void add_string_reloption (bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator)
 
Datum transformRelOptions (Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
 
ListuntransformRelOptions (Datum options)
 
byteaextractRelOptions (HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
 
relopt_valueparseRelOptions (Datum options, bool validate, relopt_kind kind, int *numrelopts)
 
void * allocateReloptStruct (Size base, relopt_value *options, int numoptions)
 
void fillRelOptions (void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int nelems)
 
byteadefault_reloptions (Datum reloptions, bool validate, relopt_kind kind)
 
byteaheap_reloptions (char relkind, Datum reloptions, bool validate)
 
byteaview_reloptions (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)
 

Macro Definition Documentation

◆ GET_STRING_RELOPTION

#define GET_STRING_RELOPTION (   optstruct,
  member 
)
Value:
((optstruct)->member == 0 ? NULL : \
(char *)(optstruct) + (optstruct)->member)

Definition at line 243 of file reloptions.h.

◆ 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 234 of file reloptions.h.

Referenced by allocateReloptStruct().

◆ HANDLE_BOOL_RELOPTION

#define HANDLE_BOOL_RELOPTION (   optname,
  var,
  option,
  wasset 
)
Value:
do { \
if (option.isset) \
var = option.values.bool_val; \
else \
var = ((relopt_bool *) option.gen)->default_val; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
} while (0)
#define dummyret
Definition: c.h:234

Definition at line 180 of file reloptions.h.

◆ HANDLE_INT_RELOPTION

#define HANDLE_INT_RELOPTION (   optname,
  var,
  option,
  wasset 
)
Value:
do { \
if (option.isset) \
var = option.values.int_val; \
else \
var = ((relopt_int *) option.gen)->default_val; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \
} while (0)
#define dummyret
Definition: c.h:234

Definition at line 171 of file reloptions.h.

◆ HANDLE_REAL_RELOPTION

#define HANDLE_REAL_RELOPTION (   optname,
  var,
  option,
  wasset 
)
Value:
do { \
if (option.isset) \
var = option.values.real_val; \
else \
var = ((relopt_real *) option.gen)->default_val; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
} while (0)
#define dummyret
Definition: c.h:234

Definition at line 189 of file reloptions.h.

◆ HANDLE_STRING_RELOPTION

#define HANDLE_STRING_RELOPTION (   optname,
  var,
  option,
  base,
  offset,
  wasset 
)
Value:
do { \
relopt_string *optstring = (relopt_string *) option.gen;\
char *string_val; \
if (option.isset) \
string_val = option.values.string_val; \
else if (!optstring->default_isnull) \
string_val = optstring->default_val; \
else \
string_val = NULL; \
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
if (string_val == NULL) \
var = 0; \
else \
{ \
strcpy(((char *)(base)) + (offset), string_val); \
var = (offset); \
(offset) += strlen(string_val) + 1; \
} \
} while (0)
#define dummyret
Definition: c.h:234

Definition at line 209 of file reloptions.h.

◆ HAVE_RELOPTION

#define HAVE_RELOPTION (   optname,
  option 
)    (strncmp(option.gen->name, optname, option.gen->namelen + 1) == 0)

Definition at line 168 of file reloptions.h.

◆ HEAP_RELOPT_NAMESPACES

#define HEAP_RELOPT_NAMESPACES   { "toast", NULL }

Typedef Documentation

◆ relopt_bool

◆ relopt_gen

◆ relopt_int

◆ relopt_kind

◆ relopt_real

◆ relopt_string

◆ relopt_type

◆ relopt_value

◆ validate_string_relopt

typedef void(* validate_string_relopt) (const char *value)

Definition at line 111 of file reloptions.h.

Enumeration Type Documentation

◆ relopt_kind

Enumerator
RELOPT_KIND_HEAP 
RELOPT_KIND_TOAST 
RELOPT_KIND_BTREE 
RELOPT_KIND_HASH 
RELOPT_KIND_GIN 
RELOPT_KIND_GIST 
RELOPT_KIND_ATTRIBUTE 
RELOPT_KIND_TABLESPACE 
RELOPT_KIND_SPGIST 
RELOPT_KIND_VIEW 
RELOPT_KIND_BRIN 
RELOPT_KIND_PARTITIONED 
RELOPT_KIND_LAST_DEFAULT 
RELOPT_KIND_MAX 

Definition at line 38 of file reloptions.h.

39 {
40  RELOPT_KIND_HEAP = (1 << 0),
41  RELOPT_KIND_TOAST = (1 << 1),
42  RELOPT_KIND_BTREE = (1 << 2),
43  RELOPT_KIND_HASH = (1 << 3),
44  RELOPT_KIND_GIN = (1 << 4),
45  RELOPT_KIND_GIST = (1 << 5),
46  RELOPT_KIND_ATTRIBUTE = (1 << 6),
47  RELOPT_KIND_TABLESPACE = (1 << 7),
48  RELOPT_KIND_SPGIST = (1 << 8),
49  RELOPT_KIND_VIEW = (1 << 9),
50  RELOPT_KIND_BRIN = (1 << 10),
51  RELOPT_KIND_PARTITIONED = (1 << 11),
52  /* if you add a new kind, make sure you update "last_default" too */
54  /* some compilers treat enums as signed ints, so we can't use 1 << 31 */
55  RELOPT_KIND_MAX = (1 << 30)
56 } relopt_kind;
relopt_kind
Definition: reloptions.h:38

◆ relopt_type

Enumerator
RELOPT_TYPE_BOOL 
RELOPT_TYPE_INT 
RELOPT_TYPE_REAL 
RELOPT_TYPE_STRING 

Definition at line 29 of file reloptions.h.

Function Documentation

◆ add_bool_reloption()

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

Definition at line 643 of file reloptions.c.

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

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

◆ add_int_reloption()

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

Definition at line 659 of file reloptions.c.

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

Referenced by _PG_init().

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

◆ add_real_reloption()

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

Definition at line 678 of file reloptions.c.

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

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

◆ add_reloption_kind()

relopt_kind add_reloption_kind ( void  )

Definition at line 544 of file reloptions.c.

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

Referenced by _PG_init().

545 {
546  /* don't hand out the last bit so that the enum's behavior is portable */
548  ereport(ERROR,
549  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
550  errmsg("user-defined relation parameter types limit exceeded")));
551  last_assigned_kind <<= 1;
553 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
relopt_kind
Definition: reloptions.h:38
static bits32 last_assigned_kind
Definition: reloptions.c:438

◆ add_string_reloption()

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

Definition at line 702 of file reloptions.c.

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

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

◆ allocateReloptStruct()

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

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

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

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

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

1540 {
1541  LOCKMODE lockmode = NoLock;
1542  ListCell *cell;
1543 
1544  if (defList == NIL)
1545  return AccessExclusiveLock;
1546 
1547  if (need_initialization)
1549 
1550  foreach(cell, defList)
1551  {
1552  DefElem *def = (DefElem *) lfirst(cell);
1553  int i;
1554 
1555  for (i = 0; relOpts[i]; i++)
1556  {
1557  if (strncmp(relOpts[i]->name,
1558  def->defname,
1559  relOpts[i]->namelen + 1) == 0)
1560  {
1561  if (lockmode < relOpts[i]->lockmode)
1562  lockmode = relOpts[i]->lockmode;
1563  }
1564  }
1565  }
1566 
1567  return lockmode;
1568 }
#define NIL
Definition: pg_list.h:69
static void initialize_reloptions(void)
Definition: reloptions.c:455
int LOCKMODE
Definition: lockdefs.h:26
LOCKMODE lockmode
Definition: reloptions.h:68
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h:69
#define lfirst(lc)
Definition: pg_list.h:106
const char * name
Definition: encode.c:521
#define AccessExclusiveLock
Definition: lockdefs.h:45
int i
static bool need_initialization
Definition: reloptions.c:442
char * defname
Definition: parsenodes.h:727
static relopt_gen ** relOpts
Definition: reloptions.c:437

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1473 of file reloptions.c.

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

Referenced by ATExecSetOptions(), and get_attribute_options().

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

◆ default_reloptions()

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

Definition at line 1325 of file reloptions.c.

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

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

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

◆ extractRelOptions()

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

Definition at line 965 of file reloptions.c.

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

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

967 {
968  bytea *options;
969  bool isnull;
970  Datum datum;
971  Form_pg_class classForm;
972 
973  datum = fastgetattr(tuple,
975  tupdesc,
976  &isnull);
977  if (isnull)
978  return NULL;
979 
980  classForm = (Form_pg_class) GETSTRUCT(tuple);
981 
982  /* Parse into appropriate format; don't error out here */
983  switch (classForm->relkind)
984  {
985  case RELKIND_RELATION:
986  case RELKIND_TOASTVALUE:
987  case RELKIND_MATVIEW:
989  options = heap_reloptions(classForm->relkind, datum, false);
990  break;
991  case RELKIND_VIEW:
992  options = view_reloptions(datum, false);
993  break;
994  case RELKIND_INDEX:
996  options = index_reloptions(amoptions, datum, false);
997  break;
999  options = NULL;
1000  break;
1001  default:
1002  Assert(false); /* can't get here */
1003  options = NULL; /* keep compiler quiet */
1004  break;
1005  }
1006 
1007  return options;
1008 }
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1420
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:724
#define Anum_pg_class_reloptions
Definition: pg_class.h:134
#define RELKIND_MATVIEW
Definition: pg_class.h:165
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1388
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define RELKIND_PARTITIONED_INDEX
Definition: pg_class.h:169
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:365
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1458
#define Assert(condition)
Definition: c.h:688
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:505
#define RELKIND_RELATION
Definition: pg_class.h:160

◆ fillRelOptions()

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

Definition at line 1248 of file reloptions.c.

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

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

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

◆ heap_reloptions()

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

Definition at line 1420 of file reloptions.c.

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

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

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

◆ index_reloptions()

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

Definition at line 1458 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

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

◆ parseRelOptions()

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

Definition at line 1030 of file reloptions.c.

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

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

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

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1504 of file reloptions.c.

References allocateReloptStruct(), effective_io_concurrency, fillRelOptions(), lengthof, offsetof, options, parseRelOptions(), pfree(), random_page_cost, RELOPT_KIND_TABLESPACE, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, and seq_page_cost.

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

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

◆ transformRelOptions()

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

Definition at line 755 of file reloptions.c.

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

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

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

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

Definition at line 916 of file reloptions.c.

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

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

917 {
918  List *result = NIL;
919  ArrayType *array;
920  Datum *optiondatums;
921  int noptions;
922  int i;
923 
924  /* Nothing to do if no options */
926  return result;
927 
928  array = DatumGetArrayTypeP(options);
929 
930  deconstruct_array(array, TEXTOID, -1, false, 'i',
931  &optiondatums, NULL, &noptions);
932 
933  for (i = 0; i < noptions; i++)
934  {
935  char *s;
936  char *p;
937  Node *val = NULL;
938 
939  s = TextDatumGetCString(optiondatums[i]);
940  p = strchr(s, '=');
941  if (p)
942  {
943  *p++ = '\0';
944  val = (Node *) makeString(pstrdup(p));
945  }
946  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
947  }
948 
949  return result;
950 }
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:1063
Definition: nodes.h:513
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
List * lappend(List *list, void *datum)
Definition: list.c:128
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:365
#define DatumGetPointer(X)
Definition: postgres.h:532
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3449
int i
static size_t noptions
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:582
long val
Definition: informix.c:689
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ view_reloptions()

bytea* view_reloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 1388 of file reloptions.c.

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

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

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