Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbxs0-0007zN-II for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Apr 2021 04:01:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lbxrz-0005V9-Do for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Apr 2021 04:01:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbxrz-0005V2-1S for pgsql-hackers@lists.postgresql.org; Thu, 29 Apr 2021 04:01:43 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lbxrr-0005Pg-LO for pgsql-hackers@lists.postgresql.org; Thu, 29 Apr 2021 04:01:41 +0000 Received: by mail-oi1-x234.google.com with SMTP id l17so33937334oil.11 for ; Wed, 28 Apr 2021 21:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=bFOhiNBFpk00UumIGBcK3tTdus4J1sz3zWPFJtuj6Sw=; b=G90QAv2ax/V5mAoHE/Lqg5J83bJfRNGJaG7Z1/ljVb6v0gj4PBtTcwSmpc0jVOosiI t7jxQPAkOmKyFEKyqwm675PTEZb9qEFeiQckYHgw8R4u9yG5wxO6hscWTfPOXlw+0zXc nlItCPJpR6FnbHTvgIJYop52H6G82VtCXfJaA6hBcN7/7P6iEs43WXGWB8uvPW5O7857 TLIPPEIDN5yBhU6TWOxM6Tkt/XLa4j9RnUWEvsef1iwyd/ncNP28SxdGA2P4SvsVUQq/ 2JmnV3J0EaE7/UqKsEN3V52pWUZFt32r+7gmDzsiGIhiB+202/jYlJtAzi171DsIk9jx SQFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=bFOhiNBFpk00UumIGBcK3tTdus4J1sz3zWPFJtuj6Sw=; b=sJgGkPOStcUkyQEzsFEqa837mt2OEjiFheyqhXIvHdaZb/jOLus0gl22BRXLivOCrH PR6mMUh9cI61E+d6dSqaTwXH88GpqZgMJMIYVlk7Prics7VT91EdNpIDTyj/xmZS0jUJ lT+tQ/fpjCBMldD/MjTOqOwPphs07uQNH+14JVnivxtFQehW26J/9fvsknoi/AGqjI40 8tGj+HHQgn4wMsyTIiSdmDUYV9YHVKSzSudp3X1lu6Ef2h01NVozj5na2RBVabRuu8jp 248Nupu+VfqVAysAgpGb2RkxaAgmEie9gvjOsSRNLtyfjepA2hMPT9QV+1FDjm6hS6gl 8zKQ== X-Gm-Message-State: AOAM532e6O7McoiO5yaNZbPsGfdZ4nuym/LI9zCILBI0FrhBWgTNxzZy AX/9onxKebmUJU2DJjBMHtkhyg== X-Google-Smtp-Source: ABdhPJxJpTqxycXnLCpO8st+11Ez/L2HUW4tH3dtPIRbEOkzqHT8ajhQajCLcSQTzpXQcC/pwGSedQ== X-Received: by 2002:a54:4188:: with SMTP id 8mr22977128oiy.96.1619668894899; Wed, 28 Apr 2021 21:01:34 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id m133sm422550oia.22.2021.04.28.21.01.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Apr 2021 21:01:34 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 2F60F800A36; Wed, 28 Apr 2021 23:01:33 -0500 (CDT) Date: Wed, 28 Apr 2021 23:01:33 -0500 From: Justin Pryzby To: Michael Paquier Cc: Postgres hackers , Jacob Champion , Robert Haas Subject: Re: Small issues with CREATE TABLE COMPRESSION Message-ID: <20210429040132.GF27406@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 27, 2021 at 03:22:25PM +0900, Michael Paquier wrote: > Hi all, > > I have been looking at and testing the patch set for CREATE TABLE > COMPRESSION, and spotted a couple of things in parallel of some work > done by Jacob (added in CC). > > The behavior around CREATE TABLE AS and matviews is a bit confusing, > and not documented. First, at the grammar level, it is not possible > to specify which compression option is used per column when creating > the relation. So, all the relation columns would just set a column's > compression to be default_toast_compression for all the toastable > columns of the relation. That's not enforceable at column level when > the relation is created, except with a follow-up ALTER TABLE. That's > similar to STORAGE when it comes to matviews, but these are at least > documented. > > And so, ALTER MATERIALIZED VIEW supports SET COMPRESSION but this is > not mentioned in its docs: > https://www.postgresql.org/docs/devel/sql-altermaterializedview.html > > psql could have tab completion support for that. Actually ALTER matview ALTER col has no tab completion at all, right ? > Now, we don't really document any of that, and the per-column > compression value would be set to default_toast_compression while the > stored values may use a mix of the compression methods, depending on > where the toasted values come from. If this behavior is intended, this > makes me wonder in what the possibility to set the compression for a > materialized view column is useful for except for a logical > dump/restore? As of HEAD we'd just insert the toasted value from the > origin as-is so the compression of the column has no effect at all. That may be true if the mat view is trivial, but not true if it has expressions. The mat view column may be built on multiple table columns, or be of a different type than the columns it's built on top of, so the relationship may not be so direct. > Another thing here is the inconsistency that this brings with pg_dump. > For example, as the dumped values are decompressed, we could have > values compressed with pglz at the origin, with a column using lz4 > within its definition that would make everything compressed with lz4 > once the values are restored. This choice may be fine, but I think > that it would be good to document all that. That would be less > surprising to the user. Can you suggest what or where we'd say it? I think this is just the behavior that pg_dump shouldn't lose the user's compression setting. The setting itself is for "future" data, and the only way to guarantee what compression types are in use are by vacuum full/cluster or pg_dump restore. > Similarly, we may want to document that COMPRESSION does not trigger a > table rewrite, but that it is effective only for the new toast values > inserted if a tuple is rebuilt and rewritten? Good point. I started with this. diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 39927be41e..8cceea41d0 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -391,7 +391,21 @@ WITH ( MODULUS numeric_literal, REM - This sets the compression method for a column. The supported compression + This sets the compression method to be used for data inserted into a column. + + This does not cause the table to be rewritten, so existing data may still + be compressed with other compression methods. If the table is rewritten with + VACUUM FULL or CLUSTER, or restored + with pg_restore, then all tuples are rewritten + with the configured compression methods. + + Also, note that when data is inserted from another relation (for example, + by INSERT ... SELECT), tuples from the source data are + not necessarily detoasted, and any previously compressed data is retained + with its existing compression method, rather than recompressing with the + compression methods of the target columns. + + The supported compression methods are pglz and lz4. lz4 is available only if --with-lz4 was used when building PostgreSQL.