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  "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 (strcmp(def->defnamespace, namspace) != 0)
800  continue;
801 
802  kw_len = strlen(def->defname);
803  if (text_len > kw_len && text_str[kw_len] == '=' &&
804  strncmp(text_str, def->defname, kw_len) == 0)
805  break;
806  }
807  if (!cell)
808  {
809  /* No match, so keep old option */
810  astate = accumArrayResult(astate, oldoptions[i],
811  false, TEXTOID,
813  }
814  }
815  }
816 
817  /*
818  * If CREATE/SET, add new options to array; if RESET, just check that the
819  * user didn't say RESET (option=val). (Must do this because the grammar
820  * doesn't enforce it.)
821  */
822  foreach(cell, defList)
823  {
824  DefElem *def = (DefElem *) lfirst(cell);
825 
826  if (isReset)
827  {
828  if (def->arg != NULL)
829  ereport(ERROR,
830  (errcode(ERRCODE_SYNTAX_ERROR),
831  errmsg("RESET must not include values for parameters")));
832  }
833  else
834  {
835  text *t;
836  const char *value;
837  Size len;
838 
839  /*
840  * Error out if the namespace is not valid. A NULL namespace is
841  * always valid.
842  */
843  if (def->defnamespace != NULL)
844  {
845  bool valid = false;
846  int i;
847 
848  if (validnsps)
849  {
850  for (i = 0; validnsps[i]; i++)
851  {
852  if (strcmp(def->defnamespace, validnsps[i]) == 0)
853  {
854  valid = true;
855  break;
856  }
857  }
858  }
859 
860  if (!valid)
861  ereport(ERROR,
862  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
863  errmsg("unrecognized parameter namespace \"%s\"",
864  def->defnamespace)));
865  }
866 
867  if (ignoreOids && strcmp(def->defname, "oids") == 0)
868  continue;
869 
870  /* ignore if not in the same namespace */
871  if (namspace == NULL)
872  {
873  if (def->defnamespace != NULL)
874  continue;
875  }
876  else if (def->defnamespace == NULL)
877  continue;
878  else if (strcmp(def->defnamespace, namspace) != 0)
879  continue;
880 
881  /*
882  * Flatten the DefElem into a text string like "name=arg". If we
883  * have just "name", assume "name=true" is meant. Note: the
884  * namespace is not output.
885  */
886  if (def->arg != NULL)
887  value = defGetString(def);
888  else
889  value = "true";
890  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
891  /* +1 leaves room for sprintf's trailing null */
892  t = (text *) palloc(len + 1);
893  SET_VARSIZE(t, len);
894  sprintf(VARDATA(t), "%s=%s", def->defname, value);
895 
896  astate = accumArrayResult(astate, PointerGetDatum(t),
897  false, TEXTOID,
899  }
900  }
901 
902  if (astate)
903  result = makeArrayResult(astate, CurrentMemoryContext);
904  else
905  result = (Datum) 0;
906 
907  return result;
908 }
909 
910 
911 /*
912  * Convert the text-array format of reloptions into a List of DefElem.
913  * This is the inverse of transformRelOptions().
914  */
915 List *
917 {
918  List *result = NIL;
919  ArrayType *array;
920  Datum *optiondatums;
921  int noptions;
922  int i;
923 
924  /* Nothing to do if no options */
925  if (!PointerIsValid(DatumGetPointer(options)))
926  return result;
927 
928  array = DatumGetArrayTypeP(options);
929 
930  deconstruct_array(array, TEXTOID, -1, false, 'i',
931  &optiondatums, NULL, &noptions);
932 
933  for (i = 0; i < noptions; i++)
934  {
935  char *s;
936  char *p;
937  Node *val = NULL;
938 
939  s = TextDatumGetCString(optiondatums[i]);
940  p = strchr(s, '=');
941  if (p)
942  {
943  *p++ = '\0';
944  val = (Node *) makeString(pstrdup(p));
945  }
946  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
947  }
948 
949  return result;
950 }
951 
952 /*
953  * Extract and parse reloptions from a pg_class tuple.
954  *
955  * This is a low-level routine, expected to be used by relcache code and
956  * callers that do not have a table's relcache entry (e.g. autovacuum). For
957  * other uses, consider grabbing the rd_options pointer from the relcache entry
958  * instead.
959  *
960  * tupdesc is pg_class' tuple descriptor. amoptions is a pointer to the index
961  * AM's options parser function in the case of a tuple corresponding to an
962  * index, or NULL otherwise.
963  */
964 bytea *
966  amoptions_function amoptions)
967 {
968  bytea *options;
969  bool isnull;
970  Datum datum;
971  Form_pg_class classForm;
972 
973  datum = fastgetattr(tuple,
975  tupdesc,
976  &isnull);
977  if (isnull)
978  return NULL;
979 
980  classForm = (Form_pg_class) GETSTRUCT(tuple);
981 
982  /* Parse into appropriate format; don't error out here */
983  switch (classForm->relkind)
984  {
985  case RELKIND_RELATION:
986  case RELKIND_TOASTVALUE:
987  case RELKIND_MATVIEW:
989  options = heap_reloptions(classForm->relkind, datum, false);
990  break;
991  case RELKIND_VIEW:
992  options = view_reloptions(datum, false);
993  break;
994  case RELKIND_INDEX:
996  options = index_reloptions(amoptions, datum, false);
997  break;
999  options = NULL;
1000  break;
1001  default:
1002  Assert(false); /* can't get here */
1003  options = NULL; /* keep compiler quiet */
1004  break;
1005  }
1006 
1007  return options;
1008 }
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  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1085  {
1086  parse_one_reloption(&reloptions[j], text_str, text_len,
1087  validate);
1088  break;
1089  }
1090  }
1091 
1092  if (j >= numoptions && validate)
1093  {
1094  char *s;
1095  char *p;
1096 
1097  s = TextDatumGetCString(optiondatums[i]);
1098  p = strchr(s, '=');
1099  if (p)
1100  *p = '\0';
1101  ereport(ERROR,
1102  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1103  errmsg("unrecognized parameter \"%s\"", s)));
1104  }
1105  }
1106 
1107  /* It's worth avoiding memory leaks in this function */
1108  pfree(optiondatums);
1109  if (((void *) array) != DatumGetPointer(options))
1110  pfree(array);
1111  }
1112 
1113  *numrelopts = numoptions;
1114  return reloptions;
1115 }
1116 
1117 /*
1118  * Subroutine for parseRelOptions, to parse and validate a single option's
1119  * value
1120  */
1121 static void
1122 parse_one_reloption(relopt_value *option, char *text_str, int text_len,
1123  bool validate)
1124 {
1125  char *value;
1126  int value_len;
1127  bool parsed;
1128  bool nofree = false;
1129 
1130  if (option->isset && validate)
1131  ereport(ERROR,
1132  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1133  errmsg("parameter \"%s\" specified more than once",
1134  option->gen->name)));
1135 
1136  value_len = text_len - option->gen->namelen - 1;
1137  value = (char *) palloc(value_len + 1);
1138  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1139  value[value_len] = '\0';
1140 
1141  switch (option->gen->type)
1142  {
1143  case RELOPT_TYPE_BOOL:
1144  {
1145  parsed = parse_bool(value, &option->values.bool_val);
1146  if (validate && !parsed)
1147  ereport(ERROR,
1148  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1149  errmsg("invalid value for boolean option \"%s\": %s",
1150  option->gen->name, value)));
1151  }
1152  break;
1153  case RELOPT_TYPE_INT:
1154  {
1155  relopt_int *optint = (relopt_int *) option->gen;
1156 
1157  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1158  if (validate && !parsed)
1159  ereport(ERROR,
1160  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1161  errmsg("invalid value for integer option \"%s\": %s",
1162  option->gen->name, value)));
1163  if (validate && (option->values.int_val < optint->min ||
1164  option->values.int_val > optint->max))
1165  ereport(ERROR,
1166  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1167  errmsg("value %s out of bounds for option \"%s\"",
1168  value, option->gen->name),
1169  errdetail("Valid values are between \"%d\" and \"%d\".",
1170  optint->min, optint->max)));
1171  }
1172  break;
1173  case RELOPT_TYPE_REAL:
1174  {
1175  relopt_real *optreal = (relopt_real *) option->gen;
1176 
1177  parsed = parse_real(value, &option->values.real_val);
1178  if (validate && !parsed)
1179  ereport(ERROR,
1180  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1181  errmsg("invalid value for floating point option \"%s\": %s",
1182  option->gen->name, value)));
1183  if (validate && (option->values.real_val < optreal->min ||
1184  option->values.real_val > optreal->max))
1185  ereport(ERROR,
1186  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1187  errmsg("value %s out of bounds for option \"%s\"",
1188  value, option->gen->name),
1189  errdetail("Valid values are between \"%f\" and \"%f\".",
1190  optreal->min, optreal->max)));
1191  }
1192  break;
1193  case RELOPT_TYPE_STRING:
1194  {
1195  relopt_string *optstring = (relopt_string *) option->gen;
1196 
1197  option->values.string_val = value;
1198  nofree = true;
1199  if (validate && optstring->validate_cb)
1200  (optstring->validate_cb) (value);
1201  parsed = true;
1202  }
1203  break;
1204  default:
1205  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1206  parsed = true; /* quiet compiler */
1207  break;
1208  }
1209 
1210  if (parsed)
1211  option->isset = true;
1212  if (!nofree)
1213  pfree(value);
1214 }
1215 
1216 /*
1217  * Given the result from parseRelOptions, allocate a struct that's of the
1218  * specified base size plus any extra space that's needed for string variables.
1219  *
1220  * "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
1221  * equivalent).
1222  */
1223 void *
1225 {
1226  Size size = base;
1227  int i;
1228 
1229  for (i = 0; i < numoptions; i++)
1230  if (options[i].gen->type == RELOPT_TYPE_STRING)
1231  size += GET_STRING_RELOPTION_LEN(options[i]) + 1;
1232 
1233  return palloc0(size);
1234 }
1235 
1236 /*
1237  * Given the result of parseRelOptions and a parsing table, fill in the
1238  * struct (previously allocated with allocateReloptStruct) with the parsed
1239  * values.
1240  *
1241  * rdopts is the pointer to the allocated struct to be filled.
1242  * basesize is the sizeof(struct) that was passed to allocateReloptStruct.
1243  * options, of length numoptions, is parseRelOptions' output.
1244  * elems, of length numelems, is the table describing the allowed options.
1245  * When validate is true, it is expected that all options appear in elems.
1246  */
1247 void
1248 fillRelOptions(void *rdopts, Size basesize,
1249  relopt_value *options, int numoptions,
1250  bool validate,
1251  const relopt_parse_elt *elems, int numelems)
1252 {
1253  int i;
1254  int offset = basesize;
1255 
1256  for (i = 0; i < numoptions; i++)
1257  {
1258  int j;
1259  bool found = false;
1260 
1261  for (j = 0; j < numelems; j++)
1262  {
1263  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1264  {
1265  relopt_string *optstring;
1266  char *itempos = ((char *) rdopts) + elems[j].offset;
1267  char *string_val;
1268 
1269  switch (options[i].gen->type)
1270  {
1271  case RELOPT_TYPE_BOOL:
1272  *(bool *) itempos = options[i].isset ?
1273  options[i].values.bool_val :
1274  ((relopt_bool *) options[i].gen)->default_val;
1275  break;
1276  case RELOPT_TYPE_INT:
1277  *(int *) itempos = options[i].isset ?
1278  options[i].values.int_val :
1279  ((relopt_int *) options[i].gen)->default_val;
1280  break;
1281  case RELOPT_TYPE_REAL:
1282  *(double *) itempos = options[i].isset ?
1283  options[i].values.real_val :
1284  ((relopt_real *) options[i].gen)->default_val;
1285  break;
1286  case RELOPT_TYPE_STRING:
1287  optstring = (relopt_string *) options[i].gen;
1288  if (options[i].isset)
1289  string_val = options[i].values.string_val;
1290  else if (!optstring->default_isnull)
1291  string_val = optstring->default_val;
1292  else
1293  string_val = NULL;
1294 
1295  if (string_val == NULL)
1296  *(int *) itempos = 0;
1297  else
1298  {
1299  strcpy((char *) rdopts + offset, string_val);
1300  *(int *) itempos = offset;
1301  offset += strlen(string_val) + 1;
1302  }
1303  break;
1304  default:
1305  elog(ERROR, "unsupported reloption type %d",
1306  options[i].gen->type);
1307  break;
1308  }
1309  found = true;
1310  break;
1311  }
1312  }
1313  if (validate && !found)
1314  elog(ERROR, "reloption \"%s\" not found in parse table",
1315  options[i].gen->name);
1316  }
1317  SET_VARSIZE(rdopts, offset);
1318 }
1319 
1320 
1321 /*
1322  * Option parser for anything that uses StdRdOptions.
1323  */
1324 bytea *
1325 default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
1326 {
1328  StdRdOptions *rdopts;
1329  int numoptions;
1330  static const relopt_parse_elt tab[] = {
1331  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1332  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1333  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1334  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1335  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1336  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1337  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1338  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
1339  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1340  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1341  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1342  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1343  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1344  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1345  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1346  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1347  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1348  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1349  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1350  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1351  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1352  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1353  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1354  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1355  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1356  {"toast_tuple_target", RELOPT_TYPE_INT,
1357  offsetof(StdRdOptions, toast_tuple_target)},
1358  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1359  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1360  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1361  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1362  {"user_catalog_table", RELOPT_TYPE_BOOL,
1363  offsetof(StdRdOptions, user_catalog_table)},
1364  {"parallel_workers", RELOPT_TYPE_INT,
1365  offsetof(StdRdOptions, parallel_workers)}
1366  };
1367 
1368  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1369 
1370  /* if none set, we're done */
1371  if (numoptions == 0)
1372  return NULL;
1373 
1374  rdopts = allocateReloptStruct(sizeof(StdRdOptions), options, numoptions);
1375 
1376  fillRelOptions((void *) rdopts, sizeof(StdRdOptions), options, numoptions,
1377  validate, tab, lengthof(tab));
1378 
1379  pfree(options);
1380 
1381  return (bytea *) rdopts;
1382 }
1383 
1384 /*
1385  * Option parser for views
1386  */
1387 bytea *
1388 view_reloptions(Datum reloptions, bool validate)
1389 {
1391  ViewOptions *vopts;
1392  int numoptions;
1393  static const relopt_parse_elt tab[] = {
1394  {"security_barrier", RELOPT_TYPE_BOOL,
1395  offsetof(ViewOptions, security_barrier)},
1396  {"check_option", RELOPT_TYPE_STRING,
1397  offsetof(ViewOptions, check_option_offset)}
1398  };
1399 
1400  options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1401 
1402  /* if none set, we're done */
1403  if (numoptions == 0)
1404  return NULL;
1405 
1406  vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1407 
1408  fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1409  validate, tab, lengthof(tab));
1410 
1411  pfree(options);
1412 
1413  return (bytea *) vopts;
1414 }
1415 
1416 /*
1417  * Parse options for heaps, views and toast tables.
1418  */
1419 bytea *
1420 heap_reloptions(char relkind, Datum reloptions, bool validate)
1421 {
1422  StdRdOptions *rdopts;
1423 
1424  switch (relkind)
1425  {
1426  case RELKIND_TOASTVALUE:
1427  rdopts = (StdRdOptions *)
1428  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
1429  if (rdopts != NULL)
1430  {
1431  /* adjust default-only parameters for TOAST relations */
1432  rdopts->fillfactor = 100;
1433  rdopts->autovacuum.analyze_threshold = -1;
1434  rdopts->autovacuum.analyze_scale_factor = -1;
1435  }
1436  return (bytea *) rdopts;
1437  case RELKIND_RELATION:
1438  case RELKIND_MATVIEW:
1439  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1441  return default_reloptions(reloptions, validate,
1443  default:
1444  /* other relkinds are not supported */
1445  return NULL;
1446  }
1447 }
1448 
1449 
1450 /*
1451  * Parse options for indexes.
1452  *
1453  * amoptions index AM's option parser function
1454  * reloptions options as text[] datum
1455  * validate error flag
1456  */
1457 bytea *
1458 index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
1459 {
1460  Assert(amoptions != NULL);
1461 
1462  /* Assume function is strict */
1463  if (!PointerIsValid(DatumGetPointer(reloptions)))
1464  return NULL;
1465 
1466  return amoptions(reloptions, validate);
1467 }
1468 
1469 /*
1470  * Option parser for attribute reloptions
1471  */
1472 bytea *
1473 attribute_reloptions(Datum reloptions, bool validate)
1474 {
1476  AttributeOpts *aopts;
1477  int numoptions;
1478  static const relopt_parse_elt tab[] = {
1479  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
1480  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
1481  };
1482 
1483  options = parseRelOptions(reloptions, validate, RELOPT_KIND_ATTRIBUTE,
1484  &numoptions);
1485 
1486  /* if none set, we're done */
1487  if (numoptions == 0)
1488  return NULL;
1489 
1490  aopts = allocateReloptStruct(sizeof(AttributeOpts), options, numoptions);
1491 
1492  fillRelOptions((void *) aopts, sizeof(AttributeOpts), options, numoptions,
1493  validate, tab, lengthof(tab));
1494 
1495  pfree(options);
1496 
1497  return (bytea *) aopts;
1498 }
1499 
1500 /*
1501  * Option parser for tablespace reloptions
1502  */
1503 bytea *
1504 tablespace_reloptions(Datum reloptions, bool validate)
1505 {
1507  TableSpaceOpts *tsopts;
1508  int numoptions;
1509  static const relopt_parse_elt tab[] = {
1510  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
1511  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1512  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1513  };
1514 
1515  options = parseRelOptions(reloptions, validate, RELOPT_KIND_TABLESPACE,
1516  &numoptions);
1517 
1518  /* if none set, we're done */
1519  if (numoptions == 0)
1520  return NULL;
1521 
1522  tsopts = allocateReloptStruct(sizeof(TableSpaceOpts), options, numoptions);
1523 
1524  fillRelOptions((void *) tsopts, sizeof(TableSpaceOpts), options, numoptions,
1525  validate, tab, lengthof(tab));
1526 
1527  pfree(options);
1528 
1529  return (bytea *) tsopts;
1530 }
1531 
1532 /*
1533  * Determine the required LOCKMODE from an option list.
1534  *
1535  * Called from AlterTableGetLockLevel(), see that function
1536  * for a longer explanation of how this works.
1537  */
1538 LOCKMODE
1540 {
1541  LOCKMODE lockmode = NoLock;
1542  ListCell *cell;
1543 
1544  if (defList == NIL)
1545  return AccessExclusiveLock;
1546 
1547  if (need_initialization)
1549 
1550  foreach(cell, defList)
1551  {
1552  DefElem *def = (DefElem *) lfirst(cell);
1553  int i;
1554 
1555  for (i = 0; relOpts[i]; i++)
1556  {
1557  if (strncmp(relOpts[i]->name,
1558  def->defname,
1559  relOpts[i]->namelen + 1) == 0)
1560  {
1561  if (lockmode < relOpts[i]->lockmode)
1562  lockmode = relOpts[i]->lockmode;
1563  }
1564  }
1565  }
1566 
1567  return lockmode;
1568 }
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:1420
#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:302
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
static struct @130 value
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:303
#define PointerGetDatum(X)
Definition: postgres.h:539
LOCKMODE lockmode
Definition: reloptions.h:68
#define VARHDRSZ
Definition: c.h:511
#define Anum_pg_class_reloptions
Definition: pg_class.h:134
char * pstrdup(const char *in)
Definition: mcxt.c:1063
#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:726
static relopt_bool boolRelOpts[]
Definition: reloptions.c:94
bytea * tablespace_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1504
Definition: nodes.h:513
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
#define lengthof(array)
Definition: c.h:618
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:1473
struct relopt_real relopt_real
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1388
#define SPGIST_DEFAULT_FILLFACTOR
Definition: spgist.h:25
double default_val
Definition: reloptions.h:105
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:659
void pfree(void *pointer)
Definition: mcxt.c:936
#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:1122
static int num_custom_options
Definition: reloptions.c:440
int fillfactor
Definition: pgbench.c:117
char * defGetString(DefElem *def)
Definition: define.c:49
union relopt_value::@47 values
relopt_gen gen
Definition: reloptions.h:90
void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1224
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:5631
#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:133
validate_string_relopt validate_cb
Definition: reloptions.h:118
MemoryContext TopMemoryContext
Definition: mcxt.c:43
Node * arg
Definition: parsenodes.h:728
List * lappend(List *list, void *datum)
Definition: list.c:128
#define RELKIND_PARTITIONED_INDEX
Definition: pg_class.h:169
#define BTREE_MIN_FILLFACTOR
Definition: nbtree.h:132
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:1248
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define TextDatumGetCString(d)
Definition: builtins.h:92
void * palloc0(Size size)
Definition: mcxt.c:864
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
uintptr_t Datum
Definition: postgres.h:365
relopt_gen gen
Definition: reloptions.h:96
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:5545
const char * optname
Definition: reloptions.h:125
List * untransformRelOptions(Datum options)
Definition: reloptions.c:916
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
Definition: reloptions.c:965
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:1458
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:323
#define Assert(condition)
Definition: c.h:688
#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:422
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:561
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:949
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
Definition: reloptions.c:1539
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:532
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:1325
void * palloc(Size size)
Definition: mcxt.c:835
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1050
const char * name
Definition: reloptions.h:64
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:693
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:505
char * defname
Definition: parsenodes.h:727
relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1030
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:327
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:111
static size_t noptions
static bits32 last_assigned_kind
Definition: reloptions.c:438
Definition: pg_list.h:45
#define PointerIsValid(pointer)
Definition: c.h:582
long val
Definition: informix.c:689
double min
Definition: reloptions.h:106
#define offsetof(type, field)
Definition: c.h:611
#define DatumGetArrayTypeP(X)
Definition: array.h:246
AutoVacOpts autovacuum
Definition: rel.h:281