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