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/
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); } /*