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 1lekWe-0003N1-Bc for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 20:23:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lekWd-0002jU-21 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 20:23:11 +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 1lekWc-0002jM-QY for pgsql-hackers@lists.postgresql.org; Thu, 06 May 2021 20:23:10 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lekWa-00071T-5L for pgsql-hackers@postgresql.org; Thu, 06 May 2021 20:23:09 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 65-20020a9d03470000b02902808b4aec6dso6032401otv.6 for ; Thu, 06 May 2021 13:23:08 -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=UbYzcFM7A2MhbwdsbSqzDztEADkbU8Rk5JDWoj63hs8=; b=b5VMdHYHeaNNRqpFAAwUWscaXi5vgKWx8fkBmNMcJrALw0EMNjzyEYyU4otPSsBh/R 4hOi45bi0yxQIATwvMG5XO8gHd8B8f8DDc4m4VfkeJGTWKs6sByV+yKF63dZuk0GT29W oxgDl4/47AobCwLxCYReauNaNVzWS8BGOwDXiD4CyqhweFv+JQ4InfDcwUE0Vb2YtvY4 Rv7xpOCb+TwZ/YCQdGJrIr5Hl13DnfUmuuufJfBQFbd57vJyDh4p7idBRBQOFBxVRJgv GRjTTOx0d0p41+Zp51VgkeyArxlDp0xxYsHVwsJFU5x+vPlwrbZZqy7y9DsGoKAwKMgV kbyg== 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=UbYzcFM7A2MhbwdsbSqzDztEADkbU8Rk5JDWoj63hs8=; b=alfbk3t1Xp0elo6iPWxmjfD+n/bUUBfyCcWDdgHHSkd4ByPnpYQGJhD1CE3hL9172s 4jzJnDaW+ueIfFKwqTKxO44BVlSC8g0JFSjVgIyghixlGMaWqzvk3VYU06RB9CxK4o4d ZZaHPxW5RxFxjRZwhUWATzZ/9s+zyORPo4VPZ5oCWTWPo72OC7lHoJCXml7P8R9TrNUA LBKT2tCVjp1tB/gHb0TGvOYaoc1vmtvbaPouJPHGmazVpeLi8WrPLueYRdKcjwXBqKnK YibmUHUQenOMGIz6svcjUbGHIAscNsslZLzThZyvuUe7jpRuql8oRWHglt780NO5JBnF c0zw== X-Gm-Message-State: AOAM53006VzXsUAV1dRmrY9OmepJgnuihufvBe+N0y0euMIxpgWCpnKe V7a+iwaiktq6IrE0pWrCstx7/w== X-Google-Smtp-Source: ABdhPJxjk8jpAOmMjF/EIzVLvJ4FSv+9Ha0B06prAMRC4A0OZUxpYKOJ6qS2dFyu/0howqhhLFVgMg== X-Received: by 2002:a9d:5e19:: with SMTP id d25mr5175092oti.308.1620332587324; Thu, 06 May 2021 13:23:07 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q1sm773657otm.26.2021.05.06.13.23.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 May 2021 13:23:06 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id C9561800897; Thu, 6 May 2021 15:23:05 -0500 (CDT) Date: Thu, 6 May 2021 15:23:05 -0500 From: Justin Pryzby To: Jeff Davis Cc: Michael Paquier , pgsql-hackers@postgresql.org, Jacob Champion , Heikki Linnakangas , Ashwin Agrawal , Ashutosh Sharma , Andres Freund , Robert Haas , Amit Kapila , Alvaro Herrera , Dilip Kumar Subject: Re: alter table set TABLE ACCESS METHOD Message-ID: <20210506202305.GQ27406@telsasoft.com> References: <20210228222530.GD20769@telsasoft.com> <20210308010707.GA29832@telsasoft.com> <35333ea26e52252174515e14671a9fbc1c20c8fa.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <35333ea26e52252174515e14671a9fbc1c20c8fa.camel@j-davis.com> 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 Thu, May 06, 2021 at 01:10:53PM -0700, Jeff Davis wrote: > On Mon, 2021-03-08 at 16:30 +0900, Michael Paquier wrote: > > This toast issue is a kind of interesting one, and it seems rather > > right to rely on toast_build_flattened_tuple() to decompress things > > if > > both table AMs support toast with the internals of toast knowing what > > kind of compression has been applied to the stored tuple, rather than > > have the table AM try to extra a toast tuple by itself. I wonder > > whether we should have a table AM API to know what kind of > > compression > > is supported for a given table AMs at hand, because there is no need > > to flatten things if both the origin and the target match their > > compression algos, which would be on HEAD to make sure that both the > > origin and table AMs have toast (relation_toast_am). Your patch, > > here, would flatten each tuples as long as the table AMs don't > > match. That can be made cheaper in some cases. > > I am confused by this. The toast-related table AM API functions are: > relation_needs_toast_table(), relation_toast_am(), and > relation_fetch_toast_slice(). I wrote this shortly after looking at one of Dilip's LZ4 patches. At one point in February/March, pg_attribute.attcompression defined the compression used by *all* tuples in the table, rather than the compression used for new tuples, and ALTER SET COMPRESSION would rewrite the table with the new compression (rather than being only a catalog update). > What cases are we trying to solve here? > > 1. target of conversion is tableam1 main table, heap toast table > 2. target of conversion is tableam1 main table, no toast table > 3. target of conversion is tableam1 main table, tableam1 toast table > 4. target of conversion is tableam1 main table, tableam2 toast table I think ALTER TABLE SET ACCESS METHOD should move all data off the old AM, including its toast table. The optimization Michael suggests is when the new AM and old AM use the same toast AM, then the data doesn't need to be de/re/toasted. Thanks for looking. -- Justin