Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpXZt-0007Fs-Az for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Nov 2021 15:19:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpXZs-0006p4-67 for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Nov 2021 15:19:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpXZr-0006ov-Sy for pgsql-hackers@lists.postgresql.org; Tue, 23 Nov 2021 15:19:23 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpXZn-0003hB-DY for pgsql-hackers@postgresql.org; Tue, 23 Nov 2021 15:19:22 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 556063200D53; Tue, 23 Nov 2021 10:19:17 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 23 Nov 2021 10:19:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=jotdJS1WXPRRzQsVuKAxRUxYedpMU23x26Cc66PK8fI=; b=my8F5ZaC SyCU/B+tQqD6MNVT+H01RXSY0h95qB8REUM0Rd1tPFAo9k0BWmJXDNAQD0ruQsN8 iqjmW0IFD1O9/QzLhsmAzpwPVjFWTZBdFz30qhof+P2+Tq1lVankOXlunQO3Blx5 R/ZhgHrRi+xWM4o7yzKPkgZP2Yu+Sjo+nXdsWKfrFSSvBzNPVbRsaFn1I78sByIt qSoZC+64l/yJ6Js0jNDaQglVyCHA8UhenFG55XB12PwWme0Mrz09LUEkvLX2w3wU vuyL9ce+K1AQMlXFgQVmWjfsPNZnZIa7aAvfWa66Eas2B0IJB7PsoUe9kciczd7Z wn00/OFiMrmN0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrgeeigdejiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnheptedvhfetueeukeefhfefudegfffhhefhvdelffelteekgeeg fefhgfegkeejtddunecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgv rhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 23 Nov 2021 10:19:16 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 1A7782A0742; Tue, 23 Nov 2021 12:19:13 -0300 (-03) Date: Tue, 23 Nov 2021 12:19:13 -0300 From: Alvaro Herrera To: Peter Eisentraut Cc: Michael Paquier , pgsql-hackers Subject: Re: Some RELKIND macro refactoring Message-ID: <202111231519.kf27gjzikeko@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vtu4mi4apo2lijv6" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --vtu4mi4apo2lijv6 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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/ --vtu4mi4apo2lijv6 Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="create-storage.patch" 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); } /* --vtu4mi4apo2lijv6--