Fill CommonRdOptions with default values in extract_autovac_opts()
authorAlexander Korotkov <[email protected]>
Mon, 8 Apr 2024 09:11:56 +0000 (12:11 +0300)
committerAlexander Korotkov <[email protected]>
Mon, 8 Apr 2024 09:18:23 +0000 (12:18 +0300)
Reported-by: Thomas Munro
Reported-by: Pavel Borisov
Discussion: https://postgr.es/m/CA%2BhUKGLZzLR50RBvuqOO3MZ%3DF54ETz-rTp1PDX9uDGP_GqyYqA%40mail.gmail.com

src/backend/access/common/reloptions.c
src/backend/postmaster/autovacuum.c
src/backend/utils/cache/relcache.c
src/include/access/reloptions.h

index c1de092a42dcdfeffa5ffda154cfc54cd094d626..24245f717283112d7b6ec6721bce7ffe46bfa4a3 100644 (file)
@@ -2056,6 +2056,34 @@ view_reloptions(Datum reloptions, bool validate)
                                      tab, lengthof(tab));
 }
 
+/*
+ * Fill CommonRdOptions with the default values.
+ */
+void
+fill_default_common_reloptions(CommonRdOptions *common)
+{
+   common->autovacuum.enabled = true;
+   common->autovacuum.vacuum_threshold = -1;
+   common->autovacuum.vacuum_ins_threshold = -2;
+   common->autovacuum.analyze_threshold = -1;
+   common->autovacuum.vacuum_cost_limit = -1;
+   common->autovacuum.freeze_min_age = -1;
+   common->autovacuum.freeze_max_age = -1;
+   common->autovacuum.freeze_table_age = -1;
+   common->autovacuum.multixact_freeze_min_age = -1;
+   common->autovacuum.multixact_freeze_max_age = -1;
+   common->autovacuum.multixact_freeze_table_age = -1;
+   common->autovacuum.log_min_duration = -1;
+   common->autovacuum.vacuum_cost_delay = -1;
+   common->autovacuum.vacuum_scale_factor = -1;
+   common->autovacuum.vacuum_ins_scale_factor = -1;
+   common->autovacuum.analyze_scale_factor = -1;
+   common->parallel_workers = -1;
+   common->user_catalog_table = false;
+   common->vacuum_index_cleanup = STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO;
+   common->vacuum_truncate = true;
+}
+
 /*
  * Parse options for heaps, views and toast tables.
  */
index 7cb79ebcedd21d8441aadc1c71d6e1452d90f2bd..170b973cc52b931cf952ea18c02236f170fea3f4 100644 (file)
@@ -2681,6 +2681,7 @@ extract_autovac_opts(HeapTuple tup, TupleDesc pg_class_desc)
           ((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_MATVIEW ||
           ((Form_pg_class) GETSTRUCT(tup))->relkind == RELKIND_TOASTVALUE);
 
+   fill_default_common_reloptions(&common);
    relopts = extractRelOptions(tup, pg_class_desc,
                                GetTableAmRoutineByAmOid(((Form_pg_class) GETSTRUCT(tup))->relam),
                                NULL, &common);
index f6f60c21fab5fddf42f89f33caaed8cd41975497..8fa09a5d75576b1c80b91f2116ea341cb4f06c9e 100644 (file)
@@ -480,26 +480,7 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
    {
        common = MemoryContextAlloc(CacheMemoryContext,
                                    sizeof(CommonRdOptions));
-       common->autovacuum.enabled = true;
-       common->autovacuum.vacuum_threshold = -1;
-       common->autovacuum.vacuum_ins_threshold = -2;
-       common->autovacuum.analyze_threshold = -1;
-       common->autovacuum.vacuum_cost_limit = -1;
-       common->autovacuum.freeze_min_age = -1;
-       common->autovacuum.freeze_max_age = -1;
-       common->autovacuum.freeze_table_age = -1;
-       common->autovacuum.multixact_freeze_min_age = -1;
-       common->autovacuum.multixact_freeze_max_age = -1;
-       common->autovacuum.multixact_freeze_table_age = -1;
-       common->autovacuum.log_min_duration = -1;
-       common->autovacuum.vacuum_cost_delay = -1;
-       common->autovacuum.vacuum_scale_factor = -1;
-       common->autovacuum.vacuum_ins_scale_factor = -1;
-       common->autovacuum.analyze_scale_factor = -1;
-       common->parallel_workers = -1;
-       common->user_catalog_table = false;
-       common->vacuum_index_cleanup = STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO;
-       common->vacuum_truncate = true;
+       fill_default_common_reloptions(common);
        relation->rd_common_options = common;
    }
    else
index 342b9cdd6ed4128072c7412c556b17b9c88aa554..a3560500f36c17da7b7749e14e1450fe726b4112 100644 (file)
@@ -236,6 +236,7 @@ extern void *build_reloptions(Datum reloptions, bool validate,
 extern void *build_local_reloptions(local_relopts *relopts, Datum options,
                                    bool validate);
 
+extern void fill_default_common_reloptions(CommonRdOptions *common);
 extern bytea *heap_reloptions(char relkind, Datum reloptions,
                              CommonRdOptions *common, bool validate);
 extern bytea *view_reloptions(Datum reloptions, bool validate);