Split handling of reloptions for partitioned tables
authorMichael Paquier <[email protected]>
Thu, 14 Nov 2019 03:34:28 +0000 (12:34 +0900)
committerMichael Paquier <[email protected]>
Thu, 14 Nov 2019 03:34:28 +0000 (12:34 +0900)
Partitioned tables do not have relation options yet, but, similarly to
what's done for views which have their own parsing table, it could make
sense to introduce new parameters for some of the existing default ones
like fillfactor, autovacuum, etc.  Splitting things has the advantage to
make the information stored in rd_options include only the necessary
information, reducing the amount of memory used for a relcache entry
with partitioned tables if new reloptions are introduced at this level.

Author:  Nikolay Shaplov
Reviewed-by: Amit Langote, Michael Paquier
Discussion: https://postgr.es/m/1627387.Qykg9O6zpu@x200m

src/backend/access/common/reloptions.c
src/backend/commands/tablecmds.c
src/include/access/reloptions.h

index d8790ad7a387cf982cef76ec297a13716d8d1c09..feb105e1ba1eb6ad7654d3814ad5a157a8da127f 100644 (file)
@@ -1099,9 +1099,11 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
                case RELKIND_RELATION:
                case RELKIND_TOASTVALUE:
                case RELKIND_MATVIEW:
-               case RELKIND_PARTITIONED_TABLE:
                        options = heap_reloptions(classForm->relkind, datum, false);
                        break;
+               case RELKIND_PARTITIONED_TABLE:
+                       options = partitioned_table_reloptions(datum, false);
+                       break;
                case RELKIND_VIEW:
                        options = view_reloptions(datum, false);
                        break;
@@ -1571,6 +1573,21 @@ build_reloptions(Datum reloptions, bool validate,
        return rdopts;
 }
 
+/*
+ * Option parser for partitioned tables
+ */
+bytea *
+partitioned_table_reloptions(Datum reloptions, bool validate)
+{
+       /*
+        * There are no options for partitioned tables yet, but this is able to do
+        * some validation.
+        */
+       return (bytea *) build_reloptions(reloptions, validate,
+                                                                         RELOPT_KIND_PARTITIONED,
+                                                                         0, NULL, 0);
+}
+
 /*
  * Option parser for views
  */
@@ -1614,9 +1631,6 @@ heap_reloptions(char relkind, Datum reloptions, bool validate)
                case RELKIND_RELATION:
                case RELKIND_MATVIEW:
                        return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
-               case RELKIND_PARTITIONED_TABLE:
-                       return default_reloptions(reloptions, validate,
-                                                                         RELOPT_KIND_PARTITIONED);
                default:
                        /* other relkinds are not supported */
                        return NULL;
index 496c2063329e97cbe62eb97549837cde1f655aad..45aae5955d0a7075abf7ffe301b180b55f17a97e 100644 (file)
@@ -719,10 +719,17 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
        reloptions = transformRelOptions((Datum) 0, stmt->options, NULL, validnsps,
                                                                         true, false);
 
-       if (relkind == RELKIND_VIEW)
-               (void) view_reloptions(reloptions, true);
-       else
-               (void) heap_reloptions(relkind, reloptions, true);
+       switch (relkind)
+       {
+               case RELKIND_VIEW:
+                       (void) view_reloptions(reloptions, true);
+                       break;
+               case RELKIND_PARTITIONED_TABLE:
+                       (void) partitioned_table_reloptions(reloptions, true);
+                       break;
+               default:
+                       (void) heap_reloptions(relkind, reloptions, true);
+       }
 
        if (stmt->ofTypename)
        {
@@ -12187,9 +12194,11 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
                case RELKIND_RELATION:
                case RELKIND_TOASTVALUE:
                case RELKIND_MATVIEW:
-               case RELKIND_PARTITIONED_TABLE:
                        (void) heap_reloptions(rel->rd_rel->relkind, newOptions, true);
                        break;
+               case RELKIND_PARTITIONED_TABLE:
+                       (void) partitioned_table_reloptions(newOptions, true);
+                       break;
                case RELKIND_VIEW:
                        (void) view_reloptions(newOptions, true);
                        break;
index db42aa35e081f06f1495d51352235bd00b60df89..ee7248ad582123f0fae57b9fcfe00423fa75f1c5 100644 (file)
@@ -306,6 +306,7 @@ extern bytea *default_reloptions(Datum reloptions, bool validate,
                                                                 relopt_kind kind);
 extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
 extern bytea *view_reloptions(Datum reloptions, bool validate);
+extern bytea *partitioned_table_reloptions(Datum reloptions, bool validate);
 extern bytea *index_reloptions(amoptions_function amoptions, Datum reloptions,
                                                           bool validate);
 extern bytea *attribute_reloptions(Datum reloptions, bool validate);