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 1mxGpm-0003m5-GZ for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Dec 2021 23:03:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxGpl-0002yh-AI for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Dec 2021 23:03:45 +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 1mxGpl-0002yY-0z for pgsql-hackers@lists.postgresql.org; Tue, 14 Dec 2021 23:03:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxGpi-00078R-OP for pgsql-hackers@postgresql.org; Tue, 14 Dec 2021 23:03:44 +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 1BEN30Hi560419; Tue, 14 Dec 2021 18:03:00 -0500 From: Tom Lane To: Chapman Flack cc: PostgreSQL Hackers Subject: Re: Life cycles of tuple descriptors In-reply-to: <61B901A4.1050808@anastigmatix.net> References: <61B901A4.1050808@anastigmatix.net> Comments: In-reply-to Chapman Flack message dated "Tue, 14 Dec 2021 15:42:12 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <560417.1639522980.1@sss.pgh.pa.us> Date: Tue, 14 Dec 2021 18:03:00 -0500 Message-ID: <560418.1639522980@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Chapman Flack writes: > There are some things about the life cycle of the common TupleDesc > that I'm not 100% sure about. > 1. In general, if you get one from relcache or typcache, it is > reference-counted, right? Tupdescs for named composite types should be, since those are potentially modifiable by DDL. The refcount allows a stale tupdesc to go away when it's no longer referenced anywhere. Tupdescs for RECORD types are a different story: there's no way to change them once created, so they'll live as long as the process does (at least for tupdescs kept in the typcache). Refcounting isn't terribly necessary in that case; and at least for the shared tupdesc case, we don't do it, to avoid questions of modifying a piece of shared state. > 3. Is that shared case the only way you could see a non-refcounted > TupleDesc handed to you by the typcache? I'm not sure what happens for a non-shared RECORD tupdesc, but it probably wouldn't be wise to assume anything either way. > 5. When a constructed TupleDesc is blessed, the copy placed in the cache > by assign_record_type_typmod is born with a refcount of 1. Assuming every > later user of that TupleDesc plays nicely with balanced pin and release, > what event(s), if any, could ever occur to decrease that initial 1 to 0? That refcount is describing the cache's own reference, so as long as that reference remains it'd be incorrect to decrease the refcount to 0. regards, tom lane