pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Some RELKIND macro refactoring
Date: Mon, 16 Aug 2021 10:22:50 -0400
Message-ID: <202108161422.sodbvh3hb7ra@alvherre.pgsql> (raw)
In-Reply-To: <a574c8f1-9c84-93ad-a9e5-65233d6fc00f@enterprisedb.com>

On 2021-Aug-16, Peter Eisentraut wrote:

> +		if (rel->rd_rel->relkind == RELKIND_INDEX ||
> +			rel->rd_rel->relkind == RELKIND_SEQUENCE)
> +			RelationCreateStorage(rel->rd_node, relpersistence);
> +		else if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
> +			table_relation_set_new_filenode(rel, &rel->rd_node,
> +											relpersistence,
> +											relfrozenxid, relminmxid);
> +		else
> +			Assert(false);

I think you could turn this one (and the one in RelationSetNewRelfilenode) around:

	if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
		table_relation_set_new_filenode(...);
	else if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
		RelationCreateStorage(...);

> +/*
> + * Relation kinds with a table access method (rd_tableam).  Although sequences
> + * use the heap table AM, they are enough of a special case in most uses that
> + * they are not included here.
> + */
> +#define RELKIND_HAS_TABLE_AM(relkind) \
> +	((relkind) == RELKIND_RELATION || \
> +	 (relkind) == RELKIND_TOASTVALUE || \
> +	 (relkind) == RELKIND_MATVIEW)

Partitioned tables are not listed here, but IIRC there's a patch to let
partitioned tables have a table AM so that their partitions inherit it.
I'm wondering if that patch is going to have to change this spot; and if
it does, how will that affect the callers of this macro that this patch
creates.  I think a few places assume that HAS_TABLE_AM means that the
table has storage, but perhaps it would be better to spell that out
explicitly:

@@ -303,9 +303,7 @@ verify_heapam(PG_FUNCTION_ARGS)
 	/*
 	 * Check that a relation's relkind and access method are both supported.
 	 */
-	if (ctx.rel->rd_rel->relkind != RELKIND_RELATION &&
-		ctx.rel->rd_rel->relkind != RELKIND_MATVIEW &&
-		ctx.rel->rd_rel->relkind != RELKIND_TOASTVALUE)
+	if (!(RELKIND_HAS_TABLE_AM(ctx.rel->rd_rel->relkind) && RELKIND_HAS_STOAGE(ctx.rel->rd_rel->relkind)))
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("cannot check relation \"%s\"",

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/





view thread (16+ messages)  latest in thread

Message-ID: <202108161422.sodbvh3hb7ra@alvherre.pgsql>
Permalink:  ../202108161422.sodbvh3hb7ra@alvherre.pgsql/
Also on:    postgresql.org/message-id/202108161422.sodbvh3hb7ra@alvherre.pgsql

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@alvh.no-ip.org, peter.eisentraut@enterprisedb.com
  Subject: Re: Some RELKIND macro refactoring
  In-Reply-To: <202108161422.sodbvh3hb7ra@alvherre.pgsql>
  References: <a574c8f1-9c84-93ad-a9e5-65233d6fc00f@enterprisedb.com> <202108161422.sodbvh3hb7ra@alvherre.pgsql>

* 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