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)   (pg_strncasecmp(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:226

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:226

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:226

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:226

Definition at line 209 of file reloptions.h.

◆ HAVE_RELOPTION

#define HAVE_RELOPTION (   optname,
  option 
)    (pg_strncasecmp(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 1225 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().

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

◆ AlterTableGetRelOptionsLockLevel()

LOCKMODE AlterTableGetRelOptionsLockLevel ( List defList)

Definition at line 1540 of file reloptions.c.

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

Referenced by AlterTableGetLockLevel().

1541 {
1542  LOCKMODE lockmode = NoLock;
1543  ListCell *cell;
1544 
1545  if (defList == NIL)
1546  return AccessExclusiveLock;
1547 
1548  if (need_initialization)
1550 
1551  foreach(cell, defList)
1552  {
1553  DefElem *def = (DefElem *) lfirst(cell);
1554  int i;
1555 
1556  for (i = 0; relOpts[i]; i++)
1557  {
1558  if (pg_strncasecmp(relOpts[i]->name,
1559  def->defname,
1560  relOpts[i]->namelen + 1) == 0)
1561  {
1562  if (lockmode < relOpts[i]->lockmode)
1563  lockmode = relOpts[i]->lockmode;
1564  }
1565  }
1566  }
1567 
1568  return lockmode;
1569 }
#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
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define NoLock
Definition: lockdefs.h:34
int namelen
Definition: reloptions.h: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:719
static relopt_gen ** relOpts
Definition: reloptions.c:437

◆ attribute_reloptions()

bytea* attribute_reloptions ( Datum  reloptions,
bool  validate 
)

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

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

◆ default_reloptions()

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

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

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

◆ extractRelOptions()

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

Definition at line 966 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_TABLE, RELKIND_RELATION, RELKIND_TOASTVALUE, RELKIND_VIEW, and view_reloptions().

Referenced by extract_autovac_opts(), and RelationParseRelOptions().

968 {
969  bytea *options;
970  bool isnull;
971  Datum datum;
972  Form_pg_class classForm;
973 
974  datum = fastgetattr(tuple,
976  tupdesc,
977  &isnull);
978  if (isnull)
979  return NULL;
980 
981  classForm = (Form_pg_class) GETSTRUCT(tuple);
982 
983  /* Parse into appropriate format; don't error out here */
984  switch (classForm->relkind)
985  {
986  case RELKIND_RELATION:
987  case RELKIND_TOASTVALUE:
988  case RELKIND_MATVIEW:
990  options = heap_reloptions(classForm->relkind, datum, false);
991  break;
992  case RELKIND_VIEW:
993  options = view_reloptions(datum, false);
994  break;
995  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:1421
#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:1389
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
static char ** options
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
uintptr_t Datum
Definition: postgres.h:372
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1459
#define Assert(condition)
Definition: c.h:680
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:497
#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 1249 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, pg_strcasecmp(), RELOPT_TYPE_BOOL, RELOPT_TYPE_INT, RELOPT_TYPE_REAL, RELOPT_TYPE_STRING, SET_VARSIZE, relopt_value::string_val, relopt_value::values, and values.

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

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

1422 {
1423  StdRdOptions *rdopts;
1424 
1425  switch (relkind)
1426  {
1427  case RELKIND_TOASTVALUE:
1428  rdopts = (StdRdOptions *)
1429  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1430  if (rdopts != NULL)
1431  {
1432  /* adjust default-only parameters for TOAST relations */
1433  rdopts->fillfactor = 100;
1434  rdopts->autovacuum.analyze_threshold = -1;
1435  rdopts->autovacuum.analyze_scale_factor = -1;
1436  }
1437  return (bytea *) rdopts;
1438  case RELKIND_RELATION:
1439  case RELKIND_MATVIEW:
1440  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1442  return default_reloptions(reloptions, validate,
1444  default:
1445  /* other relkinds are not supported */
1446  return NULL;
1447  }
1448 }
#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:1326
Definition: c.h:497
#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 1459 of file reloptions.c.

References Assert, DatumGetPointer, and PointerIsValid.

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

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

◆ 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(), pg_strncasecmp(), 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  pg_strncasecmp(text_str, reloptions[j].gen->name,
1085  kw_len) == 0)
1086  {
1087  parse_one_reloption(&reloptions[j], text_str, text_len,
1088  validate);
1089  break;
1090  }
1091  }
1092 
1093  if (j >= numoptions && validate)
1094  {
1095  char *s;
1096  char *p;
1097 
1098  s = TextDatumGetCString(optiondatums[i]);
1099  p = strchr(s, '=');
1100  if (p)
1101  *p = '\0';
1102  ereport(ERROR,
1103  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1104  errmsg("unrecognized parameter \"%s\"", s)));
1105  }
1106  }
1107 
1108  /* It's worth avoiding memory leaks in this function */
1109  pfree(optiondatums);
1110  if (((void *) array) != DatumGetPointer(options))
1111  pfree(array);
1112  }
1113 
1114  *numrelopts = numoptions;
1115  return reloptions;
1116 }
static void initialize_reloptions(void)
Definition: reloptions.c:455
#define VARDATA(PTR)
Definition: postgres.h:303
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define VARHDRSZ
Definition: c.h:503
int errcode(int sqlerrcode)
Definition: elog.c:575
relopt_gen * gen
Definition: reloptions.h:76
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
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:1123
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:372
#define DatumGetPointer(X)
Definition: postgres.h:555
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c: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:574
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ tablespace_reloptions()

bytea* tablespace_reloptions ( Datum  reloptions,
bool  validate 
)

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

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

◆ 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(), pg_strcasecmp(), pg_strncasecmp(), PointerGetDatum, PointerIsValid, SET_VARSIZE, TEXTOID, value, VARDATA, VARHDRSZ, and VARSIZE.

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

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 (pg_strcasecmp(def->defnamespace, namspace) != 0)
800  continue;
801 
802  kw_len = strlen(def->defname);
803  if (text_len > kw_len && text_str[kw_len] == '=' &&
804  pg_strncasecmp(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 (pg_strcasecmp(def->defnamespace,
853  validnsps[i]) == 0)
854  {
855  valid = true;
856  break;
857  }
858  }
859  }
860 
861  if (!valid)
862  ereport(ERROR,
863  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
864  errmsg("unrecognized parameter namespace \"%s\"",
865  def->defnamespace)));
866  }
867 
868  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
869  continue;
870 
871  /* ignore if not in the same namespace */
872  if (namspace == NULL)
873  {
874  if (def->defnamespace != NULL)
875  continue;
876  }
877  else if (def->defnamespace == NULL)
878  continue;
879  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
880  continue;
881 
882  /*
883  * Flatten the DefElem into a text string like "name=arg". If we
884  * have just "name", assume "name=true" is meant. Note: the
885  * namespace is not output.
886  */
887  if (def->arg != NULL)
888  value = defGetString(def);
889  else
890  value = "true";
891  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
892  /* +1 leaves room for sprintf's trailing null */
893  t = (text *) palloc(len + 1);
894  SET_VARSIZE(t, len);
895  sprintf(VARDATA(t), "%s=%s", def->defname, value);
896 
897  astate = accumArrayResult(astate, PointerGetDatum(t),
898  false, TEXTOID,
900  }
901  }
902 
903  if (astate)
904  result = makeArrayResult(astate, CurrentMemoryContext);
905  else
906  result = (Datum) 0;
907 
908  return result;
909 }
#define NIL
Definition: pg_list.h:69
#define VARDATA(PTR)
Definition: postgres.h:303
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define PointerGetDatum(X)
Definition: postgres.h:562
#define VARHDRSZ
Definition: c.h:503
char * defnamespace
Definition: parsenodes.h:718
int errcode(int sqlerrcode)
Definition: elog.c:575
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
static struct @121 value
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:720
uintptr_t Datum
Definition: postgres.h:372
#define lfirst(lc)
Definition: pg_list.h:106
size_t Size
Definition: c.h:414
#define DatumGetPointer(X)
Definition: postgres.h:555
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c: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:497
char * defname
Definition: parsenodes.h:719
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define PointerIsValid(pointer)
Definition: c.h:574
#define DatumGetArrayTypeP(X)
Definition: array.h:246

◆ untransformRelOptions()

List* untransformRelOptions ( Datum  options)

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

918 {
919  List *result = NIL;
920  ArrayType *array;
921  Datum *optiondatums;
922  int noptions;
923  int i;
924 
925  /* Nothing to do if no options */
927  return result;
928 
929  array = DatumGetArrayTypeP(options);
930 
931  deconstruct_array(array, TEXTOID, -1, false, 'i',
932  &optiondatums, NULL, &noptions);
933 
934  for (i = 0; i < noptions; i++)
935  {
936  char *s;
937  char *p;
938  Node *val = NULL;
939 
940  s = TextDatumGetCString(optiondatums[i]);
941  p = strchr(s, '=');
942  if (p)
943  {
944  *p++ = '\0';
945  val = (Node *) makeString(pstrdup(p));
946  }
947  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
948  }
949 
950  return result;
951 }
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:512
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:372
#define DatumGetPointer(X)
Definition: postgres.h:555
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3449
int i
static size_t noptions
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:574
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 1389 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().

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