Re: Fallback table AM for relkinds without storage

From: Andres Freund <andres(at)anarazel(dot)de>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fallback table AM for relkinds without storage
Date: 2021-02-23 01:19:37
Message-ID: 20210223011937.e53hgr36uimw2vb5@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2021-02-15 16:21:38 +0900, Michael Paquier wrote:
> I have been playing with this idea, and finished with the attached,
> which is not the sexiest patch around. The table AM used as fallback
> for tables without storage is called no_storage (this could be called
> virtual_am?).

> One thing to note is that this simplifies a bit slot_callbacks as
> views, foreign tables and partitioned tables can grab their slot type
> directly from this new table AM.

This doesn't seem like an advantage to me. Isn't this just pushing logic
away from a fairly obvious point into an AM that one would expect to
never actually get called?

> +static const TupleTableSlotOps *
> +no_storage_slot_callbacks(Relation relation)
> +{
> + if (relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
> + {
> + /*
> + * Historically FDWs expect to store heap tuples in slots. Continue
> + * handing them one, to make it less painful to adapt FDWs to new
> + * versions. The cost of a heap slot over a virtual slot is pretty
> + * small.
> + */
> + return &TTSOpsHeapTuple;
> + }
> +
> + /*
> + * These need to be supported, as some parts of the code (like COPY) need
> + * to create slots for such relations too. It seems better to centralize
> + * the knowledge that a heap slot is the right thing in that case here.
> + */
> + if (relation->rd_rel->relkind != RELKIND_VIEW &&
> + relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
> + elog(ERROR, "no_storage_slot_callbacks() failed on relation \"%s\"",
> + RelationGetRelationName(relation));
> + return &TTSOpsVirtual;
> +}

If we want to go down this path what's the justification for have
relkind awareness inside the AM? If we want it, we should give FDWs
their own tableam. And we should do the same for sequences (that'd imo
be a much nicer improvement than this change in itself).

If we were to go for separate AMs I think we could consider implementing
most of their functionality in one file, to avoid needing to duplicate
the functions that error out.

And I'd vote for not naming it no_storage - to me that sounds like a
name you'd give "blackhole_am". This concept kinda reminds me of
pseudotypes - so maybe we should just name it pseudo_am.c or such?

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andy Fan 2021-02-23 01:21:52 Re: Hybrid Hash/Nested Loop joins and caching results from subplans
Previous Message Andres Freund 2021-02-23 01:11:01 Re: Table AM and DDLs