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 1lemLd-0006nM-9t for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 22:19:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lemLb-0006Mj-14 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 May 2021 22:19:55 +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 1lemLa-0006Ma-KX for pgsql-hackers@lists.postgresql.org; Thu, 06 May 2021 22:19:54 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lemLT-0007wZ-D4 for pgsql-hackers@postgresql.org; Thu, 06 May 2021 22:19:53 +0000 Received: by mail-oi1-x236.google.com with SMTP id n184so6906305oia.12 for ; Thu, 06 May 2021 15:19:47 -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=YNBpIJeX13dBPfzjVPIGpeqnJSQqnXCXE0bY6jtqBhE=; b=H9MKzqnEUsGDLOBbA1sIQYycIiyz0uxJeIZl2P3vBEhn5B09V2iU++5YqJhKv5aO4v Zkl7uyf3f/FoTsotyxTufy6ufCMdZSfpwB+NI5DqYFDt56Bv85IGCBsp4keyEeq6ojx0 5s8/njaQH8M+Na72m9SpFCqHmNYRkFUzkEjABkmRh4AFb6VuObSohx76A20xiOJXjs10 MshI3HK/RU71wb9ncjo6SsQ7PXqNT52MufBjeGbk8BE/elt8OE/GRkeayooSe9tlkxmL RzjOSDWz54/L/0MCx0xa1FXzgf8tvzQ12iOmi+wRLomU/81+y4Pp82ebz8FlJd/+INgc RlDg== 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=YNBpIJeX13dBPfzjVPIGpeqnJSQqnXCXE0bY6jtqBhE=; b=BK6NNL0P/dct38FSoX3MV4SXNUH8524MyUiYbCTmTog+5dxg8FUkZGkCStDCtD6ZGJ TBPw+6ceGrLZLoCI/iZlUZsOyRQp7vjT+TCUKDsdjvMP55FJ3BsMU2wgX00TxzS1pR/2 owmHtQI9MzCqMPPLWC7KnZgBI2L7bCjtdFG+ZAQdF7kLj1oddsSsb90igWZrmQ66U5D/ 4R2i80ptyKCjnugbyoejiDyJARKYnRvI7bJzmOb7fh2zdIHvhNiKaBtj40hpR0bPm1KQ re84esfLpO4B6Ld9TyMBkiRJa6HhKcZJqtVtvZMJBEBNycHR+qTxWHpVl7QwuCiG9pFY 0aMw== X-Gm-Message-State: AOAM533OebOueLcdY/hYwrvD23Ec2GFVdJWWZx5z8FmehTfh7pVWOaKn La1K2SXgWMl6wvgxfR+W/75fEg== X-Google-Smtp-Source: ABdhPJwaWGYw0G46CxN1pzEAQKFyXwwBvMzoZU2MKm4k9MFsYahdku/S/NPbV9IARnYTAVwe3vHSUQ== X-Received: by 2002:aca:6701:: with SMTP id z1mr12104262oix.167.1620339586319; Thu, 06 May 2021 15:19:46 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id n17sm661901oie.11.2021.05.06.15.19.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 May 2021 15:19:45 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 43EDC8007F8; Thu, 6 May 2021 17:19:44 -0500 (CDT) Date: Thu, 6 May 2021 17:19:44 -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: <20210506221943.GS27406@telsasoft.com> References: <20210228222530.GD20769@telsasoft.com> <20210308010707.GA29832@telsasoft.com> <35333ea26e52252174515e14671a9fbc1c20c8fa.camel@j-davis.com> <20210506202305.GQ27406@telsasoft.com> <1033d6b4b5b42a014cc3f617265ae6e61cb5781b.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1033d6b4b5b42a014cc3f617265ae6e61cb5781b.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 02:11:31PM -0700, Jeff Davis wrote: > On Thu, 2021-05-06 at 15:23 -0500, Justin Pryzby wrote: > > I think ALTER TABLE SET ACCESS METHOD should move all data off the > > old AM, > > including its toast table. > > Can you explain what you mean, and why? I'm still confused. > > Let's say there are 4 table AMs: A, AT, B, and BT. A's > relation_toast_am() returns AT, and B's relation_toast_am() returns BT. > AT or BT are invalid if A or B have relation_needs_toast_table() return > false. > > Here are the cases that I see: > > If A = B, then AT = BT, and it's all a no-op. > > If A != B and BT is invalid (e.g. converting heap to columnar), then A > should detoast (and perhaps decompress, as in the case of columnar) > whatever it gets as input and do whatever it wants. That's what > columnar does and I don't see why ATRewriteTable needs to handle it. > > If A != B and AT != BT, then B needs to detoast whatever it gets (but > should not decompress, as that would just be wasted effort), and then > re-toast using BT. Again, I don't see a need for ATRewriteTable to do > anything, B can handle it. > > The only case I can really see where ATRewriteTable might be helpful is > if A != B but AT = BT. In that case, in theory, you don't need to do > anything to the toast table, just leave it where it is. But then the > responsibilities get a little confusing to me -- how is B supposed to > know that it doesn't need to toast anything? Is this the problem you > are trying to solve? That's the optimization Michael is suggesting. I was approaching this after having just looked at Dilip's patch (which was originally written using pg_am to support "pluggable" compression "AM"s, but not otherwise related to table AM). Once a table is converted to a new AM, its tuples had better not reference the old AM - it could be dropped. The new table AM (B) shouldn't need to know anything about the old one (A). It should just process incoming tuples. It makes more to me that ATRewriteTable would handle this, rather than every acccess method having the same logic (at best) or different logic (more likely). If ATRewriteTable didn't handle this, data would become inaccessible if an AM failed to de-toast tuples. -- Justin