Re: Move pg_attribute.attcompression to earlier in struct for reduced size?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Move pg_attribute.attcompression to earlier in struct for reduced size?
Дата
Msg-id 1505124.1622042026@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Move pg_attribute.attcompression to earlier in struct for reduced size?  (Andres Freund <andres@anarazel.de>)
Ответы Re: Move pg_attribute.attcompression to earlier in struct for reduced size?  (Robert Haas <robertmhaas@gmail.com>)
Re: Move pg_attribute.attcompression to earlier in struct for reduced size?  (Justin Pryzby <pryzby@telsasoft.com>)
Список pgsql-hackers
Michael Paquier <michael@paquier.xyz> writes:
> Ah, the parallel with reltablespace and default_tablespace at database
> level is a very good point.  It is true that currently the code would
> assign attcompression to a non-zero value once the relation is defined
> depending on default_toast_compression set for the database, but
> setting it to 0 in this case would be really helpful to change the
> compression methods of all the relations if doing something as crazy
> as a VACUUM FULL for this database.  Count me as convinced.

Here's a draft patch series to address this.

0001 removes the relkind checks I was questioning originally.
As expected, this results in zero changes in check-world results.

0002 is the main change in the semantics of attcompression.
This does change the results of compression.sql, but in what
seem to me to be expected ways: a column's compression option
is now shown in \d+ output only if you explicitly set it.

0003 further removes pg_dump's special handling of
default_toast_compression.  I don't think we need that anymore.
AFAICS its only effect would be to override the receiving server's
default_toast_compression setting for dumped/re-loaded data, which
does not seem like a behavior that anyone would want.

Loose ends:

* I've not reviewed the docs fully; there are likely some more
things that need updated.

* As things stand here, once you've applied ALTER ... SET COMPRESSION
to select a specific method, there is no way to undo that and go
back to the use-the-default setting.  All you can do is change to
explicitly select the other method.  Should we invent "ALTER ...
SET COMPRESSION default" or the like to cover that?  (Since
DEFAULT is a reserved word, that exact syntax might be a bit of
a pain to implement, but maybe we could think of another word.)

* I find GetDefaultToastCompression() annoying.  I do not think
it is project style to invent trivial wrapper functions around
GUC variable references: it buys nothing while requiring readers
to remember one more name than they would otherwise.  Since there
are only two uses remaining, maybe this isn't very important either
way, but I'm still inclined to flush it.

Comments?

            regards, tom lane

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 11e91c4ad3..69b1839fd7 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -897,17 +897,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
         if (colDef->generated)
             attr->attgenerated = colDef->generated;

-        /*
-         * lookup attribute's compression method and store it in the
-         * attr->attcompression.
-         */
-        if (relkind == RELKIND_RELATION ||
-            relkind == RELKIND_PARTITIONED_TABLE ||
-            relkind == RELKIND_MATVIEW)
-            attr->attcompression =
-                GetAttributeCompression(attr, colDef->compression);
-        else
-            attr->attcompression = InvalidCompressionMethod;
+        attr->attcompression = GetAttributeCompression(attr,
+                                                       colDef->compression);
     }

     /*
@@ -6602,13 +6593,8 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
     attribute.attbyval = tform->typbyval;
     attribute.attalign = tform->typalign;
     attribute.attstorage = tform->typstorage;
-    /* do not set compression in views etc */
-    if (rel->rd_rel->relkind == RELKIND_RELATION ||
-        rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
-        attribute.attcompression = GetAttributeCompression(&attribute,
-                                                           colDef->compression);
-    else
-        attribute.attcompression = InvalidCompressionMethod;
+    attribute.attcompression = GetAttributeCompression(&attribute,
+                                                       colDef->compression);
     attribute.attnotnull = colDef->is_not_null;
     attribute.atthasdef = false;
     attribute.atthasmissing = false;
@@ -12299,23 +12285,10 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
     attTup->attbyval = tform->typbyval;
     attTup->attalign = tform->typalign;
     attTup->attstorage = tform->typstorage;
-
-    /* Setup attribute compression */
-    if (rel->rd_rel->relkind == RELKIND_RELATION ||
-        rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
-    {
-        /*
-         * No compression for plain/external storage, otherwise, default
-         * compression method if it is not already set, refer comments atop
-         * attcompression parameter in pg_attribute.h.
-         */
-        if (!IsStorageCompressible(tform->typstorage))
-            attTup->attcompression = InvalidCompressionMethod;
-        else if (!CompressionMethodIsValid(attTup->attcompression))
-            attTup->attcompression = GetDefaultToastCompression();
-    }
-    else
+    if (!IsStorageCompressible(tform->typstorage))
         attTup->attcompression = InvalidCompressionMethod;
+    else if (!CompressionMethodIsValid(attTup->attcompression))
+        attTup->attcompression = GetDefaultToastCompression();

     ReleaseSysCache(typeTuple);

diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index b26b872a06..16493209c6 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -1261,10 +1261,14 @@
        <structfield>attcompression</structfield> <type>char</type>
       </para>
       <para>
-       The current compression method of the column.  If it is an invalid
-       compression method (<literal>'\0'</literal>) then column data will not
-       be compressed.  Otherwise, <literal>'p'</literal> = pglz compression or
-       <literal>'l'</literal> = <productname>LZ4</productname> compression.
+       The current compression method of the column.  Typically this is
+       <literal>'\0'</literal> to specify use of the current default setting
+       (see <xref linkend="guc-default-toast-compression"/>).  Otherwise,
+       <literal>'p'</literal> selects pglz compression, while
+       <literal>'l'</literal> selects <productname>LZ4</productname>
+       compression.  However, this field is ignored
+       whenever <structfield>attstorage</structfield> does not allow
+       compression.
       </para></entry>
      </row>

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 7e32b0686c..95a302ffee 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -8239,10 +8239,11 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
        <para>
         This variable sets the default
         <link linkend="storage-toast">TOAST</link>
-        compression method for columns of newly-created tables. The
-        <command>CREATE TABLE</command> statement can override this default
-        by specifying the <literal>COMPRESSION</literal> column option.
-
+        compression method for values of compressible columns.
+        (This can be overridden for individual columns by setting
+        the <literal>COMPRESSION</literal> column option in
+        <command>CREATE TABLE</command> or
+        <command>ALTER TABLE</command>.)
         The supported compression methods are <literal>pglz</literal> and,
         if <productname>PostgreSQL</productname> was compiled with
         <literal>--with-lz4</literal>, <literal>lz4</literal>.
diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/brin/brin_tuple.c
index ee05372f79..09e563b1f0 100644
--- a/src/backend/access/brin/brin_tuple.c
+++ b/src/backend/access/brin/brin_tuple.c
@@ -232,11 +232,10 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
                  * same compression method. Otherwise we have to use the
                  * default method.
                  */
-                if (att->atttypid == atttype->type_id &&
-                    CompressionMethodIsValid(att->attcompression))
+                if (att->atttypid == atttype->type_id)
                     compression = att->attcompression;
                 else
-                    compression = GetDefaultToastCompression();
+                    compression = InvalidCompressionMethod;

                 cvalue = toast_compress_datum(value, compression);

diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index 5212560411..8df882da7a 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -104,18 +104,9 @@ index_form_tuple(TupleDesc tupleDescriptor,
              att->attstorage == TYPSTORAGE_MAIN))
         {
             Datum        cvalue;
-            char        compression = att->attcompression;

-            /*
-             * If the compression method is not valid, use the default. We
-             * don't expect this to happen for regular index columns, which
-             * inherit the setting from the corresponding table column, but we
-             * do expect it to happen whenever an expression is indexed.
-             */
-            if (!CompressionMethodIsValid(compression))
-                compression = GetDefaultToastCompression();
-
-            cvalue = toast_compress_datum(untoasted_values[i], compression);
+            cvalue = toast_compress_datum(untoasted_values[i],
+                                          att->attcompression);

             if (DatumGetPointer(cvalue) != NULL)
             {
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 8d2a9964c3..4d60a56a59 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -53,10 +53,12 @@ toast_compress_datum(Datum value, char cmethod)
     Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));
     Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));

-    Assert(CompressionMethodIsValid(cmethod));
-
     valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));

+    /* If the compression method is not valid, use the default */
+    if (!CompressionMethodIsValid(cmethod))
+        cmethod = GetDefaultToastCompression();
+
     /*
      * Call appropriate compression routine for the compression method.
      */
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index affbc509bd..4c63bd4dc6 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -642,10 +642,7 @@ TupleDescInitEntry(TupleDesc desc,
     att->attbyval = typeForm->typbyval;
     att->attalign = typeForm->typalign;
     att->attstorage = typeForm->typstorage;
-    if (IsStorageCompressible(typeForm->typstorage))
-        att->attcompression = GetDefaultToastCompression();
-    else
-        att->attcompression = InvalidCompressionMethod;
+    att->attcompression = InvalidCompressionMethod;
     att->attcollation = typeForm->typcollation;

     ReleaseSysCache(tuple);
@@ -711,7 +708,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
             att->attbyval = false;
             att->attalign = TYPALIGN_INT;
             att->attstorage = TYPSTORAGE_EXTENDED;
-            att->attcompression = GetDefaultToastCompression();
+            att->attcompression = InvalidCompressionMethod;
             att->attcollation = DEFAULT_COLLATION_OID;
             break;

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 8e6e8d5169..d1f4c21f94 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2483,10 +2483,10 @@ reform_and_rewrite_tuple(HeapTuple tuple,
              * perform the compression here; we just need to decompress.  That
              * will trigger recompression later on.
              */
-
             struct varlena *new_value;
             ToastCompressionId cmid;
             char        cmethod;
+            char        targetmethod;

             new_value = (struct varlena *) DatumGetPointer(values[i]);
             cmid = toast_get_compression_id(new_value);
@@ -2495,7 +2495,7 @@ reform_and_rewrite_tuple(HeapTuple tuple,
             if (cmid == TOAST_INVALID_COMPRESSION_ID)
                 continue;

-            /* convert compression id to compression method */
+            /* convert existing compression id to compression method */
             switch (cmid)
             {
                 case TOAST_PGLZ_COMPRESSION_ID:
@@ -2506,10 +2506,16 @@ reform_and_rewrite_tuple(HeapTuple tuple,
                     break;
                 default:
                     elog(ERROR, "invalid compression method id %d", cmid);
+                    cmethod = '\0'; /* keep compiler quiet */
             }

+            /* figure out what the target method is */
+            targetmethod = TupleDescAttr(newTupDesc, i)->attcompression;
+            if (!CompressionMethodIsValid(targetmethod))
+                targetmethod = GetDefaultToastCompression();
+
             /* if compression method doesn't match then detoast the value */
-            if (TupleDescAttr(newTupDesc, i)->attcompression != cmethod)
+            if (targetmethod != cmethod)
             {
                 values[i] = PointerGetDatum(detoast_attr(new_value));
                 values_free[i] = true;
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 62abd008cc..94ab5ca095 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -701,6 +701,7 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
         attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
         attrtypes[attnum]->attalign = Ap->am_typ.typalign;
         attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
+        attrtypes[attnum]->attcompression = InvalidCompressionMethod;
         attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
         /* if an array type, assume 1-dimensional attribute */
         if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
@@ -715,6 +716,7 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
         attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
         attrtypes[attnum]->attalign = TypInfo[typeoid].align;
         attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
+        attrtypes[attnum]->attcompression = InvalidCompressionMethod;
         attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
         /* if an array type, assume 1-dimensional attribute */
         if (TypInfo[typeoid].elem != InvalidOid &&
@@ -724,11 +726,6 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
             attrtypes[attnum]->attndims = 0;
     }

-    if (IsStorageCompressible(attrtypes[attnum]->attstorage))
-        attrtypes[attnum]->attcompression = GetDefaultToastCompression();
-    else
-        attrtypes[attnum]->attcompression = InvalidCompressionMethod;
-
     /*
      * If a system catalog column is collation-aware, force it to use C
      * collation, so that its behavior is independent of the database's
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index 112b3affdf..f893ae4f45 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -899,9 +899,7 @@ sub morph_row_for_pgattr
     $row->{attbyval}   = $type->{typbyval};
     $row->{attalign}   = $type->{typalign};
     $row->{attstorage} = $type->{typstorage};
-
-    $row->{attcompression} =
-      $type->{typstorage} ne 'p' && $type->{typstorage} ne 'e' ? 'p' : '\0';
+    $row->{attcompression} = '\0';

     # set attndims if it's an array type
     $row->{attndims} = $type->{typcategory} eq 'A' ? '1' : '0';
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 3dfe2e8a56..afa830d924 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1719,8 +1719,6 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
         /* Unset this so no one tries to look up the generation expression */
         attStruct->attgenerated = '\0';

-        attStruct->attcompression = InvalidCompressionMethod;
-
         /*
          * Change the column name to something that isn't likely to conflict
          */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 69b1839fd7..e87d9cda93 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -601,7 +601,7 @@ static void refuseDupeIndexAttach(Relation parentIdx, Relation partIdx,
                                   Relation partitionTbl);
 static List *GetParentedForeignKeyRefs(Relation partition);
 static void ATDetachCheckNoForeignKeyRefs(Relation partition);
-static char GetAttributeCompression(Form_pg_attribute att, char *compression);
+static char GetAttributeCompression(Oid atttypid, char *compression);


 /* ----------------------------------------------------------------
@@ -897,8 +897,9 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
         if (colDef->generated)
             attr->attgenerated = colDef->generated;

-        attr->attcompression = GetAttributeCompression(attr,
-                                                       colDef->compression);
+        if (colDef->compression)
+            attr->attcompression = GetAttributeCompression(attr->atttypid,
+                                                           colDef->compression);
     }

     /*
@@ -6593,7 +6594,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
     attribute.attbyval = tform->typbyval;
     attribute.attalign = tform->typalign;
     attribute.attstorage = tform->typstorage;
-    attribute.attcompression = GetAttributeCompression(&attribute,
+    attribute.attcompression = GetAttributeCompression(typeOid,
                                                        colDef->compression);
     attribute.attnotnull = colDef->is_not_null;
     attribute.atthasdef = false;
@@ -12285,10 +12286,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
     attTup->attbyval = tform->typbyval;
     attTup->attalign = tform->typalign;
     attTup->attstorage = tform->typstorage;
-    if (!IsStorageCompressible(tform->typstorage))
-        attTup->attcompression = InvalidCompressionMethod;
-    else if (!CompressionMethodIsValid(attTup->attcompression))
-        attTup->attcompression = GetDefaultToastCompression();
+    attTup->attcompression = InvalidCompressionMethod;

     ReleaseSysCache(typeTuple);

@@ -15586,7 +15584,6 @@ ATExecSetCompression(AlteredTableInfo *tab,
     Form_pg_attribute atttableform;
     AttrNumber    attnum;
     char       *compression;
-    char        typstorage;
     char        cmethod;
     ObjectAddress address;

@@ -15611,17 +15608,11 @@ ATExecSetCompression(AlteredTableInfo *tab,
                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                  errmsg("cannot alter system column \"%s\"", column)));

-    typstorage = get_typstorage(atttableform->atttypid);
-
-    /* prevent from setting compression methods for uncompressible type */
-    if (!IsStorageCompressible(typstorage))
-        ereport(ERROR,
-                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                 errmsg("column data type %s does not support compression",
-                        format_type_be(atttableform->atttypid))));
-
-    /* get the attribute compression method. */
-    cmethod = GetAttributeCompression(atttableform, compression);
+    /*
+     * Check that column type is compressible, then get the attribute
+     * compression method code
+     */
+    cmethod = GetAttributeCompression(atttableform->atttypid, compression);

     /* update pg_attribute entry */
     atttableform->attcompression = cmethod;
@@ -18585,29 +18576,26 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
  * resolve column compression specification to compression method.
  */
 static char
-GetAttributeCompression(Form_pg_attribute att, char *compression)
+GetAttributeCompression(Oid atttypid, char *compression)
 {
-    char        typstorage = get_typstorage(att->atttypid);
+    char        typstorage;
     char        cmethod;

+    if (compression == NULL)
+        return InvalidCompressionMethod;
+
     /*
-     * No compression for plain/external storage, refer comments atop
-     * attcompression parameter in pg_attribute.h
+     * To specify a nondefault method, the column data type must be
+     * compressible.  Note this says nothing about whether the column's
+     * attstorage setting permits compression; we intentionally allow
+     * attstorage and attcompression to be independent.
      */
+    typstorage = get_typstorage(atttypid);
     if (!IsStorageCompressible(typstorage))
-    {
-        if (compression == NULL)
-            return InvalidCompressionMethod;
-
         ereport(ERROR,
                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                  errmsg("column data type %s does not support compression",
-                        format_type_be(att->atttypid))));
-    }
-
-    /* fallback to default compression if it's not specified */
-    if (compression == NULL)
-        return GetDefaultToastCompression();
+                        format_type_be(atttypid))));

     cmethod = CompressionNameToMethod(compression);
     if (!CompressionMethodIsValid(cmethod))
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index ee731044b6..87bc688704 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -4651,13 +4651,13 @@ static struct config_enum ConfigureNamesEnum[] =

     {
         {"default_toast_compression", PGC_USERSET, CLIENT_CONN_STATEMENT,
-            gettext_noop("Sets the default compression for new columns."),
-            NULL,
-            GUC_IS_NAME
+            gettext_noop("Sets the default compression method for compressible values."),
+            NULL
         },
         &default_toast_compression,
         TOAST_PGLZ_COMPRESSION,
-        default_toast_compression_options, NULL, NULL
+        default_toast_compression_options,
+        NULL, NULL, NULL
     },

     {
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 339c393718..b063e00cd4 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -16421,7 +16421,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
                                   tbinfo->attfdwoptions[j]);

             /*
-             * Dump per-column compression, if different from default.
+             * Dump per-column compression, if it's been set.
              */
             if (!dopt->no_toast_compression)
             {
@@ -16440,9 +16440,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
                         break;
                 }

-                if (cmname != NULL &&
-                    (fout->default_toast_compression == NULL ||
-                     strcmp(cmname, fout->default_toast_compression) != 0))
+                if (cmname != NULL)
                     appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET COMPRESSION %s;\n",
                                       foreign, qualrelname,
                                       fmtId(tbinfo->attnames[j]),
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 3e39fdb545..e461bcefb9 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -2055,7 +2055,7 @@ describeOneTableDetails(const char *schemaname,
         appendPQExpBufferStr(&buf, ",\n  a.attstorage");
         attstorage_col = cols++;

-        /* compression info */
+        /* compression info, if relevant to relkind */
         if (pset.sversion >= 140000 &&
             !pset.hide_compression &&
             (tableinfo.relkind == RELKIND_RELATION ||
diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h
index 1e26016214..603392fe81 100644
--- a/src/include/catalog/pg_attribute.h
+++ b/src/include/catalog/pg_attribute.h
@@ -126,8 +126,12 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,
     char        attstorage;

     /*
-     * Compression method.  Must be InvalidCompressionMethod if and only if
-     * typstorage is 'plain' or 'external'.
+     * attcompression sets the current compression method of the attribute.
+     * Typically this is InvalidCompressionMethod ('\0') to specify use of the
+     * current default setting (see default_toast_compression).  Otherwise,
+     * 'p' selects pglz compression, while 'l' selects LZ4 compression.
+     * However, this field is ignored whenever attstorage does not allow
+     * compression.
      */
     char        attcompression BKI_DEFAULT('\0');

diff --git a/src/test/regress/expected/compression.out b/src/test/regress/expected/compression.out
index 61e97cb33c..79e929673a 100644
--- a/src/test/regress/expected/compression.out
+++ b/src/test/regress/expected/compression.out
@@ -53,7 +53,7 @@ SELECT * INTO cmmove1 FROM cmdata;
                                         Table "public.cmmove1"
  Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | text |           |          |         | extended | pglz        |              |
+ f1     | text |           |          |         | extended |             |              |

 SELECT pg_column_compression(f1) FROM cmmove1;
  pg_column_compression
@@ -146,7 +146,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
                                               Table "public.cmdata2"
  Column |       Type        | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | character varying |           |          |         | extended | pglz        |              |
+ f1     | character varying |           |          |         | extended |             |              |

 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
 \d+ cmdata2
@@ -162,14 +162,14 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
                                               Table "public.cmdata2"
  Column |       Type        | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | character varying |           |          |         | extended | pglz        |              |
+ f1     | character varying |           |          |         | extended |             |              |

 ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain;
 \d+ cmdata2
                                               Table "public.cmdata2"
  Column |       Type        | Collation | Nullable | Default | Storage | Compression | Stats target | Description
 --------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
- f1     | character varying |           |          |         | plain   | pglz        |              |
+ f1     | character varying |           |          |         | plain   |             |              |

 INSERT INTO cmdata2 VALUES (repeat('123456789', 800));
 SELECT pg_column_compression(f1) FROM cmdata2;
@@ -184,7 +184,7 @@ CREATE MATERIALIZED VIEW mv(x) AS SELECT * FROM cmdata1;
                                     Materialized view "public.mv"
  Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
- x      | text |           |          |         | extended | pglz        |              |
+ x      | text |           |          |         | extended |             |              |
 View definition:
  SELECT cmdata1.f1 AS x
    FROM cmdata1;
@@ -245,7 +245,7 @@ CREATE TABLE cmdata2 (f1 text);
                                         Table "public.cmdata2"
  Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | text |           |          |         | extended | lz4         |              |
+ f1     | text |           |          |         | extended |             |              |

 SET default_toast_compression = 'pglz';
 -- test alter compression method
diff --git a/src/test/regress/expected/compression_1.out b/src/test/regress/expected/compression_1.out
index d03d6255ae..2a9fc81b51 100644
--- a/src/test/regress/expected/compression_1.out
+++ b/src/test/regress/expected/compression_1.out
@@ -50,7 +50,7 @@ SELECT * INTO cmmove1 FROM cmdata;
                                         Table "public.cmmove1"
  Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | text |           |          |         | extended | pglz        |              |
+ f1     | text |           |          |         | extended |             |              |

 SELECT pg_column_compression(f1) FROM cmmove1;
  pg_column_compression
@@ -144,7 +144,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
                                               Table "public.cmdata2"
  Column |       Type        | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | character varying |           |          |         | extended | pglz        |              |
+ f1     | character varying |           |          |         | extended |             |              |

 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
 \d+ cmdata2
@@ -160,14 +160,14 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
                                               Table "public.cmdata2"
  Column |       Type        | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | character varying |           |          |         | extended | pglz        |              |
+ f1     | character varying |           |          |         | extended |             |              |

 ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain;
 \d+ cmdata2
                                               Table "public.cmdata2"
  Column |       Type        | Collation | Nullable | Default | Storage | Compression | Stats target | Description
 --------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
- f1     | character varying |           |          |         | plain   | pglz        |              |
+ f1     | character varying |           |          |         | plain   |             |              |

 INSERT INTO cmdata2 VALUES (repeat('123456789', 800));
 SELECT pg_column_compression(f1) FROM cmdata2;
@@ -240,7 +240,7 @@ CREATE TABLE cmdata2 (f1 text);
                                         Table "public.cmdata2"
  Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
- f1     | text |           |          |         | extended | pglz        |              |
+ f1     | text |           |          |         | extended |             |              |

 SET default_toast_compression = 'pglz';
 -- test alter compression method
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index fc054af5ba..3c1cd858a8 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -208,8 +208,6 @@ typedef struct Archive

     /* other important stuff */
     char       *searchpath;        /* search_path to set during restore */
-    char       *default_toast_compression;    /* default TOAST compression to
-                                             * set during restore */
     char       *use_role;        /* Issue SET ROLE to this */

     /* error handling */
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 86de26a4bf..6b046e7734 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -86,7 +86,6 @@ static void _selectTableAccessMethod(ArchiveHandle *AH, const char *tableam);
 static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te);
 static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te);
 static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te);
-static void processToastCompressionEntry(ArchiveHandle *AH, TocEntry *te);
 static int    _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH);
 static RestorePass _tocEntryRestorePass(TocEntry *te);
 static bool _tocEntryIsACL(TocEntry *te);
@@ -2638,8 +2637,6 @@ ReadToc(ArchiveHandle *AH)
             processStdStringsEntry(AH, te);
         else if (strcmp(te->desc, "SEARCHPATH") == 0)
             processSearchPathEntry(AH, te);
-        else if (strcmp(te->desc, "TOASTCOMPRESSION") == 0)
-            processToastCompressionEntry(AH, te);
     }
 }

@@ -2697,29 +2694,6 @@ processSearchPathEntry(ArchiveHandle *AH, TocEntry *te)
     AH->public.searchpath = pg_strdup(te->defn);
 }

-static void
-processToastCompressionEntry(ArchiveHandle *AH, TocEntry *te)
-{
-    /* te->defn should have the form SET default_toast_compression = 'x'; */
-    char       *defn = pg_strdup(te->defn);
-    char       *ptr1;
-    char       *ptr2 = NULL;
-
-    ptr1 = strchr(defn, '\'');
-    if (ptr1)
-        ptr2 = strchr(++ptr1, '\'');
-    if (ptr2)
-    {
-        *ptr2 = '\0';
-        AH->public.default_toast_compression = pg_strdup(ptr1);
-    }
-    else
-        fatal("invalid TOASTCOMPRESSION item: %s",
-              te->defn);
-
-    free(defn);
-}
-
 static void
 StrictNamesCheck(RestoreOptions *ropt)
 {
@@ -2779,8 +2753,7 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
     /* These items are treated specially */
     if (strcmp(te->desc, "ENCODING") == 0 ||
         strcmp(te->desc, "STDSTRINGS") == 0 ||
-        strcmp(te->desc, "SEARCHPATH") == 0 ||
-        strcmp(te->desc, "TOASTCOMPRESSION") == 0)
+        strcmp(te->desc, "SEARCHPATH") == 0)
         return REQ_SPECIAL;

     /*
@@ -3103,11 +3076,6 @@ _doSetFixedOutputState(ArchiveHandle *AH)
     if (AH->public.searchpath)
         ahprintf(AH, "%s", AH->public.searchpath);

-    /* Select the dump-time default_toast_compression */
-    if (AH->public.default_toast_compression)
-        ahprintf(AH, "SET default_toast_compression = '%s';\n",
-                 AH->public.default_toast_compression);
-
     /* Make sure function checking is disabled */
     ahprintf(AH, "SET check_function_bodies = false;\n");

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index b063e00cd4..e9a86ed512 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -276,7 +276,6 @@ static void dumpDatabaseConfig(Archive *AH, PQExpBuffer outbuf,
 static void dumpEncoding(Archive *AH);
 static void dumpStdStrings(Archive *AH);
 static void dumpSearchPath(Archive *AH);
-static void dumpToastCompression(Archive *AH);
 static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout,
                                                      PQExpBuffer upgrade_buffer,
                                                      Oid pg_type_oid,
@@ -925,13 +924,11 @@ main(int argc, char **argv)
      */

     /*
-     * First the special entries for ENCODING, STDSTRINGS, SEARCHPATH and
-     * TOASTCOMPRESSION.
+     * First the special entries for ENCODING, STDSTRINGS, and SEARCHPATH.
      */
     dumpEncoding(fout);
     dumpStdStrings(fout);
     dumpSearchPath(fout);
-    dumpToastCompression(fout);

     /* The database items are always next, unless we don't want them at all */
     if (dopt.outputCreateDB)
@@ -3398,58 +3395,6 @@ dumpSearchPath(Archive *AH)
     destroyPQExpBuffer(path);
 }

-/*
- * dumpToastCompression: save the dump-time default TOAST compression in the
- * archive
- */
-static void
-dumpToastCompression(Archive *AH)
-{
-    char       *toast_compression;
-    PQExpBuffer qry;
-
-    if (AH->dopt->no_toast_compression)
-    {
-        /* we don't intend to dump the info, so no need to fetch it either */
-        return;
-    }
-
-    if (AH->remoteVersion < 140000)
-    {
-        /* pre-v14, the only method was pglz */
-        toast_compression = pg_strdup("pglz");
-    }
-    else
-    {
-        PGresult   *res;
-
-        res = ExecuteSqlQueryForSingleRow(AH, "SHOW default_toast_compression");
-        toast_compression = pg_strdup(PQgetvalue(res, 0, 0));
-        PQclear(res);
-    }
-
-    qry = createPQExpBuffer();
-    appendPQExpBufferStr(qry, "SET default_toast_compression = ");
-    appendStringLiteralAH(qry, toast_compression, AH);
-    appendPQExpBufferStr(qry, ";\n");
-
-    pg_log_info("saving default_toast_compression = %s", toast_compression);
-
-    ArchiveEntry(AH, nilCatalogId, createDumpId(),
-                 ARCHIVE_OPTS(.tag = "TOASTCOMPRESSION",
-                              .description = "TOASTCOMPRESSION",
-                              .section = SECTION_PRE_DATA,
-                              .createStmt = qry->data));
-
-    /*
-     * Also save it in AH->default_toast_compression, in case we're doing
-     * plain text dump.
-     */
-    AH->default_toast_compression = toast_compression;
-
-    destroyPQExpBuffer(qry);
-}
-

 /*
  * getBlobs:

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Konstantin Knizhnik
Дата:
Сообщение: Re: Add ZSON extension to /contrib/
Следующее
От: Robert Haas
Дата:
Сообщение: Re: Move pg_attribute.attcompression to earlier in struct for reduced size?