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: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Some RELKIND macro refactoring
Date: Tue, 23 Nov 2021 12:19:13 -0300
Message-ID: <202111231519.kf27gjzikeko@alvherre.pgsql> (raw)
In-Reply-To: <d0ce69e6-d8c9-af2b-a986-d2938a312862@enterprisedb.com>

On 2021-Nov-22, Peter Eisentraut wrote:

> Maybe
> 
>     else
>     {
>         Assert(RELKIND_HAS_STORAGE(rel->rd_rel->relkind);
>         RelationCreateStorage(rel->rd_node, relpersistence);
>     }
> 
> create_storage is set earlier based on RELKIND_HAS_STORAGE(), so this would
> be consistent.

Hmm, right ... but I think we can make this a little simpler.  How about
the attached?

-- 
Álvaro Herrera              Valdivia, Chile  —  https://www.EnterpriseDB.com/

Attachments:

create-storage.patch (text/x-diff, 2.1K) download diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index a13861e925..4d62a1960f 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -308,7 +308,6 @@ heap_create(const char *relname, TransactionId *relfrozenxid, MultiXactId *relminmxid) { - bool create_storage; Relation rel; /* The caller must have provided an OID for the relation. */ @@ -343,19 +342,6 @@ heap_create(const char *relname, if (!RELKIND_HAS_TABLESPACE(relkind)) reltablespace = InvalidOid; - /* - * Decide whether to create storage. If caller passed a valid relfilenode, - * storage is already created, so don't do it here. Also don't create it - * for relkinds without physical storage. - */ - if (!RELKIND_HAS_STORAGE(relkind) || OidIsValid(relfilenode)) - create_storage = false; - else - { - create_storage = true; - relfilenode = relid; - } - /* * Never allow a pg_class entry to explicitly specify the database's * default tablespace in reltablespace; force it to zero instead. This @@ -376,7 +362,7 @@ heap_create(const char *relname, tupDesc, relid, accessmtd, - relfilenode, + relfilenode ? relfilenode : relid, reltablespace, shared_relation, mapped_relation, @@ -384,20 +370,23 @@ heap_create(const char *relname, relkind); /* - * Have the storage manager create the relation's disk file, if needed. + * If caller gave us a valid relfilenode, storage is already created. + * Otherwise, create one now if the relkind requires it. * * For tables, the AM callback creates both the main and the init fork. * For others, only the main fork is created; the other forks will be * created on demand. */ - if (create_storage) + if (!OidIsValid(relfilenode)) { - if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind)) + if (RELKIND_HAS_TABLE_AM(relkind)) table_relation_set_new_filenode(rel, &rel->rd_node, relpersistence, relfrozenxid, relminmxid); - else + else if (RELKIND_HAS_STORAGE(relkind)) RelationCreateStorage(rel->rd_node, relpersistence); + else + Assert(false); } /*

view thread (16+ messages)  latest in thread

Message-ID: <202111231519.kf27gjzikeko@alvherre.pgsql>
Permalink:  ../202111231519.kf27gjzikeko@alvherre.pgsql/
Also on:    postgresql.org/message-id/202111231519.kf27gjzikeko@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, michael@paquier.xyz
  Subject: Re: Some RELKIND macro refactoring
  In-Reply-To: <202111231519.kf27gjzikeko@alvherre.pgsql>
  References: <d0ce69e6-d8c9-af2b-a986-d2938a312862@enterprisedb.com> <202111231519.kf27gjzikeko@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