PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
reloptions.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * reloptions.c
4  * Core support for relation options (pg_class.reloptions)
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/access/common/reloptions.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 
16 #include "postgres.h"
17 
18 #include <float.h>
19 
20 #include "access/gist_private.h"
21 #include "access/hash.h"
22 #include "access/htup_details.h"
23 #include "access/nbtree.h"
24 #include "access/reloptions.h"
25 #include "access/spgist.h"
26 #include "catalog/pg_type.h"
27 #include "commands/defrem.h"
28 #include "commands/tablespace.h"
29 #include "commands/view.h"
30 #include "nodes/makefuncs.h"
31 #include "postmaster/postmaster.h"
32 #include "utils/array.h"
33 #include "utils/attoptcache.h"
34 #include "utils/builtins.h"
35 #include "utils/guc.h"
36 #include "utils/memutils.h"
37 #include "utils/rel.h"
38 
39 /*
40  * Contents of pg_class.reloptions
41  *
42  * To add an option:
43  *
44  * (i) decide on a type (integer, real, bool, string), name, default value,
45  * upper and lower bounds (if applicable); for strings, consider a validation
46  * routine.
47  * (ii) add a record below (or use add_<type>_reloption).
48  * (iii) add it to the appropriate options struct (perhaps StdRdOptions)
49  * (iv) add it to the appropriate handling routine (perhaps
50  * default_reloptions)
51  * (v) make sure the lock level is set correctly for that operation
52  * (vi) don't forget to document the option
53  *
54  * Note that we don't handle "oids" in relOpts because it is handled by
55  * interpretOidsOption().
56  *
57  * The default choice for any new option should be AccessExclusiveLock.
58  * In some cases the lock level can be reduced from there, but the lock
59  * level chosen should always conflict with itself to ensure that multiple
60  * changes aren't lost when we attempt concurrent changes.
61  * The choice of lock level depends completely upon how that parameter
62  * is used within the server, not upon how and when you'd like to change it.
63  * Safety first. Existing choices are documented here, and elsewhere in
64  * backend code where the parameters are used.
65  *
66  * In general, anything that affects the results obtained from a SELECT must be
67  * protected by AccessExclusiveLock.
68  *
69  * Autovacuum related parameters can be set at ShareUpdateExclusiveLock
70  * since they are only used by the AV procs and don't change anything
71  * currently executing.
72  *
73  * Fillfactor can be set because it applies only to subsequent changes made to
74  * data blocks, as documented in heapio.c
75  *
76  * n_distinct options can be set at ShareUpdateExclusiveLock because they
77  * are only used during ANALYZE, which uses a ShareUpdateExclusiveLock,
78  * so the ANALYZE will not be affected by in-flight changes. Changing those
79  * values has no affect until the next ANALYZE, so no need for stronger lock.
80  *
81  * Planner-related parameters can be set with ShareUpdateExclusiveLock because
82  * they only affect planning and not the correctness of the execution. Plans
83  * cannot be changed in mid-flight, so changes here could not easily result in
84  * new improved plans in any case. So we allow existing queries to continue
85  * and existing plans to survive, a small price to pay for allowing better
86  * plans to be introduced concurrently without interfering with users.
87  *
88  * Setting parallel_workers is safe, since it acts the same as
89  * max_parallel_workers_per_gather which is a USERSET parameter that doesn't
90  * affect existing plans or queries.
91  */
92 
94 {
95  {
96  {
97  "autovacuum_enabled",
98  "Enables autovacuum in this relation",
101  },
102  true
103  },
104  {
105  {
106  "user_catalog_table",
107  "Declare a table as an additional catalog table, e.g. for the purpose of logical replication",
110  },
111  false
112  },
113  {
114  {
115  "fastupdate",
116  "Enables \"fast update\" feature for this GIN index",
119  },
120  true
121  },
122  {
123  {
124  "security_barrier",
125  "View acts as a row security barrier",
128  },
129  false
130  },
131  /* list terminator */
132  {{NULL}}
133 };
134 
136 {
137  {
138  {
139  "fillfactor",
140  "Packs table pages only to this percentage",
142  ShareUpdateExclusiveLock /* since it applies only to later
143  * inserts */
144  },
146  },
147  {
148  {
149  "fillfactor",
150  "Packs btree index pages only to this percentage",
152  ShareUpdateExclusiveLock /* since it applies only to later
153  * inserts */
154  },
156  },
157  {
158  {
159  "fillfactor",
160  "Packs hash index pages only to this percentage",
162  ShareUpdateExclusiveLock /* since it applies only to later
163  * inserts */
164  },
166  },
167  {
168  {
169  "fillfactor",
170  "Packs gist index pages only to this percentage",
172  ShareUpdateExclusiveLock /* since it applies only to later
173  * inserts */
174  },
176  },
177  {
178  {
179  "fillfactor",
180  "Packs spgist index pages only to this percentage",
182  ShareUpdateExclusiveLock /* since it applies only to later
183  * inserts */
184  },
186  },
187  {
188  {
189  "autovacuum_vacuum_threshold",
190  "Minimum number of tuple updates or deletes prior to vacuum",
193  },
194  -1, 0, INT_MAX
195  },
196  {
197  {
198  "autovacuum_analyze_threshold",
199  "Minimum number of tuple inserts, updates or deletes prior to analyze",
202  },
203  -1, 0, INT_MAX
204  },
205  {
206  {
207  "autovacuum_vacuum_cost_delay",
208  "Vacuum cost delay in milliseconds, for autovacuum",
211  },
212  -1, 0, 100
213  },
214  {
215  {
216  "autovacuum_vacuum_cost_limit",
217  "Vacuum cost amount available before napping, for autovacuum",
220  },
221  -1, 1, 10000
222  },
223  {
224  {
225  "autovacuum_freeze_min_age",
226  "Minimum age at which VACUUM should freeze a table row, for autovacuum",
229  },
230  -1, 0, 1000000000
231  },
232  {
233  {
234  "autovacuum_multixact_freeze_min_age",
235  "Minimum multixact age at which VACUUM should freeze a row multixact's, for autovacuum",
238  },
239  -1, 0, 1000000000
240  },
241  {
242  {
243  "autovacuum_freeze_max_age",
244  "Age at which to autovacuum a table to prevent transaction ID wraparound",
247  },
248  -1, 100000, 2000000000
249  },
250  {
251  {
252  "autovacuum_multixact_freeze_max_age",
253  "Multixact age at which to autovacuum a table to prevent multixact wraparound",
256  },
257  -1, 10000, 2000000000
258  },
259  {
260  {
261  "autovacuum_freeze_table_age",
262  "Age at which VACUUM should perform a full table sweep to freeze row versions",
265  }, -1, 0, 2000000000
266  },
267  {
268  {
269  "autovacuum_multixact_freeze_table_age",
270  "Age of multixact at which VACUUM should perform a full table sweep to freeze row versions",
273  }, -1, 0, 2000000000
274  },
275  {
276  {
277  "log_autovacuum_min_duration",
278  "Sets the minimum execution time above which autovacuum actions will be logged",
281  },
282  -1, -1, INT_MAX
283  },
284  {
285  {
286  "pages_per_range",
287  "Number of pages that each page range covers in a BRIN index",
290  }, 128, 1, 131072
291  },
292  {
293  {
294  "gin_pending_list_limit",
295  "Maximum size of the pending list for this GIN index, in kilobytes.",
298  },
299  -1, 64, MAX_KILOBYTES
300  },
301  {
302  {
303  "effective_io_concurrency",
304  "Number of simultaneous requests that can be handled efficiently by the disk subsystem.",
307  },
308 #ifdef USE_PREFETCH
309  -1, 0, MAX_IO_CONCURRENCY
310 #else
311  0, 0, 0
312 #endif
313  },
314  {
315  {
316  "parallel_workers",
317  "Number of parallel processes that can be used per executor node for this relation.",
320  },
321  -1, 0, 1024
322  },
323 
324  /* list terminator */
325  {{NULL}}
326 };
327 
329 {
330  {
331  {
332  "autovacuum_vacuum_scale_factor",
333  "Number of tuple updates or deletes prior to vacuum as a fraction of reltuples",
336  },
337  -1, 0.0, 100.0
338  },
339  {
340  {
341  "autovacuum_analyze_scale_factor",
342  "Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples",
345  },
346  -1, 0.0, 100.0
347  },
348  {
349  {
350  "seq_page_cost",
351  "Sets the planner's estimate of the cost of a sequentially fetched disk page.",
354  },
355  -1, 0.0, DBL_MAX
356  },
357  {
358  {
359  "random_page_cost",
360  "Sets the planner's estimate of the cost of a nonsequentially fetched disk page.",
363  },
364  -1, 0.0, DBL_MAX
365  },
366  {
367  {
368  "n_distinct",
369  "Sets the planner's estimate of the number of distinct values appearing in a column (excluding child relations).",
372  },
373  0, -1.0, DBL_MAX
374  },
375  {
376  {
377  "n_distinct_inherited",
378  "Sets the planner's estimate of the number of distinct values appearing in a column (including child relations).",
381  },
382  0, -1.0, DBL_MAX
383  },
384  /* list terminator */
385  {{NULL}}
386 };
387 
389 {
390  {
391  {
392  "buffering",
393  "Enables buffering build for this GiST index",
396  },
397  4,
398  false,
400  "auto"
401  },
402  {
403  {
404  "check_option",
405  "View has WITH CHECK OPTION defined (local or cascaded).",
408  },
409  0,
410  true,
412  NULL
413  },
414  /* list terminator */
415  {{NULL}}
416 };
417 
420 
421 static int num_custom_options = 0;
423 static bool need_initialization = true;
424 
425 static void initialize_reloptions(void);
426 static void parse_one_reloption(relopt_value *option, char *text_str,
427  int text_len, bool validate);
428 
429 /*
430  * initialize_reloptions
431  * initialization routine, must be called before parsing
432  *
433  * Initialize the relOpts array and fill each variable's type and name length.
434  */
435 static void
437 {
438  int i;
439  int j;
440 
441  j = 0;
442  for (i = 0; boolRelOpts[i].gen.name; i++)
443  {
444  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
445  boolRelOpts[i].gen.lockmode));
446  j++;
447  }
448  for (i = 0; intRelOpts[i].gen.name; i++)
449  {
450  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
451  intRelOpts[i].gen.lockmode));
452  j++;
453  }
454  for (i = 0; realRelOpts[i].gen.name; i++)
455  {
456  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
457  realRelOpts[i].gen.lockmode));
458  j++;
459  }
460  for (i = 0; stringRelOpts[i].gen.name; i++)
461  {
462  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
463  stringRelOpts[i].gen.lockmode));
464  j++;
465  }
466  j += num_custom_options;
467 
468  if (relOpts)
469  pfree(relOpts);
471  (j + 1) * sizeof(relopt_gen *));
472 
473  j = 0;
474  for (i = 0; boolRelOpts[i].gen.name; i++)
475  {
476  relOpts[j] = &boolRelOpts[i].gen;
477  relOpts[j]->type = RELOPT_TYPE_BOOL;
478  relOpts[j]->namelen = strlen(relOpts[j]->name);
479  j++;
480  }
481 
482  for (i = 0; intRelOpts[i].gen.name; i++)
483  {
484  relOpts[j] = &intRelOpts[i].gen;
485  relOpts[j]->type = RELOPT_TYPE_INT;
486  relOpts[j]->namelen = strlen(relOpts[j]->name);
487  j++;
488  }
489 
490  for (i = 0; realRelOpts[i].gen.name; i++)
491  {
492  relOpts[j] = &realRelOpts[i].gen;
493  relOpts[j]->type = RELOPT_TYPE_REAL;
494  relOpts[j]->namelen = strlen(relOpts[j]->name);
495  j++;
496  }
497 
498  for (i = 0; stringRelOpts[i].gen.name; i++)
499  {
500  relOpts[j] = &stringRelOpts[i].gen;
501  relOpts[j]->type = RELOPT_TYPE_STRING;
502  relOpts[j]->namelen = strlen(relOpts[j]->name);
503  j++;
504  }
505 
506  for (i = 0; i < num_custom_options; i++)
507  {
508  relOpts[j] = custom_options[i];
509  j++;
510  }
511 
512  /* add a list terminator */
513  relOpts[j] = NULL;
514 
515  /* flag the work is complete */
516  need_initialization = false;
517 }
518 
519 /*
520  * add_reloption_kind
521  * Create a new relopt_kind value, to be used in custom reloptions by
522  * user-defined AMs.
523  */
526 {
527  /* don't hand out the last bit so that the enum's behavior is portable */
529  ereport(ERROR,
530  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
531  errmsg("user-defined relation parameter types limit exceeded")));
532  last_assigned_kind <<= 1;
534 }
535 
536 /*
537  * add_reloption
538  * Add an already-created custom reloption to the list, and recompute the
539  * main parser table.
540  */
541 static void
543 {
544  static int max_custom_options = 0;
545 
546  if (num_custom_options >= max_custom_options)
547  {
548  MemoryContext oldcxt;
549 
551 
552  if (max_custom_options == 0)
553  {
554  max_custom_options = 8;
555  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
556  }
557  else
558  {
559  max_custom_options *= 2;
560  custom_options = repalloc(custom_options,
561  max_custom_options * sizeof(relopt_gen *));
562  }
563  MemoryContextSwitchTo(oldcxt);
564  }
565  custom_options[num_custom_options++] = newoption;
566 
567  need_initialization = true;
568 }
569 
570 /*
571  * allocate_reloption
572  * Allocate a new reloption and initialize the type-agnostic fields
573  * (for types other than string)
574  */
575 static relopt_gen *
576 allocate_reloption(bits32 kinds, int type, char *name, char *desc)
577 {
578  MemoryContext oldcxt;
579  size_t size;
580  relopt_gen *newoption;
581 
583 
584  switch (type)
585  {
586  case RELOPT_TYPE_BOOL:
587  size = sizeof(relopt_bool);
588  break;
589  case RELOPT_TYPE_INT:
590  size = sizeof(relopt_int);
591  break;
592  case RELOPT_TYPE_REAL:
593  size = sizeof(relopt_real);
594  break;
595  case RELOPT_TYPE_STRING:
596  size = sizeof(relopt_string);
597  break;
598  default:
599  elog(ERROR, "unsupported reloption type %d", type);
600  return NULL; /* keep compiler quiet */
601  }
602 
603  newoption = palloc(size);
604 
605  newoption->name = pstrdup(name);
606  if (desc)
607  newoption->desc = pstrdup(desc);
608  else
609  newoption->desc = NULL;
610  newoption->kinds = kinds;
611  newoption->namelen = strlen(name);
612  newoption->type = type;
613 
614  MemoryContextSwitchTo(oldcxt);
615 
616  return newoption;
617 }
618 
619 /*
620  * add_bool_reloption
621  * Add a new boolean reloption
622  */
623 void
624 add_bool_reloption(bits32 kinds, char *name, char *desc, bool default_val)
625 {
626  relopt_bool *newoption;
627 
628  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
629  name, desc);
630  newoption->default_val = default_val;
631 
632  add_reloption((relopt_gen *) newoption);
633 }
634 
635 /*
636  * add_int_reloption
637  * Add a new integer reloption
638  */
639 void
640 add_int_reloption(bits32 kinds, char *name, char *desc, int default_val,
641  int min_val, int max_val)
642 {
643  relopt_int *newoption;
644 
645  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
646  name, desc);
647  newoption->default_val = default_val;
648  newoption->min = min_val;
649  newoption->max = max_val;
650 
651  add_reloption((relopt_gen *) newoption);
652 }
653 
654 /*
655  * add_real_reloption
656  * Add a new float reloption
657  */
658 void
659 add_real_reloption(bits32 kinds, char *name, char *desc, double default_val,
660  double min_val, double max_val)
661 {
662  relopt_real *newoption;
663 
664  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
665  name, desc);
666  newoption->default_val = default_val;
667  newoption->min = min_val;
668  newoption->max = max_val;
669 
670  add_reloption((relopt_gen *) newoption);
671 }
672 
673 /*
674  * add_string_reloption
675  * Add a new string reloption
676  *
677  * "validator" is an optional function pointer that can be used to test the
678  * validity of the values. It must elog(ERROR) when the argument string is
679  * not acceptable for the variable. Note that the default value must pass
680  * the validation.
681  */
682 void
683 add_string_reloption(bits32 kinds, char *name, char *desc, char *default_val,
684  validate_string_relopt validator)
685 {
686  relopt_string *newoption;
687 
688  /* make sure the validator/default combination is sane */
689  if (validator)
690  (validator) (default_val);
691 
692  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
693  name, desc);
694  newoption->validate_cb = validator;
695  if (default_val)
696  {
698  default_val);
699  newoption->default_len = strlen(default_val);
700  newoption->default_isnull = false;
701  }
702  else
703  {
704  newoption->default_val = "";
705  newoption->default_len = 0;
706  newoption->default_isnull = true;
707  }
708 
709  add_reloption((relopt_gen *) newoption);
710 }
711 
712 /*
713  * Transform a relation options list (list of DefElem) into the text array
714  * format that is kept in pg_class.reloptions, including only those options
715  * that are in the passed namespace. The output values do not include the
716  * namespace.
717  *
718  * This is used for three cases: CREATE TABLE/INDEX, ALTER TABLE SET, and
719  * ALTER TABLE RESET. In the ALTER cases, oldOptions is the existing
720  * reloptions value (possibly NULL), and we replace or remove entries
721  * as needed.
722  *
723  * If ignoreOids is true, then we should ignore any occurrence of "oids"
724  * in the list (it will be or has been handled by interpretOidsOption()).
725  *
726  * Note that this is not responsible for determining whether the options
727  * are valid, but it does check that namespaces for all the options given are
728  * listed in validnsps. The NULL namespace is always valid and need not be
729  * explicitly listed. Passing a NULL pointer means that only the NULL
730  * namespace is valid.
731  *
732  * Both oldOptions and the result are text arrays (or NULL for "default"),
733  * but we declare them as Datums to avoid including array.h in reloptions.h.
734  */
735 Datum
736 transformRelOptions(Datum oldOptions, List *defList, char *namspace,
737  char *validnsps[], bool ignoreOids, bool isReset)
738 {
739  Datum result;
740  ArrayBuildState *astate;
741  ListCell *cell;
742 
743  /* no change if empty list */
744  if (defList == NIL)
745  return oldOptions;
746 
747  /* We build new array using accumArrayResult */
748  astate = NULL;
749 
750  /* Copy any oldOptions that aren't to be replaced */
751  if (PointerIsValid(DatumGetPointer(oldOptions)))
752  {
753  ArrayType *array = DatumGetArrayTypeP(oldOptions);
754  Datum *oldoptions;
755  int noldoptions;
756  int i;
757 
758  deconstruct_array(array, TEXTOID, -1, false, 'i',
759  &oldoptions, NULL, &noldoptions);
760 
761  for (i = 0; i < noldoptions; i++)
762  {
763  char *text_str = VARDATA(oldoptions[i]);
764  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
765 
766  /* Search for a match in defList */
767  foreach(cell, defList)
768  {
769  DefElem *def = (DefElem *) lfirst(cell);
770  int kw_len;
771 
772  /* ignore if not in the same namespace */
773  if (namspace == NULL)
774  {
775  if (def->defnamespace != NULL)
776  continue;
777  }
778  else if (def->defnamespace == NULL)
779  continue;
780  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
781  continue;
782 
783  kw_len = strlen(def->defname);
784  if (text_len > kw_len && text_str[kw_len] == '=' &&
785  pg_strncasecmp(text_str, def->defname, kw_len) == 0)
786  break;
787  }
788  if (!cell)
789  {
790  /* No match, so keep old option */
791  astate = accumArrayResult(astate, oldoptions[i],
792  false, TEXTOID,
794  }
795  }
796  }
797 
798  /*
799  * If CREATE/SET, add new options to array; if RESET, just check that the
800  * user didn't say RESET (option=val). (Must do this because the grammar
801  * doesn't enforce it.)
802  */
803  foreach(cell, defList)
804  {
805  DefElem *def = (DefElem *) lfirst(cell);
806 
807  if (isReset)
808  {
809  if (def->arg != NULL)
810  ereport(ERROR,
811  (errcode(ERRCODE_SYNTAX_ERROR),
812  errmsg("RESET must not include values for parameters")));
813  }
814  else
815  {
816  text *t;
817  const char *value;
818  Size len;
819 
820  /*
821  * Error out if the namespace is not valid. A NULL namespace is
822  * always valid.
823  */
824  if (def->defnamespace != NULL)
825  {
826  bool valid = false;
827  int i;
828 
829  if (validnsps)
830  {
831  for (i = 0; validnsps[i]; i++)
832  {
833  if (pg_strcasecmp(def->defnamespace,
834  validnsps[i]) == 0)
835  {
836  valid = true;
837  break;
838  }
839  }
840  }
841 
842  if (!valid)
843  ereport(ERROR,
844  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
845  errmsg("unrecognized parameter namespace \"%s\"",
846  def->defnamespace)));
847  }
848 
849  if (ignoreOids && pg_strcasecmp(def->defname, "oids") == 0)
850  continue;
851 
852  /* ignore if not in the same namespace */
853  if (namspace == NULL)
854  {
855  if (def->defnamespace != NULL)
856  continue;
857  }
858  else if (def->defnamespace == NULL)
859  continue;
860  else if (pg_strcasecmp(def->defnamespace, namspace) != 0)
861  continue;
862 
863  /*
864  * Flatten the DefElem into a text string like "name=arg". If we
865  * have just "name", assume "name=true" is meant. Note: the
866  * namespace is not output.
867  */
868  if (def->arg != NULL)
869  value = defGetString(def);
870  else
871  value = "true";
872  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
873  /* +1 leaves room for sprintf's trailing null */
874  t = (text *) palloc(len + 1);
875  SET_VARSIZE(t, len);
876  sprintf(VARDATA(t), "%s=%s", def->defname, value);
877 
878  astate = accumArrayResult(astate, PointerGetDatum(t),
879  false, TEXTOID,
881  }
882  }
883 
884  if (astate)
885  result = makeArrayResult(astate, CurrentMemoryContext);
886  else
887  result = (Datum) 0;
888 
889  return result;
890 }
891 
892 
893 /*
894  * Convert the text-array format of reloptions into a List of DefElem.
895  * This is the inverse of transformRelOptions().
896  */
897 List *
899 {
900  List *result = NIL;
901  ArrayType *array;
902  Datum *optiondatums;
903  int noptions;
904  int i;
905 
906  /* Nothing to do if no options */
907  if (!PointerIsValid(DatumGetPointer(options)))
908  return result;
909 
910  array = DatumGetArrayTypeP(options);
911 
912  deconstruct_array(array, TEXTOID, -1, false, 'i',
913  &optiondatums, NULL, &noptions);
914 
915  for (i = 0; i < noptions; i++)
916  {
917  char *s;
918  char *p;
919  Node *val = NULL;
920 
921  s = TextDatumGetCString(optiondatums[i]);
922  p = strchr(s, '=');
923  if (p)
924  {
925  *p++ = '\0';
926  val = (Node *) makeString(pstrdup(p));
927  }
928  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
929  }
930 
931  return result;
932 }
933 
934 /*
935  * Extract and parse reloptions from a pg_class tuple.
936  *
937  * This is a low-level routine, expected to be used by relcache code and
938  * callers that do not have a table's relcache entry (e.g. autovacuum). For
939  * other uses, consider grabbing the rd_options pointer from the relcache entry
940  * instead.
941  *
942  * tupdesc is pg_class' tuple descriptor. amoptions is a pointer to the index
943  * AM's options parser function in the case of a tuple corresponding to an
944  * index, or NULL otherwise.
945  */
946 bytea *
948  amoptions_function amoptions)
949 {
950  bytea *options;
951  bool isnull;
952  Datum datum;
953  Form_pg_class classForm;
954 
955  datum = fastgetattr(tuple,
957  tupdesc,
958  &isnull);
959  if (isnull)
960  return NULL;
961 
962  classForm = (Form_pg_class) GETSTRUCT(tuple);
963 
964  /* Parse into appropriate format; don't error out here */
965  switch (classForm->relkind)
966  {
967  case RELKIND_RELATION:
968  case RELKIND_TOASTVALUE:
969  case RELKIND_MATVIEW:
971  options = heap_reloptions(classForm->relkind, datum, false);
972  break;
973  case RELKIND_VIEW:
974  options = view_reloptions(datum, false);
975  break;
976  case RELKIND_INDEX:
977  options = index_reloptions(amoptions, datum, false);
978  break;
980  options = NULL;
981  break;
982  default:
983  Assert(false); /* can't get here */
984  options = NULL; /* keep compiler quiet */
985  break;
986  }
987 
988  return options;
989 }
990 
991 /*
992  * Interpret reloptions that are given in text-array format.
993  *
994  * options is a reloption text array as constructed by transformRelOptions.
995  * kind specifies the family of options to be processed.
996  *
997  * The return value is a relopt_value * array on which the options actually
998  * set in the options array are marked with isset=true. The length of this
999  * array is returned in *numrelopts. Options not set are also present in the
1000  * array; this is so that the caller can easily locate the default values.
1001  *
1002  * If there are no options of the given kind, numrelopts is set to 0 and NULL
1003  * is returned.
1004  *
1005  * Note: values of type int, bool and real are allocated as part of the
1006  * returned array. Values of type string are allocated separately and must
1007  * be freed by the caller.
1008  */
1009 relopt_value *
1011  int *numrelopts)
1012 {
1013  relopt_value *reloptions;
1014  int numoptions = 0;
1015  int i;
1016  int j;
1017 
1018  if (need_initialization)
1020 
1021  /* Build a list of expected options, based on kind */
1022 
1023  for (i = 0; relOpts[i]; i++)
1024  if (relOpts[i]->kinds & kind)
1025  numoptions++;
1026 
1027  if (numoptions == 0)
1028  {
1029  *numrelopts = 0;
1030  return NULL;
1031  }
1032 
1033  reloptions = palloc(numoptions * sizeof(relopt_value));
1034 
1035  for (i = 0, j = 0; relOpts[i]; i++)
1036  {
1037  if (relOpts[i]->kinds & kind)
1038  {
1039  reloptions[j].gen = relOpts[i];
1040  reloptions[j].isset = false;
1041  j++;
1042  }
1043  }
1044 
1045  /* Done if no options */
1046  if (PointerIsValid(DatumGetPointer(options)))
1047  {
1048  ArrayType *array = DatumGetArrayTypeP(options);
1049  Datum *optiondatums;
1050  int noptions;
1051 
1052  deconstruct_array(array, TEXTOID, -1, false, 'i',
1053  &optiondatums, NULL, &noptions);
1054 
1055  for (i = 0; i < noptions; i++)
1056  {
1057  char *text_str = VARDATA(optiondatums[i]);
1058  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1059  int j;
1060 
1061  /* Search for a match in reloptions */
1062  for (j = 0; j < numoptions; j++)
1063  {
1064  int kw_len = reloptions[j].gen->namelen;
1065 
1066  if (text_len > kw_len && text_str[kw_len] == '=' &&
1067  pg_strncasecmp(text_str, reloptions[j].gen->name,
1068  kw_len) == 0)
1069  {
1070  parse_one_reloption(&reloptions[j], text_str, text_len,
1071  validate);
1072  break;
1073  }
1074  }
1075 
1076  if (j >= numoptions && validate)
1077  {
1078  char *s;
1079  char *p;
1080 
1081  s = TextDatumGetCString(optiondatums[i]);
1082  p = strchr(s, '=');
1083  if (p)
1084  *p = '\0';
1085  ereport(ERROR,
1086  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1087  errmsg("unrecognized parameter \"%s\"", s)));
1088  }
1089  }
1090 
1091  /* It's worth avoiding memory leaks in this function */
1092  pfree(optiondatums);
1093  if (((void *) array) != DatumGetPointer(options))
1094  pfree(array);
1095  }
1096 
1097  *numrelopts = numoptions;
1098  return reloptions;
1099 }
1100 
1101 /*
1102  * Subroutine for parseRelOptions, to parse and validate a single option's
1103  * value
1104  */
1105 static void
1106 parse_one_reloption(relopt_value *option, char *text_str, int text_len,
1107  bool validate)
1108 {
1109  char *value;
1110  int value_len;
1111  bool parsed;
1112  bool nofree = false;
1113 
1114  if (option->isset && validate)
1115  ereport(ERROR,
1116  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1117  errmsg("parameter \"%s\" specified more than once",
1118  option->gen->name)));
1119 
1120  value_len = text_len - option->gen->namelen - 1;
1121  value = (char *) palloc(value_len + 1);
1122  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1123  value[value_len] = '\0';
1124 
1125  switch (option->gen->type)
1126  {
1127  case RELOPT_TYPE_BOOL:
1128  {
1129  parsed = parse_bool(value, &option->values.bool_val);
1130  if (validate && !parsed)
1131  ereport(ERROR,
1132  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1133  errmsg("invalid value for boolean option \"%s\": %s",
1134  option->gen->name, value)));
1135  }
1136  break;
1137  case RELOPT_TYPE_INT:
1138  {
1139  relopt_int *optint = (relopt_int *) option->gen;
1140 
1141  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1142  if (validate && !parsed)
1143  ereport(ERROR,
1144  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1145  errmsg("invalid value for integer option \"%s\": %s",
1146  option->gen->name, value)));
1147  if (validate && (option->values.int_val < optint->min ||
1148  option->values.int_val > optint->max))
1149  ereport(ERROR,
1150  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1151  errmsg("value %s out of bounds for option \"%s\"",
1152  value, option->gen->name),
1153  errdetail("Valid values are between \"%d\" and \"%d\".",
1154  optint->min, optint->max)));
1155  }
1156  break;
1157  case RELOPT_TYPE_REAL:
1158  {
1159  relopt_real *optreal = (relopt_real *) option->gen;
1160 
1161  parsed = parse_real(value, &option->values.real_val);
1162  if (validate && !parsed)
1163  ereport(ERROR,
1164  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1165  errmsg("invalid value for floating point option \"%s\": %s",
1166  option->gen->name, value)));
1167  if (validate && (option->values.real_val < optreal->min ||
1168  option->values.real_val > optreal->max))
1169  ereport(ERROR,
1170  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1171  errmsg("value %s out of bounds for option \"%s\"",
1172  value, option->gen->name),
1173  errdetail("Valid values are between \"%f\" and \"%f\".",
1174  optreal->min, optreal->max)));
1175  }
1176  break;
1177  case RELOPT_TYPE_STRING:
1178  {
1179  relopt_string *optstring = (relopt_string *) option->gen;
1180 
1181  option->values.string_val = value;
1182  nofree = true;
1183  if (validate && optstring->validate_cb)
1184  (optstring->validate_cb) (value);
1185  parsed = true;
1186  }
1187  break;
1188  default:
1189  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1190  parsed = true; /* quiet compiler */
1191  break;
1192  }
1193 
1194  if (parsed)
1195  option->isset = true;
1196  if (!nofree)
1197  pfree(value);
1198 }
1199 
1200 /*
1201  * Given the result from parseRelOptions, allocate a struct that's of the
1202  * specified base size plus any extra space that's needed for string variables.
1203  *
1204  * "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
1205  * equivalent).
1206  */
1207 void *
1209 {
1210  Size size = base;
1211  int i;
1212 
1213  for (i = 0; i < numoptions; i++)
1214  if (options[i].gen->type == RELOPT_TYPE_STRING)
1215  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1216 
1217  return palloc0(size);
1218 }
1219 
1220 /*
1221  * Given the result of parseRelOptions and a parsing table, fill in the
1222  * struct (previously allocated with allocateReloptStruct) with the parsed
1223  * values.
1224  *
1225  * rdopts is the pointer to the allocated struct to be filled.
1226  * basesize is the sizeof(struct) that was passed to allocateReloptStruct.
1227  * options, of length numoptions, is parseRelOptions' output.
1228  * elems, of length numelems, is the table describing the allowed options.
1229  * When validate is true, it is expected that all options appear in elems.
1230  */
1231 void
1232 fillRelOptions(void *rdopts, Size basesize,
1233  relopt_value *options, int numoptions,
1234  bool validate,
1235  const relopt_parse_elt *elems, int numelems)
1236 {
1237  int i;
1238  int offset = basesize;
1239 
1240  for (i = 0; i < numoptions; i++)
1241  {
1242  int j;
1243  bool found = false;
1244 
1245  for (j = 0; j < numelems; j++)
1246  {
1247  if (pg_strcasecmp(options[i].gen->name, elems[j].optname) == 0)
1248  {
1249  relopt_string *optstring;
1250  char *itempos = ((char *) rdopts) + elems[j].offset;
1251  char *string_val;
1252 
1253  switch (options[i].gen->type)
1254  {
1255  case RELOPT_TYPE_BOOL:
1256  *(bool *) itempos = options[i].isset ?
1257  options[i].values.bool_val :
1258  ((relopt_bool *) options[i].gen)->default_val;
1259  break;
1260  case RELOPT_TYPE_INT:
1261  *(int *) itempos = options[i].isset ?
1262  options[i].values.int_val :
1263  ((relopt_int *) options[i].gen)->default_val;
1264  break;
1265  case RELOPT_TYPE_REAL:
1266  *(double *) itempos = options[i].isset ?
1267  options[i].values.real_val :
1268  ((relopt_real *) options[i].gen)->default_val;
1269  break;
1270  case RELOPT_TYPE_STRING:
1271  optstring = (relopt_string *) options[i].gen;
1272  if (options[i].isset)
1273  string_val = options[i].values.string_val;
1274  else if (!optstring->default_isnull)
1275  string_val = optstring->default_val;
1276  else
1277  string_val = NULL;
1278 
1279  if (string_val == NULL)
1280  *(int *) itempos = 0;
1281  else
1282  {
1283  strcpy((char *) rdopts + offset, string_val);
1284  *(int *) itempos = offset;
1285  offset += strlen(string_val) + 1;
1286  }
1287  break;
1288  default:
1289  elog(ERROR, "unsupported reloption type %d",
1290  options[i].gen->type);
1291  break;
1292  }
1293  found = true;
1294  break;
1295  }
1296  }
1297  if (validate && !found)
1298  elog(ERROR, "reloption \"%s\" not found in parse table",
1299  options[i].gen->name);
1300  }
1301  SET_VARSIZE(rdopts, offset);
1302 }
1303 
1304 
1305 /*
1306  * Option parser for anything that uses StdRdOptions.
1307  */
1308 bytea *
1309 default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
1310 {
1312  StdRdOptions *rdopts;
1313  int numoptions;
1314  static const relopt_parse_elt tab[] = {
1315  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1316  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1317  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, enabled)},
1318  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1319  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_threshold)},
1320  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1321  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_threshold)},
1322  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1323  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_delay)},
1324  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1325  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_limit)},
1326  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1327  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_min_age)},
1328  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1329  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_max_age)},
1330  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1331  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_table_age)},
1332  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1333  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_min_age)},
1334  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1335  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_max_age)},
1336  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1337  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_table_age)},
1338  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1339  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, log_min_duration)},
1340  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1341  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
1342  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1343  offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
1344  {"user_catalog_table", RELOPT_TYPE_BOOL,
1345  offsetof(StdRdOptions, user_catalog_table)},
1346  {"parallel_workers", RELOPT_TYPE_INT,
1347  offsetof(StdRdOptions, parallel_workers)}
1348  };
1349 
1350  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1351 
1352  /* if none set, we're done */
1353  if (numoptions == 0)
1354  return NULL;
1355 
1356  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1357 
1358  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1359  validate, tab, lengthof(tab));
1360 
1361  pfree(options);
1362 
1363  return (bytea *) rdopts;
1364 }
1365 
1366 /*
1367  * Option parser for views
1368  */
1369 bytea *
1370 view_reloptions(Datum reloptions, bool validate)
1371 {
1373  ViewOptions *vopts;
1374  int numoptions;
1375  static const relopt_parse_elt tab[] = {
1376  {"security_barrier", RELOPT_TYPE_BOOL,
1377  offsetof(ViewOptions, security_barrier)},
1378  {"check_option", RELOPT_TYPE_STRING,
1379  offsetof(ViewOptions, check_option_offset)}
1380  };
1381 
1382  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1383 
1384  /* if none set, we're done */
1385  if (numoptions == 0)
1386  return NULL;
1387 
1388  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1389 
1390  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1391  validate, tab, lengthof(tab));
1392 
1393  pfree(options);
1394 
1395  return (bytea *) vopts;
1396 }
1397 
1398 /*
1399  * Parse options for heaps, views and toast tables.
1400  */
1401 bytea *
1402 heap_reloptions(char relkind, Datum reloptions, bool validate)
1403 {
1404  StdRdOptions *rdopts;
1405 
1406  switch (relkind)
1407  {
1408  case RELKIND_TOASTVALUE:
1409  rdopts = (StdRdOptions *)
1410  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1411  if (rdopts != NULL)
1412  {
1413  /* adjust default-only parameters for TOAST relations */
1414  rdopts->fillfactor = 100;
1415  rdopts->autovacuum.analyze_threshold = -1;
1416  rdopts->autovacuum.analyze_scale_factor = -1;
1417  }
1418  return (bytea *) rdopts;
1419  case RELKIND_RELATION:
1420  case RELKIND_MATVIEW:
1422  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1423  default:
1424  /* other relkinds are not supported */
1425  return NULL;
1426  }
1427 }
1428 
1429 
1430 /*
1431  * Parse options for indexes.
1432  *
1433  * amoptions index AM's option parser function
1434  * reloptions options as text[] datum
1435  * validate error flag
1436  */
1437 bytea *
1438 index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
1439 {
1440  Assert(amoptions != NULL);
1441 
1442  /* Assume function is strict */
1443  if (!PointerIsValid(DatumGetPointer(reloptions)))
1444  return NULL;
1445 
1446  return amoptions(reloptions, validate);
1447 }
1448 
1449 /*
1450  * Option parser for attribute reloptions
1451  */
1452 bytea *
1453 attribute_reloptions(Datum reloptions, bool validate)
1454 {
1456  AttributeOpts *aopts;
1457  int numoptions;
1458  static const relopt_parse_elt tab[] = {
1459  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1460  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1461  };
1462 
1463  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1464  &numoptions);
1465 
1466  /* if none set, we're done */
1467  if (numoptions == 0)
1468  return NULL;
1469 
1470  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1471 
1472  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1473  validate, tab, lengthof(tab));
1474 
1475  pfree(options);
1476 
1477  return (bytea *) aopts;
1478 }
1479 
1480 /*
1481  * Option parser for tablespace reloptions
1482  */
1483 bytea *
1484 tablespace_reloptions(Datum reloptions, bool validate)
1485 {
1487  TableSpaceOpts *tsopts;
1488  int numoptions;
1489  static const relopt_parse_elt tab[] = {
1490  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1491  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1492  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1493  };
1494 
1495  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1496  &numoptions);
1497 
1498  /* if none set, we're done */
1499  if (numoptions == 0)
1500  return NULL;
1501 
1502  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1503 
1504  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1505  validate, tab, lengthof(tab));
1506 
1507  pfree(options);
1508 
1509  return (bytea *) tsopts;
1510 }
1511 
1512 /*
1513  * Determine the required LOCKMODE from an option list.
1514  *
1515  * Called from AlterTableGetLockLevel(), see that function
1516  * for a longer explanation of how this works.
1517  */
1518 LOCKMODE
1520 {
1521  LOCKMODE lockmode = NoLock;
1522  ListCell *cell;
1523 
1524  if (defList == NIL)
1525  return AccessExclusiveLock;
1526 
1527  if (need_initialization)
1529 
1530  foreach(cell, defList)
1531  {
1532  DefElem *def = (DefElem *) lfirst(cell);
1533  int i;
1534 
1535  for (i = 0; relOpts[i]; i++)
1536  {
1537  if (pg_strncasecmp(relOpts[i]->name,
1538  def->defname,
1539  relOpts[i]->namelen + 1) == 0)
1540  {
1541  if (lockmode < relOpts[i]->lockmode)
1542  lockmode = relOpts[i]->lockmode;
1543  }
1544  }
1545  }
1546 
1547  return lockmode;
1548 }
Value * makeString(char *str)
Definition: value.c:53
#define HASH_DEFAULT_FILLFACTOR
Definition: hash.h:223
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1402
#define NIL
Definition: pg_list.h:69
bool bool_val
Definition: reloptions.h:79
#define MAX_IO_CONCURRENCY
Definition: bufmgr.h:79
static void initialize_reloptions(void)
Definition: reloptions.c:436
#define HASH_MIN_FILLFACTOR
Definition: hash.h:222
static relopt_gen ** custom_options
Definition: reloptions.c:422
char * string_val
Definition: reloptions.h:82
#define VARDATA(PTR)
Definition: postgres.h:303
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
struct relopt_string relopt_string
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:719
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.h:233
const char * desc
Definition: reloptions.h:65
void gistValidateBufferingOption(char *value)
Definition: gistbuild.c:241
int LOCKMODE
Definition: lockdefs.h:26
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:304
#define PointerGetDatum(X)
Definition: postgres.h:562
union relopt_value::@41 values
LOCKMODE lockmode
Definition: reloptions.h:67
#define VARHDRSZ
Definition: c.h:445
#define Anum_pg_class_reloptions
Definition: pg_class.h:134
void add_bool_reloption(bits32 kinds, char *name, char *desc, bool default_val)
Definition: reloptions.c:624
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
char * defnamespace
Definition: parsenodes.h:707
static relopt_bool boolRelOpts[]
Definition: reloptions.c:93
bytea * tablespace_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1484
void validateWithCheckOption(char *value)
Definition: view.c:46
Definition: nodes.h:506
bool default_isnull
Definition: reloptions.h:116
int fillfactor
Definition: rel.h:279
int errcode(int sqlerrcode)
Definition: elog.c:575
bool default_val
Definition: reloptions.h:90
return result
Definition: formatting.c:1618
bool parse_bool(const char *value, bool *result)
Definition: bool.c:30
relopt_gen gen
Definition: reloptions.h:114
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define lengthof(array)
Definition: c.h:562
relopt_gen * gen
Definition: reloptions.h:75
struct relopt_bool relopt_bool
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:543
int effective_io_concurrency
Definition: bufmgr.c:112
bytea * attribute_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1453
struct relopt_real relopt_real
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1370
#define SPGIST_DEFAULT_FILLFACTOR
Definition: spgist.h:25
static struct @114 value
double default_val
Definition: reloptions.h:104
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
double random_page_cost
Definition: costsize.c:105
static relopt_gen * allocate_reloption(bits32 kinds, int type, char *name, char *desc)
Definition: reloptions.c:576
void pfree(void *pointer)
Definition: mcxt.c:950
#define MAX_KILOBYTES
Definition: guc.h:26
#define ERROR
Definition: elog.h:43
static void parse_one_reloption(relopt_value *option, char *text_str, int text_len, bool validate)
Definition: reloptions.c:1106
static int num_custom_options
Definition: reloptions.c:421
int fillfactor
Definition: pgbench.c:112
char * defGetString(DefElem *def)
Definition: define.c:49
relopt_gen gen
Definition: reloptions.h:89
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1208
int analyze_threshold
Definition: rel.h:262
#define NoLock
Definition: lockdefs.h:34
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:556
static relopt_real realRelOpts[]
Definition: reloptions.c:328
int errdetail(const char *fmt,...)
Definition: elog.c:873
int namelen
Definition: reloptions.h:68
bool parse_real(const char *value, double *result)
Definition: guc.c:5562
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
double real_val
Definition: reloptions.h:81
#define GIST_DEFAULT_FILLFACTOR
Definition: gist_private.h:436
#define ereport(elevel, rest)
Definition: elog.h:122
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5055
#define BTREE_DEFAULT_FILLFACTOR
Definition: nbtree.h:132
validate_string_relopt validate_cb
Definition: reloptions.h:117
void add_real_reloption(bits32 kinds, char *name, char *desc, double default_val, double min_val, double max_val)
Definition: reloptions.c:659
MemoryContext TopMemoryContext
Definition: mcxt.c:43
Node * arg
Definition: parsenodes.h:709
List * lappend(List *list, void *datum)
Definition: list.c:128
#define BTREE_MIN_FILLFACTOR
Definition: nbtree.h:131
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition: amapi.h:102
static char ** options
bits32 kinds
Definition: reloptions.h:66
void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1232
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define TextDatumGetCString(d)
Definition: builtins.h:92
void * palloc0(Size size)
Definition: mcxt.c:878
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
uintptr_t Datum
Definition: postgres.h:372
relopt_gen gen
Definition: reloptions.h:95
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:5476
const char * optname
Definition: reloptions.h:124
List * untransformRelOptions(Datum options)
Definition: reloptions.c:898
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
Definition: reloptions.c:947
Datum transformRelOptions(Datum oldOptions, List *defList, char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
Definition: reloptions.c:736
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1438
float8 analyze_scale_factor
Definition: rel.h:273
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
uint32 bits32
Definition: c.h:277
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
#define HEAP_MIN_FILLFACTOR
Definition: rel.h:286
relopt_type type
Definition: reloptions.h:69
#define GIST_MIN_FILLFACTOR
Definition: gist_private.h:435
struct relopt_int relopt_int
size_t Size
Definition: c.h:356
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:542
void(* validate_string_relopt)(char *value)
Definition: reloptions.h:110
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:963
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
Definition: reloptions.c:1519
relopt_gen gen
Definition: reloptions.h:103
const char * name
Definition: encode.c:521
static relopt_string stringRelOpts[]
Definition: reloptions.c:388
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:525
#define DatumGetPointer(X)
Definition: postgres.h:555
int default_val
Definition: reloptions.h:96
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3475
static Datum values[MAXATTR]
Definition: bootstrap.c:162
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:4991
#define AccessExclusiveLock
Definition: lockdefs.h:46
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1309
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1064
const char * name
Definition: reloptions.h:63
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
relopt_kind
Definition: reloptions.h:38
#define RELKIND_VIEW
Definition: pg_class.h:164
int i
#define RELKIND_INDEX
Definition: pg_class.h:161
static bool need_initialization
Definition: reloptions.c:423
Definition: c.h:439
char * defname
Definition: parsenodes.h:708
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1010
void add_string_reloption(bits32 kinds, char *name, char *desc, char *default_val, validate_string_relopt validator)
Definition: reloptions.c:683
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define elog
Definition: elog.h:219
void add_int_reloption(bits32 kinds, char *name, char *desc, int default_val, int min_val, int max_val)
Definition: reloptions.c:640
#define HEAP_DEFAULT_FILLFACTOR
Definition: rel.h:287
static relopt_int intRelOpts[]
Definition: reloptions.c:135
char * default_val
Definition: reloptions.h:118
static relopt_gen ** relOpts
Definition: reloptions.c:418
#define SPGIST_MIN_FILLFACTOR
Definition: spgist.h:24
double max
Definition: reloptions.h:106
#define RELKIND_RELATION
Definition: pg_class.h:160
double seq_page_cost
Definition: costsize.c:104
static size_t noptions
static bits32 last_assigned_kind
Definition: reloptions.c:419
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:526
long val
Definition: informix.c:689
double min
Definition: reloptions.h:105
#define offsetof(type, field)
Definition: c.h:555
#define DatumGetArrayTypeP(X)
Definition: array.h:242
AutoVacOpts autovacuum
Definition: rel.h:280