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 1mFdW3-0007Wa-Ij for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Aug 2021 14:23:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mFdW2-0003JL-Iu for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Aug 2021 14:23:02 +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 1mFdW1-0003JC-OD for pgsql-hackers@lists.postgresql.org; Mon, 16 Aug 2021 14:23:02 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mFdVw-0000EW-Te for pgsql-hackers@postgresql.org; Mon, 16 Aug 2021 14:23:01 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E8FEA5C00EB; Mon, 16 Aug 2021 10:22:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 16 Aug 2021 10:22:54 -0400 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= fm3; bh=s+t1NFi0VWGeU/F47hJ/WOhqCzKD5VQDdMzEdAgraLY=; b=XRsBDERp t45i6iJtPcTLS688hB5pXLL3K0iho1YuOMrWgydEInUjGXFm4Nwth7ldfB1Yf1VH OhCQ2rXRsyn8i0JVRZWSVDNmDDSrjjZjsHAUTna35M4ertVgozFXKXEtmHAF0yCV Vloisp4zkk46YCkltYds+1XrXus/OD8nkUy6F4FZZ3MqfH/Ip+ZFY95h+PxlZfve mQIweJ3wSusprV0xOqOYJucvG2DGUoEca2ySBKlms4YIdY6M/ZPRo/uO1OBzWuBP BtNL2mYymyCens0J1lVcsrEpUQARDokNPXrcTlJaHEttOMyt74Tcu3KarAgFwLQ+ rYqjE6dKGyC+DA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrledugdejhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeevjedu feeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgv rhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 16 Aug 2021 10:22:53 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 6E69C2A099B; Mon, 16 Aug 2021 10:22:50 -0400 (-04) Date: Mon, 16 Aug 2021 10:22:50 -0400 From: Alvaro Herrera To: Peter Eisentraut Cc: pgsql-hackers Subject: Re: Some RELKIND macro refactoring Message-ID: <202108161422.sodbvh3hb7ra@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 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 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/