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