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 1pwmjn-0008AN-6p for pgsql-hackers@arkaria.postgresql.org; Wed, 10 May 2023 16:32:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pwmjl-0001Qk-NL for pgsql-hackers@arkaria.postgresql.org; Wed, 10 May 2023 16:32:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pwmjl-0001Qb-EH for pgsql-hackers@lists.postgresql.org; Wed, 10 May 2023 16:32:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pwmjj-001auV-1o for pgsql-hackers@lists.postgresql.org; Wed, 10 May 2023 16:32:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 34AGWGdJ901574; Wed, 10 May 2023 12:32:16 -0400 From: Tom Lane To: Bharath Rupireddy cc: Xiaoran Wang , "pgsql-hackers@lists.postgresql.org" Subject: Re: [PATCH] Use RelationClose rather than table_close in heap_create_with_catalog In-reply-to: References: Comments: In-reply-to Bharath Rupireddy message dated "Wed, 10 May 2023 19:47:24 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <901572.1683736336.1@sss.pgh.pa.us> Date: Wed, 10 May 2023 12:32:16 -0400 Message-ID: <901573.1683736336@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bharath Rupireddy writes: > And, the /* do not unlock till end of xact */, it looks like it's been > there from day 1. It may be indicating that the ref count fo the new > relation created in heap_create_with_catalog() will be decremented at > the end of xact, but I'm not sure what it means. Hmm, I think it's been copied-and-pasted from somewhere. It's quite common for us to not release locks on modified tables until end of transaction. However, that's not what's happening here, because we actually *don't have any such lock* at this point, as you can easily prove by stepping through this code and watching the contents of pg_locks from another session. We do acquire AccessExclusiveLock on the new table eventually, but not till control returns to DefineRelation. I'm not real sure that I like the proposed code change: it's unclear to me whether it's an unwise piercing of a couple of abstraction layers or an okay change because those abstraction layers haven't yet been applied to the new relation at all. However, I think the existing comment is actively misleading and needs to be changed. Maybe something like /* * Close the relcache entry, since we return only an OID not a * relcache reference. Note that we do not yet hold any lockmanager * lock on the new rel, so there's nothing to release. */ table_close(new_rel_desc, NoLock); /* * ok, the relation has been cataloged, so close catalogs and return * the OID of the newly created relation. */ table_close(pg_class_desc, RowExclusiveLock); Given these comments, maybe changing the first call to RelationClose would be sensible, but I'm still not quite convinced. regards, tom lane