Re: Obsolete reference to pg_relation in comment

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Obsolete reference to pg_relation in comment
Date: 2023-07-26 21:14:08
Message-ID: 1948637.1690406048@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nathan Bossart <nathandbossart(at)gmail(dot)com> writes:
> On Wed, Jul 26, 2023 at 06:48:51PM +0100, Dagfinn Ilmari Mannsåker wrote:
>> * All accesses to pg_largeobject and its index make use of a single Relation
>> - * reference, so that we only need to open pg_relation once per transaction.
>> + * reference, so that we only need to open pg_class once per transaction.
>> * To avoid problems when the first such reference occurs inside a
>> * subtransaction, we execute a slightly klugy maneuver to assign ownership of
>> * the Relation reference to TopTransactionResourceOwner.

> Hm. Are you sure this is actually referring to pg_class? It seems
> unlikely given pg_relation was renamed 14 years before this comment was
> added, and the code appears to be ensuring that pg_largeobject and its
> index are opened at most once per transaction.

I believe it is just a typo/thinko for pg_class, but there's more not
to like about this comment. First, once we've made a relcache entry
it would typically stay valid across uses, so it's far from clear that
this coding actually prevents many catalog accesses in typical cases.
Second, when we do have to rebuild the relcache entry, there's a lot
more involved than just a pg_class fetch; we at least need to read
pg_attribute, and I think there may be other catalogs that we'd read
along the way, even for a system catalog that lacks complicated
features. (pg_index would presumably get looked at, for instance.)

I think we should reword this to just generically claim that holding
the Relation reference open for the whole transaction reduces overhead.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-07-26 21:20:36 Re: Obsolete reference to pg_relation in comment
Previous Message Hannu Krosing 2023-07-26 20:56:45 Re: incremental-checkopints