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