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-2021, 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/heaptoast.h"
23 #include "access/htup_details.h"
24 #include "access/nbtree.h"
25 #include "access/reloptions.h"
26 #include "access/spgist_private.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  * The default choice for any new option should be AccessExclusiveLock.
56  * In some cases the lock level can be reduced from there, but the lock
57  * level chosen should always conflict with itself to ensure that multiple
58  * changes aren't lost when we attempt concurrent changes.
59  * The choice of lock level depends completely upon how that parameter
60  * is used within the server, not upon how and when you'd like to change it.
61  * Safety first. Existing choices are documented here, and elsewhere in
62  * backend code where the parameters are used.
63  *
64  * In general, anything that affects the results obtained from a SELECT must be
65  * protected by AccessExclusiveLock.
66  *
67  * Autovacuum related parameters can be set at ShareUpdateExclusiveLock
68  * since they are only used by the AV procs and don't change anything
69  * currently executing.
70  *
71  * Fillfactor can be set because it applies only to subsequent changes made to
72  * data blocks, as documented in hio.c
73  *
74  * n_distinct options can be set at ShareUpdateExclusiveLock because they
75  * are only used during ANALYZE, which uses a ShareUpdateExclusiveLock,
76  * so the ANALYZE will not be affected by in-flight changes. Changing those
77  * values has no effect until the next ANALYZE, so no need for stronger lock.
78  *
79  * Planner-related parameters can be set with ShareUpdateExclusiveLock because
80  * they only affect planning and not the correctness of the execution. Plans
81  * cannot be changed in mid-flight, so changes here could not easily result in
82  * new improved plans in any case. So we allow existing queries to continue
83  * and existing plans to survive, a small price to pay for allowing better
84  * plans to be introduced concurrently without interfering with users.
85  *
86  * Setting parallel_workers is safe, since it acts the same as
87  * max_parallel_workers_per_gather which is a USERSET parameter that doesn't
88  * affect existing plans or queries.
89  *
90  * vacuum_truncate can be set at ShareUpdateExclusiveLock because it
91  * is only used during VACUUM, which uses a ShareUpdateExclusiveLock,
92  * so the VACUUM will not be affected by in-flight changes. Changing its
93  * value has no effect until the next VACUUM, so no need for stronger lock.
94  */
95 
97 {
98  {
99  {
100  "autosummarize",
101  "Enables automatic summarization on this BRIN index",
104  },
105  false
106  },
107  {
108  {
109  "autovacuum_enabled",
110  "Enables autovacuum in this relation",
113  },
114  true
115  },
116  {
117  {
118  "user_catalog_table",
119  "Declare a table as an additional catalog table, e.g. for the purpose of logical replication",
122  },
123  false
124  },
125  {
126  {
127  "fastupdate",
128  "Enables \"fast update\" feature for this GIN index",
131  },
132  true
133  },
134  {
135  {
136  "security_barrier",
137  "View acts as a row security barrier",
140  },
141  false
142  },
143  {
144  {
145  "vacuum_truncate",
146  "Enables vacuum to truncate empty pages at the end of this table",
149  },
150  true
151  },
152  {
153  {
154  "deduplicate_items",
155  "Enables \"deduplicate items\" feature for this btree index",
157  ShareUpdateExclusiveLock /* since it applies only to later
158  * inserts */
159  },
160  true
161  },
162  /* list terminator */
163  {{NULL}}
164 };
165 
167 {
168  {
169  {
170  "fillfactor",
171  "Packs table pages only to this percentage",
173  ShareUpdateExclusiveLock /* since it applies only to later
174  * inserts */
175  },
177  },
178  {
179  {
180  "fillfactor",
181  "Packs btree index pages only to this percentage",
183  ShareUpdateExclusiveLock /* since it applies only to later
184  * inserts */
185  },
187  },
188  {
189  {
190  "fillfactor",
191  "Packs hash index pages only to this percentage",
193  ShareUpdateExclusiveLock /* since it applies only to later
194  * inserts */
195  },
197  },
198  {
199  {
200  "fillfactor",
201  "Packs gist index pages only to this percentage",
203  ShareUpdateExclusiveLock /* since it applies only to later
204  * inserts */
205  },
207  },
208  {
209  {
210  "fillfactor",
211  "Packs spgist index pages only to this percentage",
213  ShareUpdateExclusiveLock /* since it applies only to later
214  * inserts */
215  },
217  },
218  {
219  {
220  "autovacuum_vacuum_threshold",
221  "Minimum number of tuple updates or deletes prior to vacuum",
224  },
225  -1, 0, INT_MAX
226  },
227  {
228  {
229  "autovacuum_vacuum_insert_threshold",
230  "Minimum number of tuple inserts prior to vacuum, or -1 to disable insert vacuums",
233  },
234  -2, -1, INT_MAX
235  },
236  {
237  {
238  "autovacuum_analyze_threshold",
239  "Minimum number of tuple inserts, updates or deletes prior to analyze",
242  },
243  -1, 0, INT_MAX
244  },
245  {
246  {
247  "autovacuum_vacuum_cost_limit",
248  "Vacuum cost amount available before napping, for autovacuum",
251  },
252  -1, 1, 10000
253  },
254  {
255  {
256  "autovacuum_freeze_min_age",
257  "Minimum age at which VACUUM should freeze a table row, for autovacuum",
260  },
261  -1, 0, 1000000000
262  },
263  {
264  {
265  "autovacuum_multixact_freeze_min_age",
266  "Minimum multixact age at which VACUUM should freeze a row multixact's, for autovacuum",
269  },
270  -1, 0, 1000000000
271  },
272  {
273  {
274  "autovacuum_freeze_max_age",
275  "Age at which to autovacuum a table to prevent transaction ID wraparound",
278  },
279  -1, 100000, 2000000000
280  },
281  {
282  {
283  "autovacuum_multixact_freeze_max_age",
284  "Multixact age at which to autovacuum a table to prevent multixact wraparound",
287  },
288  -1, 10000, 2000000000
289  },
290  {
291  {
292  "autovacuum_freeze_table_age",
293  "Age at which VACUUM should perform a full table sweep to freeze row versions",
296  }, -1, 0, 2000000000
297  },
298  {
299  {
300  "autovacuum_multixact_freeze_table_age",
301  "Age of multixact at which VACUUM should perform a full table sweep to freeze row versions",
304  }, -1, 0, 2000000000
305  },
306  {
307  {
308  "log_autovacuum_min_duration",
309  "Sets the minimum execution time above which autovacuum actions will be logged",
312  },
313  -1, -1, INT_MAX
314  },
315  {
316  {
317  "toast_tuple_target",
318  "Sets the target tuple length at which external columns will be toasted",
321  },
323  },
324  {
325  {
326  "pages_per_range",
327  "Number of pages that each page range covers in a BRIN index",
330  }, 128, 1, 131072
331  },
332  {
333  {
334  "gin_pending_list_limit",
335  "Maximum size of the pending list for this GIN index, in kilobytes.",
338  },
339  -1, 64, MAX_KILOBYTES
340  },
341  {
342  {
343  "effective_io_concurrency",
344  "Number of simultaneous requests that can be handled efficiently by the disk subsystem.",
347  },
348 #ifdef USE_PREFETCH
349  -1, 0, MAX_IO_CONCURRENCY
350 #else
351  0, 0, 0
352 #endif
353  },
354  {
355  {
356  "maintenance_io_concurrency",
357  "Number of simultaneous requests that can be handled efficiently by the disk subsystem for maintenance work.",
360  },
361 #ifdef USE_PREFETCH
362  -1, 0, MAX_IO_CONCURRENCY
363 #else
364  0, 0, 0
365 #endif
366  },
367  {
368  {
369  "parallel_workers",
370  "Number of parallel processes that can be used per executor node for this relation.",
373  },
374  -1, 0, 1024
375  },
376 
377  /* list terminator */
378  {{NULL}}
379 };
380 
382 {
383  {
384  {
385  "autovacuum_vacuum_cost_delay",
386  "Vacuum cost delay in milliseconds, for autovacuum",
389  },
390  -1, 0.0, 100.0
391  },
392  {
393  {
394  "autovacuum_vacuum_scale_factor",
395  "Number of tuple updates or deletes prior to vacuum as a fraction of reltuples",
398  },
399  -1, 0.0, 100.0
400  },
401  {
402  {
403  "autovacuum_vacuum_insert_scale_factor",
404  "Number of tuple inserts prior to vacuum as a fraction of reltuples",
407  },
408  -1, 0.0, 100.0
409  },
410  {
411  {
412  "autovacuum_analyze_scale_factor",
413  "Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples",
416  },
417  -1, 0.0, 100.0
418  },
419  {
420  {
421  "seq_page_cost",
422  "Sets the planner's estimate of the cost of a sequentially fetched disk page.",
425  },
426  -1, 0.0, DBL_MAX
427  },
428  {
429  {
430  "random_page_cost",
431  "Sets the planner's estimate of the cost of a nonsequentially fetched disk page.",
434  },
435  -1, 0.0, DBL_MAX
436  },
437  {
438  {
439  "n_distinct",
440  "Sets the planner's estimate of the number of distinct values appearing in a column (excluding child relations).",
443  },
444  0, -1.0, DBL_MAX
445  },
446  {
447  {
448  "n_distinct_inherited",
449  "Sets the planner's estimate of the number of distinct values appearing in a column (including child relations).",
452  },
453  0, -1.0, DBL_MAX
454  },
455  {
456  {
457  "vacuum_cleanup_index_scale_factor",
458  "Deprecated B-Tree parameter.",
461  },
462  -1, 0.0, 1e10
463  },
464  /* list terminator */
465  {{NULL}}
466 };
467 
468 /* values from StdRdOptIndexCleanup */
470 {
480  {(const char *) NULL} /* list terminator */
481 };
482 
483 /* values from GistOptBufferingMode */
485 {
486  {"auto", GIST_OPTION_BUFFERING_AUTO},
487  {"on", GIST_OPTION_BUFFERING_ON},
488  {"off", GIST_OPTION_BUFFERING_OFF},
489  {(const char *) NULL} /* list terminator */
490 };
491 
492 /* values from ViewOptCheckOption */
494 {
495  /* no value for NOT_SET */
497  {"cascaded", VIEW_OPTION_CHECK_OPTION_CASCADED},
498  {(const char *) NULL} /* list terminator */
499 };
500 
502 {
503  {
504  {
505  "vacuum_index_cleanup",
506  "Controls index vacuuming and index cleanup",
509  },
512  gettext_noop("Valid values are \"on\", \"off\", and \"auto\".")
513  },
514  {
515  {
516  "buffering",
517  "Enables buffering build for this GiST index",
520  },
523  gettext_noop("Valid values are \"on\", \"off\", and \"auto\".")
524  },
525  {
526  {
527  "check_option",
528  "View has WITH CHECK OPTION defined (local or cascaded).",
531  },
534  gettext_noop("Valid values are \"local\" and \"cascaded\".")
535  },
536  /* list terminator */
537  {{NULL}}
538 };
539 
541 {
542  /* list terminator */
543  {{NULL}}
544 };
545 
546 static relopt_gen **relOpts = NULL;
548 
549 static int num_custom_options = 0;
550 static relopt_gen **custom_options = NULL;
551 static bool need_initialization = true;
552 
553 static void initialize_reloptions(void);
554 static void parse_one_reloption(relopt_value *option, char *text_str,
555  int text_len, bool validate);
556 
557 /*
558  * Get the length of a string reloption (either default or the user-defined
559  * value). This is used for allocation purposes when building a set of
560  * relation options.
561  */
562 #define GET_STRING_RELOPTION_LEN(option) \
563  ((option).isset ? strlen((option).values.string_val) : \
564  ((relopt_string *) (option).gen)->default_len)
565 
566 /*
567  * initialize_reloptions
568  * initialization routine, must be called before parsing
569  *
570  * Initialize the relOpts array and fill each variable's type and name length.
571  */
572 static void
574 {
575  int i;
576  int j;
577 
578  j = 0;
579  for (i = 0; boolRelOpts[i].gen.name; i++)
580  {
581  Assert(DoLockModesConflict(boolRelOpts[i].gen.lockmode,
582  boolRelOpts[i].gen.lockmode));
583  j++;
584  }
585  for (i = 0; intRelOpts[i].gen.name; i++)
586  {
587  Assert(DoLockModesConflict(intRelOpts[i].gen.lockmode,
588  intRelOpts[i].gen.lockmode));
589  j++;
590  }
591  for (i = 0; realRelOpts[i].gen.name; i++)
592  {
593  Assert(DoLockModesConflict(realRelOpts[i].gen.lockmode,
594  realRelOpts[i].gen.lockmode));
595  j++;
596  }
597  for (i = 0; enumRelOpts[i].gen.name; i++)
598  {
599  Assert(DoLockModesConflict(enumRelOpts[i].gen.lockmode,
600  enumRelOpts[i].gen.lockmode));
601  j++;
602  }
603  for (i = 0; stringRelOpts[i].gen.name; i++)
604  {
605  Assert(DoLockModesConflict(stringRelOpts[i].gen.lockmode,
606  stringRelOpts[i].gen.lockmode));
607  j++;
608  }
609  j += num_custom_options;
610 
611  if (relOpts)
612  pfree(relOpts);
614  (j + 1) * sizeof(relopt_gen *));
615 
616  j = 0;
617  for (i = 0; boolRelOpts[i].gen.name; i++)
618  {
619  relOpts[j] = &boolRelOpts[i].gen;
620  relOpts[j]->type = RELOPT_TYPE_BOOL;
621  relOpts[j]->namelen = strlen(relOpts[j]->name);
622  j++;
623  }
624 
625  for (i = 0; intRelOpts[i].gen.name; i++)
626  {
627  relOpts[j] = &intRelOpts[i].gen;
628  relOpts[j]->type = RELOPT_TYPE_INT;
629  relOpts[j]->namelen = strlen(relOpts[j]->name);
630  j++;
631  }
632 
633  for (i = 0; realRelOpts[i].gen.name; i++)
634  {
635  relOpts[j] = &realRelOpts[i].gen;
636  relOpts[j]->type = RELOPT_TYPE_REAL;
637  relOpts[j]->namelen = strlen(relOpts[j]->name);
638  j++;
639  }
640 
641  for (i = 0; enumRelOpts[i].gen.name; i++)
642  {
643  relOpts[j] = &enumRelOpts[i].gen;
644  relOpts[j]->type = RELOPT_TYPE_ENUM;
645  relOpts[j]->namelen = strlen(relOpts[j]->name);
646  j++;
647  }
648 
649  for (i = 0; stringRelOpts[i].gen.name; i++)
650  {
651  relOpts[j] = &stringRelOpts[i].gen;
652  relOpts[j]->type = RELOPT_TYPE_STRING;
653  relOpts[j]->namelen = strlen(relOpts[j]->name);
654  j++;
655  }
656 
657  for (i = 0; i < num_custom_options; i++)
658  {
659  relOpts[j] = custom_options[i];
660  j++;
661  }
662 
663  /* add a list terminator */
664  relOpts[j] = NULL;
665 
666  /* flag the work is complete */
667  need_initialization = false;
668 }
669 
670 /*
671  * add_reloption_kind
672  * Create a new relopt_kind value, to be used in custom reloptions by
673  * user-defined AMs.
674  */
677 {
678  /* don't hand out the last bit so that the enum's behavior is portable */
680  ereport(ERROR,
681  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
682  errmsg("user-defined relation parameter types limit exceeded")));
683  last_assigned_kind <<= 1;
685 }
686 
687 /*
688  * add_reloption
689  * Add an already-created custom reloption to the list, and recompute the
690  * main parser table.
691  */
692 static void
694 {
695  static int max_custom_options = 0;
696 
697  if (num_custom_options >= max_custom_options)
698  {
699  MemoryContext oldcxt;
700 
702 
703  if (max_custom_options == 0)
704  {
705  max_custom_options = 8;
706  custom_options = palloc(max_custom_options * sizeof(relopt_gen *));
707  }
708  else
709  {
710  max_custom_options *= 2;
711  custom_options = repalloc(custom_options,
712  max_custom_options * sizeof(relopt_gen *));
713  }
714  MemoryContextSwitchTo(oldcxt);
715  }
716  custom_options[num_custom_options++] = newoption;
717 
718  need_initialization = true;
719 }
720 
721 /*
722  * init_local_reloptions
723  * Initialize local reloptions that will parsed into bytea structure of
724  * 'relopt_struct_size'.
725  */
726 void
728 {
729  opts->options = NIL;
730  opts->validators = NIL;
731  opts->relopt_struct_size = relopt_struct_size;
732 }
733 
734 /*
735  * register_reloptions_validator
736  * Register custom validation callback that will be called at the end of
737  * build_local_reloptions().
738  */
739 void
741 {
742  opts->validators = lappend(opts->validators, validator);
743 }
744 
745 /*
746  * add_local_reloption
747  * Add an already-created custom reloption to the local list.
748  */
749 static void
750 add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
751 {
752  local_relopt *opt = palloc(sizeof(*opt));
753 
754  Assert(offset < relopts->relopt_struct_size);
755 
756  opt->option = newoption;
757  opt->offset = offset;
758 
759  relopts->options = lappend(relopts->options, opt);
760 }
761 
762 /*
763  * allocate_reloption
764  * Allocate a new reloption and initialize the type-agnostic fields
765  * (for types other than string)
766  */
767 static relopt_gen *
768 allocate_reloption(bits32 kinds, int type, const char *name, const char *desc,
769  LOCKMODE lockmode)
770 {
771  MemoryContext oldcxt;
772  size_t size;
773  relopt_gen *newoption;
774 
775  if (kinds != RELOPT_KIND_LOCAL)
777  else
778  oldcxt = NULL;
779 
780  switch (type)
781  {
782  case RELOPT_TYPE_BOOL:
783  size = sizeof(relopt_bool);
784  break;
785  case RELOPT_TYPE_INT:
786  size = sizeof(relopt_int);
787  break;
788  case RELOPT_TYPE_REAL:
789  size = sizeof(relopt_real);
790  break;
791  case RELOPT_TYPE_ENUM:
792  size = sizeof(relopt_enum);
793  break;
794  case RELOPT_TYPE_STRING:
795  size = sizeof(relopt_string);
796  break;
797  default:
798  elog(ERROR, "unsupported reloption type %d", type);
799  return NULL; /* keep compiler quiet */
800  }
801 
802  newoption = palloc(size);
803 
804  newoption->name = pstrdup(name);
805  if (desc)
806  newoption->desc = pstrdup(desc);
807  else
808  newoption->desc = NULL;
809  newoption->kinds = kinds;
810  newoption->namelen = strlen(name);
811  newoption->type = type;
812  newoption->lockmode = lockmode;
813 
814  if (oldcxt != NULL)
815  MemoryContextSwitchTo(oldcxt);
816 
817  return newoption;
818 }
819 
820 /*
821  * init_bool_reloption
822  * Allocate and initialize a new boolean reloption
823  */
824 static relopt_bool *
825 init_bool_reloption(bits32 kinds, const char *name, const char *desc,
826  bool default_val, LOCKMODE lockmode)
827 {
828  relopt_bool *newoption;
829 
830  newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
831  name, desc, lockmode);
832  newoption->default_val = default_val;
833 
834  return newoption;
835 }
836 
837 /*
838  * add_bool_reloption
839  * Add a new boolean reloption
840  */
841 void
842 add_bool_reloption(bits32 kinds, const char *name, const char *desc,
843  bool default_val, LOCKMODE lockmode)
844 {
845  relopt_bool *newoption = init_bool_reloption(kinds, name, desc,
846  default_val, lockmode);
847 
848  add_reloption((relopt_gen *) newoption);
849 }
850 
851 /*
852  * add_local_bool_reloption
853  * Add a new boolean local reloption
854  *
855  * 'offset' is offset of bool-typed field.
856  */
857 void
859  const char *desc, bool default_val, int offset)
860 {
862  name, desc,
863  default_val, 0);
864 
865  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
866 }
867 
868 
869 /*
870  * init_real_reloption
871  * Allocate and initialize a new integer reloption
872  */
873 static relopt_int *
874 init_int_reloption(bits32 kinds, const char *name, const char *desc,
875  int default_val, int min_val, int max_val,
876  LOCKMODE lockmode)
877 {
878  relopt_int *newoption;
879 
880  newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
881  name, desc, lockmode);
882  newoption->default_val = default_val;
883  newoption->min = min_val;
884  newoption->max = max_val;
885 
886  return newoption;
887 }
888 
889 /*
890  * add_int_reloption
891  * Add a new integer reloption
892  */
893 void
894 add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val,
895  int min_val, int max_val, LOCKMODE lockmode)
896 {
897  relopt_int *newoption = init_int_reloption(kinds, name, desc,
898  default_val, min_val,
899  max_val, lockmode);
900 
901  add_reloption((relopt_gen *) newoption);
902 }
903 
904 /*
905  * add_local_int_reloption
906  * Add a new local integer reloption
907  *
908  * 'offset' is offset of int-typed field.
909  */
910 void
912  const char *desc, int default_val, int min_val,
913  int max_val, int offset)
914 {
916  name, desc, default_val,
917  min_val, max_val, 0);
918 
919  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
920 }
921 
922 /*
923  * init_real_reloption
924  * Allocate and initialize a new real reloption
925  */
926 static relopt_real *
927 init_real_reloption(bits32 kinds, const char *name, const char *desc,
928  double default_val, double min_val, double max_val,
929  LOCKMODE lockmode)
930 {
931  relopt_real *newoption;
932 
933  newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
934  name, desc, lockmode);
935  newoption->default_val = default_val;
936  newoption->min = min_val;
937  newoption->max = max_val;
938 
939  return newoption;
940 }
941 
942 /*
943  * add_real_reloption
944  * Add a new float reloption
945  */
946 void
947 add_real_reloption(bits32 kinds, const char *name, const char *desc,
948  double default_val, double min_val, double max_val,
949  LOCKMODE lockmode)
950 {
951  relopt_real *newoption = init_real_reloption(kinds, name, desc,
952  default_val, min_val,
953  max_val, lockmode);
954 
955  add_reloption((relopt_gen *) newoption);
956 }
957 
958 /*
959  * add_local_real_reloption
960  * Add a new local float reloption
961  *
962  * 'offset' is offset of double-typed field.
963  */
964 void
966  const char *desc, double default_val,
967  double min_val, double max_val, int offset)
968 {
970  name, desc,
971  default_val, min_val,
972  max_val, 0);
973 
974  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
975 }
976 
977 /*
978  * init_enum_reloption
979  * Allocate and initialize a new enum reloption
980  */
981 static relopt_enum *
982 init_enum_reloption(bits32 kinds, const char *name, const char *desc,
983  relopt_enum_elt_def *members, int default_val,
984  const char *detailmsg, LOCKMODE lockmode)
985 {
986  relopt_enum *newoption;
987 
988  newoption = (relopt_enum *) allocate_reloption(kinds, RELOPT_TYPE_ENUM,
989  name, desc, lockmode);
990  newoption->members = members;
991  newoption->default_val = default_val;
992  newoption->detailmsg = detailmsg;
993 
994  return newoption;
995 }
996 
997 
998 /*
999  * add_enum_reloption
1000  * Add a new enum reloption
1001  *
1002  * The members array must have a terminating NULL entry.
1003  *
1004  * The detailmsg is shown when unsupported values are passed, and has this
1005  * form: "Valid values are \"foo\", \"bar\", and \"bar\"."
1006  *
1007  * The members array and detailmsg are not copied -- caller must ensure that
1008  * they are valid throughout the life of the process.
1009  */
1010 void
1011 add_enum_reloption(bits32 kinds, const char *name, const char *desc,
1012  relopt_enum_elt_def *members, int default_val,
1013  const char *detailmsg, LOCKMODE lockmode)
1014 {
1015  relopt_enum *newoption = init_enum_reloption(kinds, name, desc,
1016  members, default_val,
1017  detailmsg, lockmode);
1018 
1019  add_reloption((relopt_gen *) newoption);
1020 }
1021 
1022 /*
1023  * add_local_enum_reloption
1024  * Add a new local enum reloption
1025  *
1026  * 'offset' is offset of int-typed field.
1027  */
1028 void
1030  const char *desc, relopt_enum_elt_def *members,
1031  int default_val, const char *detailmsg, int offset)
1032 {
1034  name, desc,
1035  members, default_val,
1036  detailmsg, 0);
1037 
1038  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1039 }
1040 
1041 /*
1042  * init_string_reloption
1043  * Allocate and initialize a new string reloption
1044  */
1045 static relopt_string *
1046 init_string_reloption(bits32 kinds, const char *name, const char *desc,
1047  const char *default_val,
1048  validate_string_relopt validator,
1049  fill_string_relopt filler,
1050  LOCKMODE lockmode)
1051 {
1052  relopt_string *newoption;
1053 
1054  /* make sure the validator/default combination is sane */
1055  if (validator)
1056  (validator) (default_val);
1057 
1058  newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
1059  name, desc, lockmode);
1060  newoption->validate_cb = validator;
1061  newoption->fill_cb = filler;
1062  if (default_val)
1063  {
1064  if (kinds == RELOPT_KIND_LOCAL)
1065  newoption->default_val = strdup(default_val);
1066  else
1067  newoption->default_val = MemoryContextStrdup(TopMemoryContext, default_val);
1068  newoption->default_len = strlen(default_val);
1069  newoption->default_isnull = false;
1070  }
1071  else
1072  {
1073  newoption->default_val = "";
1074  newoption->default_len = 0;
1075  newoption->default_isnull = true;
1076  }
1077 
1078  return newoption;
1079 }
1080 
1081 /*
1082  * add_string_reloption
1083  * Add a new string reloption
1084  *
1085  * "validator" is an optional function pointer that can be used to test the
1086  * validity of the values. It must elog(ERROR) when the argument string is
1087  * not acceptable for the variable. Note that the default value must pass
1088  * the validation.
1089  */
1090 void
1091 add_string_reloption(bits32 kinds, const char *name, const char *desc,
1092  const char *default_val, validate_string_relopt validator,
1093  LOCKMODE lockmode)
1094 {
1095  relopt_string *newoption = init_string_reloption(kinds, name, desc,
1096  default_val,
1097  validator, NULL,
1098  lockmode);
1099 
1100  add_reloption((relopt_gen *) newoption);
1101 }
1102 
1103 /*
1104  * add_local_string_reloption
1105  * Add a new local string reloption
1106  *
1107  * 'offset' is offset of int-typed field that will store offset of string value
1108  * in the resulting bytea structure.
1109  */
1110 void
1112  const char *desc, const char *default_val,
1113  validate_string_relopt validator,
1114  fill_string_relopt filler, int offset)
1115 {
1117  name, desc,
1118  default_val,
1119  validator, filler,
1120  0);
1121 
1122  add_local_reloption(relopts, (relopt_gen *) newoption, offset);
1123 }
1124 
1125 /*
1126  * Transform a relation options list (list of DefElem) into the text array
1127  * format that is kept in pg_class.reloptions, including only those options
1128  * that are in the passed namespace. The output values do not include the
1129  * namespace.
1130  *
1131  * This is used for three cases: CREATE TABLE/INDEX, ALTER TABLE SET, and
1132  * ALTER TABLE RESET. In the ALTER cases, oldOptions is the existing
1133  * reloptions value (possibly NULL), and we replace or remove entries
1134  * as needed.
1135  *
1136  * If acceptOidsOff is true, then we allow oids = false, but throw error when
1137  * on. This is solely needed for backwards compatibility.
1138  *
1139  * Note that this is not responsible for determining whether the options
1140  * are valid, but it does check that namespaces for all the options given are
1141  * listed in validnsps. The NULL namespace is always valid and need not be
1142  * explicitly listed. Passing a NULL pointer means that only the NULL
1143  * namespace is valid.
1144  *
1145  * Both oldOptions and the result are text arrays (or NULL for "default"),
1146  * but we declare them as Datums to avoid including array.h in reloptions.h.
1147  */
1148 Datum
1149 transformRelOptions(Datum oldOptions, List *defList, const char *namspace,
1150  char *validnsps[], bool acceptOidsOff, bool isReset)
1151 {
1152  Datum result;
1153  ArrayBuildState *astate;
1154  ListCell *cell;
1155 
1156  /* no change if empty list */
1157  if (defList == NIL)
1158  return oldOptions;
1159 
1160  /* We build new array using accumArrayResult */
1161  astate = NULL;
1162 
1163  /* Copy any oldOptions that aren't to be replaced */
1164  if (PointerIsValid(DatumGetPointer(oldOptions)))
1165  {
1166  ArrayType *array = DatumGetArrayTypeP(oldOptions);
1167  Datum *oldoptions;
1168  int noldoptions;
1169  int i;
1170 
1171  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1172  &oldoptions, NULL, &noldoptions);
1173 
1174  for (i = 0; i < noldoptions; i++)
1175  {
1176  char *text_str = VARDATA(oldoptions[i]);
1177  int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
1178 
1179  /* Search for a match in defList */
1180  foreach(cell, defList)
1181  {
1182  DefElem *def = (DefElem *) lfirst(cell);
1183  int kw_len;
1184 
1185  /* ignore if not in the same namespace */
1186  if (namspace == NULL)
1187  {
1188  if (def->defnamespace != NULL)
1189  continue;
1190  }
1191  else if (def->defnamespace == NULL)
1192  continue;
1193  else if (strcmp(def->defnamespace, namspace) != 0)
1194  continue;
1195 
1196  kw_len = strlen(def->defname);
1197  if (text_len > kw_len && text_str[kw_len] == '=' &&
1198  strncmp(text_str, def->defname, kw_len) == 0)
1199  break;
1200  }
1201  if (!cell)
1202  {
1203  /* No match, so keep old option */
1204  astate = accumArrayResult(astate, oldoptions[i],
1205  false, TEXTOID,
1207  }
1208  }
1209  }
1210 
1211  /*
1212  * If CREATE/SET, add new options to array; if RESET, just check that the
1213  * user didn't say RESET (option=val). (Must do this because the grammar
1214  * doesn't enforce it.)
1215  */
1216  foreach(cell, defList)
1217  {
1218  DefElem *def = (DefElem *) lfirst(cell);
1219 
1220  if (isReset)
1221  {
1222  if (def->arg != NULL)
1223  ereport(ERROR,
1224  (errcode(ERRCODE_SYNTAX_ERROR),
1225  errmsg("RESET must not include values for parameters")));
1226  }
1227  else
1228  {
1229  text *t;
1230  const char *value;
1231  Size len;
1232 
1233  /*
1234  * Error out if the namespace is not valid. A NULL namespace is
1235  * always valid.
1236  */
1237  if (def->defnamespace != NULL)
1238  {
1239  bool valid = false;
1240  int i;
1241 
1242  if (validnsps)
1243  {
1244  for (i = 0; validnsps[i]; i++)
1245  {
1246  if (strcmp(def->defnamespace, validnsps[i]) == 0)
1247  {
1248  valid = true;
1249  break;
1250  }
1251  }
1252  }
1253 
1254  if (!valid)
1255  ereport(ERROR,
1256  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1257  errmsg("unrecognized parameter namespace \"%s\"",
1258  def->defnamespace)));
1259  }
1260 
1261  /* ignore if not in the same namespace */
1262  if (namspace == NULL)
1263  {
1264  if (def->defnamespace != NULL)
1265  continue;
1266  }
1267  else if (def->defnamespace == NULL)
1268  continue;
1269  else if (strcmp(def->defnamespace, namspace) != 0)
1270  continue;
1271 
1272  /*
1273  * Flatten the DefElem into a text string like "name=arg". If we
1274  * have just "name", assume "name=true" is meant. Note: the
1275  * namespace is not output.
1276  */
1277  if (def->arg != NULL)
1278  value = defGetString(def);
1279  else
1280  value = "true";
1281 
1282  /*
1283  * This is not a great place for this test, but there's no other
1284  * convenient place to filter the option out. As WITH (oids =
1285  * false) will be removed someday, this seems like an acceptable
1286  * amount of ugly.
1287  */
1288  if (acceptOidsOff && def->defnamespace == NULL &&
1289  strcmp(def->defname, "oids") == 0)
1290  {
1291  if (defGetBoolean(def))
1292  ereport(ERROR,
1293  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1294  errmsg("tables declared WITH OIDS are not supported")));
1295  /* skip over option, reloptions machinery doesn't know it */
1296  continue;
1297  }
1298 
1299  len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
1300  /* +1 leaves room for sprintf's trailing null */
1301  t = (text *) palloc(len + 1);
1302  SET_VARSIZE(t, len);
1303  sprintf(VARDATA(t), "%s=%s", def->defname, value);
1304 
1305  astate = accumArrayResult(astate, PointerGetDatum(t),
1306  false, TEXTOID,
1308  }
1309  }
1310 
1311  if (astate)
1312  result = makeArrayResult(astate, CurrentMemoryContext);
1313  else
1314  result = (Datum) 0;
1315 
1316  return result;
1317 }
1318 
1319 
1320 /*
1321  * Convert the text-array format of reloptions into a List of DefElem.
1322  * This is the inverse of transformRelOptions().
1323  */
1324 List *
1326 {
1327  List *result = NIL;
1328  ArrayType *array;
1329  Datum *optiondatums;
1330  int noptions;
1331  int i;
1332 
1333  /* Nothing to do if no options */
1334  if (!PointerIsValid(DatumGetPointer(options)))
1335  return result;
1336 
1337  array = DatumGetArrayTypeP(options);
1338 
1339  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1340  &optiondatums, NULL, &noptions);
1341 
1342  for (i = 0; i < noptions; i++)
1343  {
1344  char *s;
1345  char *p;
1346  Node *val = NULL;
1347 
1348  s = TextDatumGetCString(optiondatums[i]);
1349  p = strchr(s, '=');
1350  if (p)
1351  {
1352  *p++ = '\0';
1353  val = (Node *) makeString(pstrdup(p));
1354  }
1355  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
1356  }
1357 
1358  return result;
1359 }
1360 
1361 /*
1362  * Extract and parse reloptions from a pg_class tuple.
1363  *
1364  * This is a low-level routine, expected to be used by relcache code and
1365  * callers that do not have a table's relcache entry (e.g. autovacuum). For
1366  * other uses, consider grabbing the rd_options pointer from the relcache entry
1367  * instead.
1368  *
1369  * tupdesc is pg_class' tuple descriptor. amoptions is a pointer to the index
1370  * AM's options parser function in the case of a tuple corresponding to an
1371  * index, or NULL otherwise.
1372  */
1373 bytea *
1375  amoptions_function amoptions)
1376 {
1377  bytea *options;
1378  bool isnull;
1379  Datum datum;
1380  Form_pg_class classForm;
1381 
1382  datum = fastgetattr(tuple,
1383  Anum_pg_class_reloptions,
1384  tupdesc,
1385  &isnull);
1386  if (isnull)
1387  return NULL;
1388 
1389  classForm = (Form_pg_class) GETSTRUCT(tuple);
1390 
1391  /* Parse into appropriate format; don't error out here */
1392  switch (classForm->relkind)
1393  {
1394  case RELKIND_RELATION:
1395  case RELKIND_TOASTVALUE:
1396  case RELKIND_MATVIEW:
1397  options = heap_reloptions(classForm->relkind, datum, false);
1398  break;
1399  case RELKIND_PARTITIONED_TABLE:
1400  options = partitioned_table_reloptions(datum, false);
1401  break;
1402  case RELKIND_VIEW:
1403  options = view_reloptions(datum, false);
1404  break;
1405  case RELKIND_INDEX:
1406  case RELKIND_PARTITIONED_INDEX:
1407  options = index_reloptions(amoptions, datum, false);
1408  break;
1409  case RELKIND_FOREIGN_TABLE:
1410  options = NULL;
1411  break;
1412  default:
1413  Assert(false); /* can't get here */
1414  options = NULL; /* keep compiler quiet */
1415  break;
1416  }
1417 
1418  return options;
1419 }
1420 
1421 static void
1423  relopt_value *reloptions, int numoptions)
1424 {
1425  ArrayType *array = DatumGetArrayTypeP(options);
1426  Datum *optiondatums;
1427  int noptions;
1428  int i;
1429 
1430  deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
1431  &optiondatums, NULL, &noptions);
1432 
1433  for (i = 0; i < noptions; i++)
1434  {
1435  char *text_str = VARDATA(optiondatums[i]);
1436  int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
1437  int j;
1438 
1439  /* Search for a match in reloptions */
1440  for (j = 0; j < numoptions; j++)
1441  {
1442  int kw_len = reloptions[j].gen->namelen;
1443 
1444  if (text_len > kw_len && text_str[kw_len] == '=' &&
1445  strncmp(text_str, reloptions[j].gen->name, kw_len) == 0)
1446  {
1447  parse_one_reloption(&reloptions[j], text_str, text_len,
1448  validate);
1449  break;
1450  }
1451  }
1452 
1453  if (j >= numoptions && validate)
1454  {
1455  char *s;
1456  char *p;
1457 
1458  s = TextDatumGetCString(optiondatums[i]);
1459  p = strchr(s, '=');
1460  if (p)
1461  *p = '\0';
1462  ereport(ERROR,
1463  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1464  errmsg("unrecognized parameter \"%s\"", s)));
1465  }
1466  }
1467 
1468  /* It's worth avoiding memory leaks in this function */
1469  pfree(optiondatums);
1470 
1471  if (((void *) array) != DatumGetPointer(options))
1472  pfree(array);
1473 }
1474 
1475 /*
1476  * Interpret reloptions that are given in text-array format.
1477  *
1478  * options is a reloption text array as constructed by transformRelOptions.
1479  * kind specifies the family of options to be processed.
1480  *
1481  * The return value is a relopt_value * array on which the options actually
1482  * set in the options array are marked with isset=true. The length of this
1483  * array is returned in *numrelopts. Options not set are also present in the
1484  * array; this is so that the caller can easily locate the default values.
1485  *
1486  * If there are no options of the given kind, numrelopts is set to 0 and NULL
1487  * is returned (unless options are illegally supplied despite none being
1488  * defined, in which case an error occurs).
1489  *
1490  * Note: values of type int, bool and real are allocated as part of the
1491  * returned array. Values of type string are allocated separately and must
1492  * be freed by the caller.
1493  */
1494 static relopt_value *
1496  int *numrelopts)
1497 {
1498  relopt_value *reloptions = NULL;
1499  int numoptions = 0;
1500  int i;
1501  int j;
1502 
1503  if (need_initialization)
1505 
1506  /* Build a list of expected options, based on kind */
1507 
1508  for (i = 0; relOpts[i]; i++)
1509  if (relOpts[i]->kinds & kind)
1510  numoptions++;
1511 
1512  if (numoptions > 0)
1513  {
1514  reloptions = palloc(numoptions * sizeof(relopt_value));
1515 
1516  for (i = 0, j = 0; relOpts[i]; i++)
1517  {
1518  if (relOpts[i]->kinds & kind)
1519  {
1520  reloptions[j].gen = relOpts[i];
1521  reloptions[j].isset = false;
1522  j++;
1523  }
1524  }
1525  }
1526 
1527  /* Done if no options */
1528  if (PointerIsValid(DatumGetPointer(options)))
1529  parseRelOptionsInternal(options, validate, reloptions, numoptions);
1530 
1531  *numrelopts = numoptions;
1532  return reloptions;
1533 }
1534 
1535 /* Parse local unregistered options. */
1536 static relopt_value *
1538 {
1539  int nopts = list_length(relopts->options);
1540  relopt_value *values = palloc(sizeof(*values) * nopts);
1541  ListCell *lc;
1542  int i = 0;
1543 
1544  foreach(lc, relopts->options)
1545  {
1546  local_relopt *opt = lfirst(lc);
1547 
1548  values[i].gen = opt->option;
1549  values[i].isset = false;
1550 
1551  i++;
1552  }
1553 
1554  if (options != (Datum) 0)
1555  parseRelOptionsInternal(options, validate, values, nopts);
1556 
1557  return values;
1558 }
1559 
1560 /*
1561  * Subroutine for parseRelOptions, to parse and validate a single option's
1562  * value
1563  */
1564 static void
1565 parse_one_reloption(relopt_value *option, char *text_str, int text_len,
1566  bool validate)
1567 {
1568  char *value;
1569  int value_len;
1570  bool parsed;
1571  bool nofree = false;
1572 
1573  if (option->isset && validate)
1574  ereport(ERROR,
1575  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1576  errmsg("parameter \"%s\" specified more than once",
1577  option->gen->name)));
1578 
1579  value_len = text_len - option->gen->namelen - 1;
1580  value = (char *) palloc(value_len + 1);
1581  memcpy(value, text_str + option->gen->namelen + 1, value_len);
1582  value[value_len] = '\0';
1583 
1584  switch (option->gen->type)
1585  {
1586  case RELOPT_TYPE_BOOL:
1587  {
1588  parsed = parse_bool(value, &option->values.bool_val);
1589  if (validate && !parsed)
1590  ereport(ERROR,
1591  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1592  errmsg("invalid value for boolean option \"%s\": %s",
1593  option->gen->name, value)));
1594  }
1595  break;
1596  case RELOPT_TYPE_INT:
1597  {
1598  relopt_int *optint = (relopt_int *) option->gen;
1599 
1600  parsed = parse_int(value, &option->values.int_val, 0, NULL);
1601  if (validate && !parsed)
1602  ereport(ERROR,
1603  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1604  errmsg("invalid value for integer option \"%s\": %s",
1605  option->gen->name, value)));
1606  if (validate && (option->values.int_val < optint->min ||
1607  option->values.int_val > optint->max))
1608  ereport(ERROR,
1609  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1610  errmsg("value %s out of bounds for option \"%s\"",
1611  value, option->gen->name),
1612  errdetail("Valid values are between \"%d\" and \"%d\".",
1613  optint->min, optint->max)));
1614  }
1615  break;
1616  case RELOPT_TYPE_REAL:
1617  {
1618  relopt_real *optreal = (relopt_real *) option->gen;
1619 
1620  parsed = parse_real(value, &option->values.real_val, 0, NULL);
1621  if (validate && !parsed)
1622  ereport(ERROR,
1623  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1624  errmsg("invalid value for floating point option \"%s\": %s",
1625  option->gen->name, value)));
1626  if (validate && (option->values.real_val < optreal->min ||
1627  option->values.real_val > optreal->max))
1628  ereport(ERROR,
1629  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1630  errmsg("value %s out of bounds for option \"%s\"",
1631  value, option->gen->name),
1632  errdetail("Valid values are between \"%f\" and \"%f\".",
1633  optreal->min, optreal->max)));
1634  }
1635  break;
1636  case RELOPT_TYPE_ENUM:
1637  {
1638  relopt_enum *optenum = (relopt_enum *) option->gen;
1639  relopt_enum_elt_def *elt;
1640 
1641  parsed = false;
1642  for (elt = optenum->members; elt->string_val; elt++)
1643  {
1644  if (pg_strcasecmp(value, elt->string_val) == 0)
1645  {
1646  option->values.enum_val = elt->symbol_val;
1647  parsed = true;
1648  break;
1649  }
1650  }
1651  if (validate && !parsed)
1652  ereport(ERROR,
1653  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1654  errmsg("invalid value for enum option \"%s\": %s",
1655  option->gen->name, value),
1656  optenum->detailmsg ?
1657  errdetail_internal("%s", _(optenum->detailmsg)) : 0));
1658 
1659  /*
1660  * If value is not among the allowed string values, but we are
1661  * not asked to validate, just use the default numeric value.
1662  */
1663  if (!parsed)
1664  option->values.enum_val = optenum->default_val;
1665  }
1666  break;
1667  case RELOPT_TYPE_STRING:
1668  {
1669  relopt_string *optstring = (relopt_string *) option->gen;
1670 
1671  option->values.string_val = value;
1672  nofree = true;
1673  if (validate && optstring->validate_cb)
1674  (optstring->validate_cb) (value);
1675  parsed = true;
1676  }
1677  break;
1678  default:
1679  elog(ERROR, "unsupported reloption type %d", option->gen->type);
1680  parsed = true; /* quiet compiler */
1681  break;
1682  }
1683 
1684  if (parsed)
1685  option->isset = true;
1686  if (!nofree)
1687  pfree(value);
1688 }
1689 
1690 /*
1691  * Given the result from parseRelOptions, allocate a struct that's of the
1692  * specified base size plus any extra space that's needed for string variables.
1693  *
1694  * "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
1695  * equivalent).
1696  */
1697 static void *
1699 {
1700  Size size = base;
1701  int i;
1702 
1703  for (i = 0; i < numoptions; i++)
1704  {
1705  relopt_value *optval = &options[i];
1706 
1707  if (optval->gen->type == RELOPT_TYPE_STRING)
1708  {
1709  relopt_string *optstr = (relopt_string *) optval->gen;
1710 
1711  if (optstr->fill_cb)
1712  {
1713  const char *val = optval->isset ? optval->values.string_val :
1714  optstr->default_isnull ? NULL : optstr->default_val;
1715 
1716  size += optstr->fill_cb(val, NULL);
1717  }
1718  else
1719  size += GET_STRING_RELOPTION_LEN(*optval) + 1;
1720  }
1721  }
1722 
1723  return palloc0(size);
1724 }
1725 
1726 /*
1727  * Given the result of parseRelOptions and a parsing table, fill in the
1728  * struct (previously allocated with allocateReloptStruct) with the parsed
1729  * values.
1730  *
1731  * rdopts is the pointer to the allocated struct to be filled.
1732  * basesize is the sizeof(struct) that was passed to allocateReloptStruct.
1733  * options, of length numoptions, is parseRelOptions' output.
1734  * elems, of length numelems, is the table describing the allowed options.
1735  * When validate is true, it is expected that all options appear in elems.
1736  */
1737 static void
1738 fillRelOptions(void *rdopts, Size basesize,
1739  relopt_value *options, int numoptions,
1740  bool validate,
1741  const relopt_parse_elt *elems, int numelems)
1742 {
1743  int i;
1744  int offset = basesize;
1745 
1746  for (i = 0; i < numoptions; i++)
1747  {
1748  int j;
1749  bool found = false;
1750 
1751  for (j = 0; j < numelems; j++)
1752  {
1753  if (strcmp(options[i].gen->name, elems[j].optname) == 0)
1754  {
1755  relopt_string *optstring;
1756  char *itempos = ((char *) rdopts) + elems[j].offset;
1757  char *string_val;
1758 
1759  switch (options[i].gen->type)
1760  {
1761  case RELOPT_TYPE_BOOL:
1762  *(bool *) itempos = options[i].isset ?
1763  options[i].values.bool_val :
1764  ((relopt_bool *) options[i].gen)->default_val;
1765  break;
1766  case RELOPT_TYPE_INT:
1767  *(int *) itempos = options[i].isset ?
1768  options[i].values.int_val :
1769  ((relopt_int *) options[i].gen)->default_val;
1770  break;
1771  case RELOPT_TYPE_REAL:
1772  *(double *) itempos = options[i].isset ?
1773  options[i].values.real_val :
1774  ((relopt_real *) options[i].gen)->default_val;
1775  break;
1776  case RELOPT_TYPE_ENUM:
1777  *(int *) itempos = options[i].isset ?
1778  options[i].values.enum_val :
1779  ((relopt_enum *) options[i].gen)->default_val;
1780  break;
1781  case RELOPT_TYPE_STRING:
1782  optstring = (relopt_string *) options[i].gen;
1783  if (options[i].isset)
1784  string_val = options[i].values.string_val;
1785  else if (!optstring->default_isnull)
1786  string_val = optstring->default_val;
1787  else
1788  string_val = NULL;
1789 
1790  if (optstring->fill_cb)
1791  {
1792  Size size =
1793  optstring->fill_cb(string_val,
1794  (char *) rdopts + offset);
1795 
1796  if (size)
1797  {
1798  *(int *) itempos = offset;
1799  offset += size;
1800  }
1801  else
1802  *(int *) itempos = 0;
1803  }
1804  else if (string_val == NULL)
1805  *(int *) itempos = 0;
1806  else
1807  {
1808  strcpy((char *) rdopts + offset, string_val);
1809  *(int *) itempos = offset;
1810  offset += strlen(string_val) + 1;
1811  }
1812  break;
1813  default:
1814  elog(ERROR, "unsupported reloption type %d",
1815  options[i].gen->type);
1816  break;
1817  }
1818  found = true;
1819  break;
1820  }
1821  }
1822  if (validate && !found)
1823  elog(ERROR, "reloption \"%s\" not found in parse table",
1824  options[i].gen->name);
1825  }
1826  SET_VARSIZE(rdopts, offset);
1827 }
1828 
1829 
1830 /*
1831  * Option parser for anything that uses StdRdOptions.
1832  */
1833 bytea *
1834 default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
1835 {
1836  static const relopt_parse_elt tab[] = {
1837  {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
1838  {"autovacuum_enabled", RELOPT_TYPE_BOOL,
1839  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
1840  {"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
1841  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
1842  {"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT,
1843  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)},
1844  {"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
1845  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
1846  {"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
1847  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
1848  {"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
1849  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
1850  {"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
1851  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
1852  {"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
1853  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
1854  {"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
1855  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
1856  {"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
1857  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
1858  {"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
1859  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1860  {"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1861  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1862  {"toast_tuple_target", RELOPT_TYPE_INT,
1863  offsetof(StdRdOptions, toast_tuple_target)},
1864  {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
1865  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
1866  {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
1867  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
1868  {"autovacuum_vacuum_insert_scale_factor", RELOPT_TYPE_REAL,
1869  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
1870  {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
1871  offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
1872  {"user_catalog_table", RELOPT_TYPE_BOOL,
1873  offsetof(StdRdOptions, user_catalog_table)},
1874  {"parallel_workers", RELOPT_TYPE_INT,
1875  offsetof(StdRdOptions, parallel_workers)},
1876  {"vacuum_index_cleanup", RELOPT_TYPE_BOOL,
1877  offsetof(StdRdOptions, vacuum_index_cleanup)},
1878  {"vacuum_truncate", RELOPT_TYPE_BOOL,
1879  offsetof(StdRdOptions, vacuum_truncate)}
1880  };
1881 
1882  return (bytea *) build_reloptions(reloptions, validate, kind,
1883  sizeof(StdRdOptions),
1884  tab, lengthof(tab));
1885 }
1886 
1887 /*
1888  * build_reloptions
1889  *
1890  * Parses "reloptions" provided by the caller, returning them in a
1891  * structure containing the parsed options. The parsing is done with
1892  * the help of a parsing table describing the allowed options, defined
1893  * by "relopt_elems" of length "num_relopt_elems".
1894  *
1895  * "validate" must be true if reloptions value is freshly built by
1896  * transformRelOptions(), as opposed to being read from the catalog, in which
1897  * case the values contained in it must already be valid.
1898  *
1899  * NULL is returned if the passed-in options did not match any of the options
1900  * in the parsing table, unless validate is true in which case an error would
1901  * be reported.
1902  */
1903 void *
1904 build_reloptions(Datum reloptions, bool validate,
1905  relopt_kind kind,
1906  Size relopt_struct_size,
1907  const relopt_parse_elt *relopt_elems,
1908  int num_relopt_elems)
1909 {
1910  int numoptions;
1912  void *rdopts;
1913 
1914  /* parse options specific to given relation option kind */
1915  options = parseRelOptions(reloptions, validate, kind, &numoptions);
1916  Assert(numoptions <= num_relopt_elems);
1917 
1918  /* if none set, we're done */
1919  if (numoptions == 0)
1920  {
1921  Assert(options == NULL);
1922  return NULL;
1923  }
1924 
1925  /* allocate and fill the structure */
1926  rdopts = allocateReloptStruct(relopt_struct_size, options, numoptions);
1927  fillRelOptions(rdopts, relopt_struct_size, options, numoptions,
1928  validate, relopt_elems, num_relopt_elems);
1929 
1930  pfree(options);
1931 
1932  return rdopts;
1933 }
1934 
1935 /*
1936  * Parse local options, allocate a bytea struct that's of the specified
1937  * 'base_size' plus any extra space that's needed for string variables,
1938  * fill its option's fields located at the given offsets and return it.
1939  */
1940 void *
1942 {
1943  int noptions = list_length(relopts->options);
1944  relopt_parse_elt *elems = palloc(sizeof(*elems) * noptions);
1945  relopt_value *vals;
1946  void *opts;
1947  int i = 0;
1948  ListCell *lc;
1949 
1950  foreach(lc, relopts->options)
1951  {
1952  local_relopt *opt = lfirst(lc);
1953 
1954  elems[i].optname = opt->option->name;
1955  elems[i].opttype = opt->option->type;
1956  elems[i].offset = opt->offset;
1957 
1958  i++;
1959  }
1960 
1961  vals = parseLocalRelOptions(relopts, options, validate);
1962  opts = allocateReloptStruct(relopts->relopt_struct_size, vals, noptions);
1963  fillRelOptions(opts, relopts->relopt_struct_size, vals, noptions, validate,
1964  elems, noptions);
1965 
1966  foreach(lc, relopts->validators)
1967  ((relopts_validator) lfirst(lc)) (opts, vals, noptions);
1968 
1969  if (elems)
1970  pfree(elems);
1971 
1972  return opts;
1973 }
1974 
1975 /*
1976  * Option parser for partitioned tables
1977  */
1978 bytea *
1979 partitioned_table_reloptions(Datum reloptions, bool validate)
1980 {
1981  /*
1982  * autovacuum_enabled, autovacuum_analyze_threshold and
1983  * autovacuum_analyze_scale_factor are supported for partitioned tables.
1984  */
1985 
1986  return default_reloptions(reloptions, validate, RELOPT_KIND_PARTITIONED);
1987 }
1988 
1989 /*
1990  * Option parser for views
1991  */
1992 bytea *
1993 view_reloptions(Datum reloptions, bool validate)
1994 {
1995  static const relopt_parse_elt tab[] = {
1996  {"security_barrier", RELOPT_TYPE_BOOL,
1997  offsetof(ViewOptions, security_barrier)},
1998  {"check_option", RELOPT_TYPE_ENUM,
1999  offsetof(ViewOptions, check_option)}
2000  };
2001 
2002  return (bytea *) build_reloptions(reloptions, validate,
2004  sizeof(ViewOptions),
2005  tab, lengthof(tab));
2006 }
2007 
2008 /*
2009  * Parse options for heaps, views and toast tables.
2010  */
2011 bytea *
2012 heap_reloptions(char relkind, Datum reloptions, bool validate)
2013 {
2014  StdRdOptions *rdopts;
2015 
2016  switch (relkind)
2017  {
2018  case RELKIND_TOASTVALUE:
2019  rdopts = (StdRdOptions *)
2020  default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
2021  if (rdopts != NULL)
2022  {
2023  /* adjust default-only parameters for TOAST relations */
2024  rdopts->fillfactor = 100;
2025  rdopts->autovacuum.analyze_threshold = -1;
2026  rdopts->autovacuum.analyze_scale_factor = -1;
2027  }
2028  return (bytea *) rdopts;
2029  case RELKIND_RELATION:
2030  case RELKIND_MATVIEW:
2031  return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
2032  default:
2033  /* other relkinds are not supported */
2034  return NULL;
2035  }
2036 }
2037 
2038 
2039 /*
2040  * Parse options for indexes.
2041  *
2042  * amoptions index AM's option parser function
2043  * reloptions options as text[] datum
2044  * validate error flag
2045  */
2046 bytea *
2047 index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
2048 {
2049  Assert(amoptions != NULL);
2050 
2051  /* Assume function is strict */
2052  if (!PointerIsValid(DatumGetPointer(reloptions)))
2053  return NULL;
2054 
2055  return amoptions(reloptions, validate);
2056 }
2057 
2058 /*
2059  * Option parser for attribute reloptions
2060  */
2061 bytea *
2062 attribute_reloptions(Datum reloptions, bool validate)
2063 {
2064  static const relopt_parse_elt tab[] = {
2065  {"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2066  {"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2067  };
2068 
2069  return (bytea *) build_reloptions(reloptions, validate,
2071  sizeof(AttributeOpts),
2072  tab, lengthof(tab));
2073 }
2074 
2075 /*
2076  * Option parser for tablespace reloptions
2077  */
2078 bytea *
2079 tablespace_reloptions(Datum reloptions, bool validate)
2080 {
2081  static const relopt_parse_elt tab[] = {
2082  {"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
2083  {"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
2084  {"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
2085  {"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
2086  };
2087 
2088  return (bytea *) build_reloptions(reloptions, validate,
2090  sizeof(TableSpaceOpts),
2091  tab, lengthof(tab));
2092 }
2093 
2094 /*
2095  * Determine the required LOCKMODE from an option list.
2096  *
2097  * Called from AlterTableGetLockLevel(), see that function
2098  * for a longer explanation of how this works.
2099  */
2100 LOCKMODE
2102 {
2103  LOCKMODE lockmode = NoLock;
2104  ListCell *cell;
2105 
2106  if (defList == NIL)
2107  return AccessExclusiveLock;
2108 
2109  if (need_initialization)
2111 
2112  foreach(cell, defList)
2113  {
2114  DefElem *def = (DefElem *) lfirst(cell);
2115  int i;
2116 
2117  for (i = 0; relOpts[i]; i++)
2118  {
2119  if (strncmp(relOpts[i]->name,
2120  def->defname,
2121  relOpts[i]->namelen + 1) == 0)
2122  {
2123  if (lockmode < relOpts[i]->lockmode)
2124  lockmode = relOpts[i]->lockmode;
2125  }
2126  }
2127  }
2128 
2129  return lockmode;
2130 }
Value * makeString(char *str)
Definition: value.c:53
static relopt_value * parseLocalRelOptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1537
#define HASH_DEFAULT_FILLFACTOR
Definition: hash.h:294
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:2012
#define NIL
Definition: pg_list.h:65
bool bool_val
Definition: reloptions.h:82
#define MAX_IO_CONCURRENCY
Definition: bufmgr.h:88
static void initialize_reloptions(void)
Definition: reloptions.c:573
relopt_type opttype
Definition: reloptions.h:153
#define HASH_MIN_FILLFACTOR
Definition: hash.h:293
static relopt_gen ** custom_options
Definition: reloptions.c:550
#define SPGIST_MIN_FILLFACTOR
void init_local_reloptions(local_relopts *opts, Size relopt_struct_size)
Definition: reloptions.c:727
relopt_gen gen
Definition: reloptions.h:125
int maintenance_io_concurrency
Definition: bufmgr.c:150
char * string_val
Definition: reloptions.h:86
#define VARDATA(PTR)
Definition: postgres.h:315
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
struct relopt_string relopt_string
#define fastgetattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:711
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:1149
const char * desc
Definition: reloptions.h:68
int LOCKMODE
Definition: lockdefs.h:26
void add_local_real_reloption(local_relopts *relopts, const char *name, const char *desc, double default_val, double min_val, double max_val, int offset)
Definition: reloptions.c:965
struct relopt_enum relopt_enum
#define VARSIZE(PTR)
Definition: postgres.h:316
#define PointerGetDatum(X)
Definition: postgres.h:600
relopt_enum_elt_def StdRdOptIndexCleanupValues[]
Definition: reloptions.c:469
LOCKMODE lockmode
Definition: reloptions.h:70
#define VARHDRSZ
Definition: c.h:627
char * pstrdup(const char *in)
Definition: mcxt.c:1299
void * build_local_reloptions(local_relopts *relopts, Datum options, bool validate)
Definition: reloptions.c:1941
List * validators
Definition: reloptions.h:168
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
char * defnamespace
Definition: parsenodes.h:745
static relopt_bool boolRelOpts[]
Definition: reloptions.c:96
#define gettext_noop(x)
Definition: c.h:1197
bytea * tablespace_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2079
Definition: nodes.h:539
bool default_isnull
Definition: reloptions.h:143
int fillfactor
Definition: rel.h:321
int errcode(int sqlerrcode)
Definition: elog.c:698
static void * allocateReloptStruct(Size base, relopt_value *options, int numoptions)
Definition: reloptions.c:1698
bool parse_real(const char *value, double *result, int flags, const char **hintmsg)
Definition: guc.c:6925
bool default_val
Definition: reloptions.h:94
bool parse_bool(const char *value, bool *result)
Definition: bool.c:30
relopt_gen gen
Definition: reloptions.h:141
relopt_enum_elt_def gistBufferingOptValues[]
Definition: reloptions.c:484
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define lengthof(array)
Definition: c.h:734
relopt_gen * gen
Definition: reloptions.h:78
void add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:894
struct relopt_bool relopt_bool
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
void add_local_int_reloption(local_relopts *relopts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)
Definition: reloptions.c:911
int effective_io_concurrency
Definition: bufmgr.c:143
bytea * attribute_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:2062
#define TOAST_TUPLE_TARGET
Definition: heaptoast.h:50
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1904
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
union relopt_value::@44 values
#define GET_STRING_RELOPTION_LEN(option)
Definition: reloptions.c:562
void add_local_string_reloption(local_relopts *relopts, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, int offset)
Definition: reloptions.c:1111
struct relopt_real relopt_real
bytea * view_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1993
List * options
Definition: reloptions.h:167
#define sprintf
Definition: port.h:218
double default_val
Definition: reloptions.h:108
#define SPGIST_DEFAULT_FILLFACTOR
double random_page_cost
Definition: costsize.c:120
bool defGetBoolean(DefElem *def)
Definition: define.c:111
void pfree(void *pointer)
Definition: mcxt.c:1169
static relopt_int * init_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:874
#define MAX_KILOBYTES
Definition: guc.h:26
Size relopt_struct_size
Definition: reloptions.h:169
static relopt_gen * allocate_reloption(bits32 kinds, int type, const char *name, const char *desc, LOCKMODE lockmode)
Definition: reloptions.c:768
#define ERROR
Definition: elog.h:46
const char * detailmsg
Definition: reloptions.h:128
static void parse_one_reloption(relopt_value *option, char *text_str, int text_len, bool validate)
Definition: reloptions.c:1565
static int num_custom_options
Definition: reloptions.c:549
int fillfactor
Definition: pgbench.c:197
char * defGetString(DefElem *def)
Definition: define.c:49
relopt_gen gen
Definition: reloptions.h:93
int analyze_threshold
Definition: rel.h:295
#define NoLock
Definition: lockdefs.h:34
static relopt_real * init_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:927
bool DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
Definition: lock.c:583
static relopt_real realRelOpts[]
Definition: reloptions.c:381
static void fillRelOptions(void *rdopts, Size basesize, relopt_value *options, int numoptions, bool validate, const relopt_parse_elt *elems, int numelems)
Definition: reloptions.c:1738
int errdetail(const char *fmt,...)
Definition: elog.c:1042
int namelen
Definition: reloptions.h:71
relopt_enum_elt_def * members
Definition: reloptions.h:126
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
double real_val
Definition: reloptions.h:84
#define GIST_DEFAULT_FILLFACTOR
Definition: gist_private.h:479
#define TOAST_TUPLE_TARGET_MAIN
Definition: heaptoast.h:61
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5151
#define BTREE_DEFAULT_FILLFACTOR
Definition: nbtree.h:199
static relopt_value * parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts)
Definition: reloptions.c:1495
validate_string_relopt validate_cb
Definition: reloptions.h:144
relopt_gen * option
Definition: reloptions.h:160
MemoryContext TopMemoryContext
Definition: mcxt.c:48
static AmcheckOptions opts
Definition: pg_amcheck.c:111
Node * arg
Definition: parsenodes.h:747
List * lappend(List *list, void *datum)
Definition: list.c:336
#define BTREE_MIN_FILLFACTOR
Definition: nbtree.h:198
static char ** options
bits32 kinds
Definition: reloptions.h:69
bytea * partitioned_table_reloptions(Datum reloptions, bool validate)
Definition: reloptions.c:1979
int default_val
Definition: reloptions.h:127
relopt_enum_elt_def viewCheckOptValues[]
Definition: reloptions.c:493
#define TextDatumGetCString(d)
Definition: builtins.h:83
Size(* fill_string_relopt)(const char *value, void *ptr)
Definition: reloptions.h:134
void * palloc0(Size size)
Definition: mcxt.c:1093
uintptr_t Datum
Definition: postgres.h:411
static relopt_enum * init_enum_reloption(bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
Definition: reloptions.c:982
relopt_gen gen
Definition: reloptions.h:99
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:6835
const char * optname
Definition: reloptions.h:152
static void add_local_reloption(local_relopts *relopts, relopt_gen *newoption, int offset)
Definition: reloptions.c:750
List * untransformRelOptions(Datum options)
Definition: reloptions.c:1325
bytea * extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, amoptions_function amoptions)
Definition: reloptions.c:1374
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:157
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Definition: reloptions.c:2047
void(* relopts_validator)(void *parsed_options, relopt_value *vals, int nvals)
Definition: reloptions.h:137
float8 analyze_scale_factor
Definition: rel.h:307
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
uint32 bits32
Definition: c.h:450
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
void(* validate_string_relopt)(const char *value)
Definition: reloptions.h:133
#define HEAP_MIN_FILLFACTOR
Definition: rel.h:331
relopt_type type
Definition: reloptions.h:72
#define GIST_MIN_FILLFACTOR
Definition: gist_private.h:478
struct relopt_int relopt_int
size_t Size
Definition: c.h:540
void add_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val, double min_val, double max_val, LOCKMODE lockmode)
Definition: reloptions.c:947
const char * string_val
Definition: reloptions.h:119
static int list_length(const List *l)
Definition: pg_list.h:149
static void add_reloption(relopt_gen *newoption)
Definition: reloptions.c:693
static relopt_string * init_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, fill_string_relopt filler, LOCKMODE lockmode)
Definition: reloptions.c:1046
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList)
Definition: reloptions.c:2101
relopt_gen gen
Definition: reloptions.h:107
const char * name
Definition: encode.c:515
void add_local_bool_reloption(local_relopts *relopts, const char *name, const char *desc, bool default_val, int offset)
Definition: reloptions.c:858
static relopt_string stringRelOpts[]
Definition: reloptions.c:540
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:676
#define DatumGetPointer(X)
Definition: postgres.h:593
int default_val
Definition: reloptions.h:100
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3490
static Datum values[MAXATTR]
Definition: bootstrap.c:166
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5087
#define AccessExclusiveLock
Definition: lockdefs.h:45
bytea * default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
Definition: reloptions.c:1834
static void parseRelOptionsInternal(Datum options, bool validate, relopt_value *reloptions, int numoptions)
Definition: reloptions.c:1422
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
void add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val, validate_string_relopt validator, LOCKMODE lockmode)
Definition: reloptions.c:1091
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1286
const char * name
Definition: reloptions.h:66
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
relopt_kind
Definition: reloptions.h:39
fill_string_relopt fill_cb
Definition: reloptions.h:145
#define elog(elevel,...)
Definition: elog.h:232
int i
static bool need_initialization
Definition: reloptions.c:551
Definition: c.h:621
char * defname
Definition: parsenodes.h:746
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Definition: amapi.h:140
static relopt_enum enumRelOpts[]
Definition: reloptions.c:501
#define HEAP_DEFAULT_FILLFACTOR
Definition: rel.h:332
static relopt_bool * init_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:825
static relopt_int intRelOpts[]
Definition: reloptions.c:166
char * default_val
Definition: reloptions.h:146
static relopt_gen ** relOpts
Definition: reloptions.c:546
double max
Definition: reloptions.h:110
void add_enum_reloption(bits32 kinds, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, LOCKMODE lockmode)
Definition: reloptions.c:1011
double seq_page_cost
Definition: costsize.c:119
static size_t noptions
static bits32 last_assigned_kind
Definition: reloptions.c:547
void add_local_enum_reloption(local_relopts *relopts, const char *name, const char *desc, relopt_enum_elt_def *members, int default_val, const char *detailmsg, int offset)
Definition: reloptions.c:1029
void add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val, LOCKMODE lockmode)
Definition: reloptions.c:842
Definition: pg_list.h:50
#define PointerIsValid(pointer)
Definition: c.h:698
void register_reloptions_validator(local_relopts *opts, relopts_validator validator)
Definition: reloptions.c:740
#define _(x)
Definition: elog.c:89
long val
Definition: informix.c:664
double min
Definition: reloptions.h:109
#define offsetof(type, field)
Definition: c.h:727
#define DatumGetArrayTypeP(X)
Definition: array.h:254
AutoVacOpts autovacuum
Definition: rel.h:324