LCOV - differential code coverage report
Current view: top level - src/backend/access/common - reloptions.c (source / functions) Coverage Total Hit UNC UBC GNC CBC DCB
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 90.7 % 561 509 52 9 500 9
Current Date: 2025-09-06 07:49:51 +0900 Functions: 92.7 % 41 38 3 2 36 1
Baseline: lcov-20250906-005545-baseline Branches: 79.1 % 373 295 2 76 6 289
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 94.7 % 19 18 1 9 9
(360..) days: 90.6 % 542 491 51 491
Function coverage date bins:
(30,360] days: 100.0 % 1 1 1
(360..) days: 92.5 % 40 37 3 1 36
Branch coverage date bins:
(30,360] days: 68.8 % 16 11 2 3 6 5
(360..) days: 79.6 % 357 284 73 284

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

Generated by: LCOV version 2.4-beta