Re: Obsolete reference to pg_relation in comment

2023-09-26 Thread Bruce Momjian
On Thu, Sep  7, 2023 at 10:44:25AM +0200, Daniel Gustafsson wrote:
> > On 6 Sep 2023, at 21:13, Bruce Momjian  wrote:
> > On Wed, Jul 26, 2023 at 05:14:08PM -0400, Tom Lane wrote:
> 
> >> I think we should reword this to just generically claim that holding
> >> the Relation reference open for the whole transaction reduces overhead.
> > 
> > How is this attached patch?
> 
> Reads good to me, +1.

Patch applied to master.  I didn't think backpatching it made much sense
since it is so localized.

-- 
  Bruce Momjian  https://momjian.us
  EDB  https://enterprisedb.com

  Only you can decide what is important to you.




Re: Obsolete reference to pg_relation in comment

2023-09-07 Thread Daniel Gustafsson
> On 6 Sep 2023, at 21:13, Bruce Momjian  wrote:
> On Wed, Jul 26, 2023 at 05:14:08PM -0400, Tom Lane wrote:

>> I think we should reword this to just generically claim that holding
>> the Relation reference open for the whole transaction reduces overhead.
> 
> How is this attached patch?

Reads good to me, +1.

--
Daniel Gustafsson





Re: Obsolete reference to pg_relation in comment

2023-09-06 Thread Bruce Momjian
On Wed, Jul 26, 2023 at 05:14:08PM -0400, Tom Lane wrote:
> Nathan Bossart  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.

How is this attached patch?

-- 
  Bruce Momjian  https://momjian.us
  EDB  https://enterprisedb.com

  Only you can decide what is important to you.
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
new file mode 100644
index 84e543e..cc9c335
*** a/src/backend/storage/large_object/inv_api.c
--- b/src/backend/storage/large_object/inv_api.c
***
*** 58,68 
  bool		lo_compat_privileges;
  
  /*
!  * 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.
!  * 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.
   */
  static Relation lo_heap_r = NULL;
  static Relation lo_index_r = NULL;
--- 58,68 
  bool		lo_compat_privileges;
  
  /*
!  * All accesses to pg_largeobject and its index make use of a single
!  * Relation reference.  To guarantee that the relcache entry remains
!  * in the cache, on the first reference inside a subtransaction, we
!  * execute a slightly klugy maneuver to assign ownership of the
!  * Relation reference to TopTransactionResourceOwner.
   */
  static Relation lo_heap_r = NULL;
  static Relation lo_index_r = NULL;


Re: Obsolete reference to pg_relation in comment

2023-07-26 Thread Nathan Bossart
On Wed, Jul 26, 2023 at 05:14:08PM -0400, Tom Lane wrote:
> I think we should reword this to just generically claim that holding
> the Relation reference open for the whole transaction reduces overhead.

WFM

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Re: Obsolete reference to pg_relation in comment

2023-07-26 Thread Tom Lane
Nathan Bossart  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




Re: Obsolete reference to pg_relation in comment

2023-07-26 Thread Nathan Bossart
Okay, now looking at the patch...

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 couldn't find the
original thread for this comment, unfortunately, but ISTM we might want to
replace "pg_relation" with "them" instead.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Re: Obsolete reference to pg_relation in comment

2023-07-26 Thread Nathan Bossart
On Wed, Jul 26, 2023 at 11:53:06AM -0700, Nathan Bossart wrote:
> On Wed, Jul 26, 2023 at 06:48:51PM +0100, Dagfinn Ilmari Mannsåker wrote:
>> Triggered by a discussion on IRC, I noticed that there's a stray
>> reference to pg_relation in a comment that was added long after it was
>> renamed to pg_class.  Here's a patch to bring that up to speed.
> 
>> pg_relation was renamed to pg_class in 1991, but this comment (added
>> in 2004) missed the memo
> 
> Huh, interesting!  I dug around the Berkeley archives [0] and found
> comments indicating that pg_relation was renamed to pg_class in Februrary
> 1990.  However, it looks like the file was named pg_relation.h until
> Postgres95 v0.01, which has the following comment in pg_class.h:
> 
>*``pg_relation'' is being replaced by ``pg_class''.  currently
>*we are only changing the name in the catalogs but someday the
>*code will be changed too. -cim 2/26/90
>*[it finally happens.  -ay 11/5/94]

This comment actually lived in Postgres until 9cf80f2 (June 2000), too.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Re: Obsolete reference to pg_relation in comment

2023-07-26 Thread Nathan Bossart
On Wed, Jul 26, 2023 at 06:48:51PM +0100, Dagfinn Ilmari Mannsåker wrote:
> Triggered by a discussion on IRC, I noticed that there's a stray
> reference to pg_relation in a comment that was added long after it was
> renamed to pg_class.  Here's a patch to bring that up to speed.

> pg_relation was renamed to pg_class in 1991, but this comment (added
> in 2004) missed the memo

Huh, interesting!  I dug around the Berkeley archives [0] and found
comments indicating that pg_relation was renamed to pg_class in Februrary
1990.  However, it looks like the file was named pg_relation.h until
Postgres95 v0.01, which has the following comment in pg_class.h:

 *``pg_relation'' is being replaced by ``pg_class''.  currently
 *we are only changing the name in the catalogs but someday the
 *code will be changed too. -cim 2/26/90
 *[it finally happens.  -ay 11/5/94]

[0] https://dsf.berkeley.edu/postgres.html

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Obsolete reference to pg_relation in comment

2023-07-26 Thread Dagfinn Ilmari Mannsåker
Hi hackers,

Triggered by a discussion on IRC, I noticed that there's a stray
reference to pg_relation in a comment that was added long after it was
renamed to pg_class.  Here's a patch to bring that up to speed.

- ilmari

>From e395f8cb293f674f45eb3847534de07c7124e738 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= 
Date: Wed, 26 Jul 2023 18:31:51 +0100
Subject: [PATCH] Fix obsolete reference to pg_relation in comment

pg_relation was renamed to pg_class in 1991, but this comment (added
in 2004) missed the memo
---
 src/backend/storage/large_object/inv_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index 84e543e731..a56912700b 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -59,7 +59,7 @@ bool		lo_compat_privileges;
 
 /*
  * 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.
-- 
2.39.2