Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpFhA-005pmI-E7 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 22:55:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rpFh9-007GXn-GU for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 22:55:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpFh9-007GXf-77 for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 22:55:03 +0000 Received: from charmander.telsasoft.com ([50.244.222.1] helo=pryzbyj2023.telsasoft) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpFh5-006bR6-ED for pgsql-hackers@postgresql.org; Tue, 26 Mar 2024 22:55:01 +0000 Received: by pryzbyj2023.telsasoft (Postfix, from userid 1000) id 61D3D9848; Tue, 26 Mar 2024 17:54:58 -0500 (CDT) Date: Tue, 26 Mar 2024 17:54:58 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Michael Paquier , Peter Eisentraut , Soumyadeep Chakraborty , Zhihong Yu , pgsql-hackers@postgresql.org, Ashwin Agrawal , vanjared@vmware.com, Alexander Lakhin Subject: Re: ALTER TABLE SET ACCESS METHOD on partitioned tables Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202403261105.6o4ff4d6qagc@alvherre.pgsql> <202403211207.hfyirjweshbh@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 21, 2024 at 01:07:01PM +0100, Alvaro Herrera wrote: > Given that Michaël is temporarily gone, I propose to push the attached > tomorrow. Thanks. On Tue, Mar 26, 2024 at 12:05:47PM +0100, Alvaro Herrera wrote: > On 2024-Mar-26, Alexander Lakhin wrote: > > > Hello Alvaro, > > > > 21.03.2024 15:07, Alvaro Herrera wrote: > > > Given that Michaël is temporarily gone, I propose to push the attached > > > tomorrow. > > > > Please look at a new anomaly introduced with 374c7a229. > > Starting from that commit, the following erroneous query: > > CREATE FOREIGN TABLE fp PARTITION OF pg_am DEFAULT SERVER x; > > > > triggers an assertion failure: > > TRAP: failed Assert("relation->rd_rel->relam == InvalidOid"), File: "relcache.c", Line: 1219, PID: 3706301 > > Hmm, yeah, we're setting relam for relations that shouldn't have it. > I propose the attached. Looks right. That's how I originally wrote it, except for the "stmt->accessMethod != NULL" case. I prefered my way - the grammar should refuse to set stmt->accessMethod for inappropriate relkinds. And you could assert that. I also prefered to set "accessMethodId = InvalidOid" once, rather than twice. diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8a02c5b05b6..050be89728f 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -962,18 +962,21 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, * case of a partitioned table) the parent's, if it has one. */ if (stmt->accessMethod != NULL) - accessMethodId = get_table_am_oid(stmt->accessMethod, false); - else if (stmt->partbound) { - Assert(list_length(inheritOids) == 1); - accessMethodId = get_rel_relam(linitial_oid(inheritOids)); + Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE); + accessMethodId = get_table_am_oid(stmt->accessMethod, false); } - else - accessMethodId = InvalidOid; + else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE) + { + if (stmt->partbound) + { + Assert(list_length(inheritOids) == 1); + accessMethodId = get_rel_relam(linitial_oid(inheritOids)); + } - /* still nothing? use the default */ - if (RELKIND_HAS_TABLE_AM(relkind) && !OidIsValid(accessMethodId)) - accessMethodId = get_table_am_oid(default_table_access_method, false); + if (RELKIND_HAS_TABLE_AM(relkind) && !OidIsValid(accessMethodId)) + accessMethodId = get_table_am_oid(default_table_access_method, false); + } /* * Create the relation. Inherited defaults and constraints are passed in