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