pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers@postgresql.org, Jacob Champion <pchampion@vmware.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Ashwin Agrawal <aagrawal@pivotal.io>
Cc: Ashutosh Sharma <ashu.coek88@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Dilip Kumar <dilipbalaut@gmail.com>
Subject: Re: alter table set TABLE ACCESS METHOD
Date: Thu, 6 May 2021 17:19:44 -0500
Message-ID: <20210506221943.GS27406@telsasoft.com> (raw)
In-Reply-To: <1033d6b4b5b42a014cc3f617265ae6e61cb5781b.camel@j-davis.com>
References: <20210228222530.GD20769@telsasoft.com>
	<YDxOhIGLPEGYINNP@paquier.xyz>
	<20210308010707.GA29832@telsasoft.com>
	<YEXSj7vO/ypnlIqq@paquier.xyz>
	<35333ea26e52252174515e14671a9fbc1c20c8fa.camel@j-davis.com>
	<20210506202305.GQ27406@telsasoft.com>
	<1033d6b4b5b42a014cc3f617265ae6e61cb5781b.camel@j-davis.com>

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





view thread (41+ messages)  latest in thread

Message-ID: <20210506221943.GS27406@telsasoft.com>
Permalink:  ../20210506221943.GS27406@telsasoft.com/
Also on:    postgresql.org/message-id/20210506221943.GS27406@telsasoft.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: pryzby@telsasoft.com, pgsql@j-davis.com, michael@paquier.xyz, pchampion@vmware.com, hlinnaka@iki.fi, aagrawal@pivotal.io, ashu.coek88@gmail.com, andres@anarazel.de, robertmhaas@gmail.com, amit.kapila16@gmail.com, alvherre@alvh.no-ip.org, dilipbalaut@gmail.com
  Subject: Re: alter table set TABLE ACCESS METHOD
  In-Reply-To: <20210506221943.GS27406@telsasoft.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox