Re: [PATCH] Use RelationClose rather than table_close in heap_create_with_catalog

From: Xiaoran Wang <wxiaoran(at)vmware(dot)com>
To: "tndrwang(at)gmail(dot)com" <tndrwang(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Use RelationClose rather than table_close in heap_create_with_catalog
Date: 2023-05-10 13:48:36
Message-ID: DS0PR05MB968928826514AAD5470E1542BA779@DS0PR05MB9689.namprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The routine table_close​ takes 2 params: Relation​ and LOCKMODE​, it first calls RelationClose to decrease the relation cache reference count, then deals with the lock on the table based on LOCKMOD​ param.

In heap_create_with_catalog, the Relation new_rel_desc is only a local relation cache, created by RelationBuildLocalRelation. No other processes can see this relation, as the transaction is not committed, so there is no lock on it.

There is no problem to release the relation cache by table_close(new_rel_desc, NoLock) here. However, from my point of view, table_close(new_rel_desc, NoLock); /* do not unlock till end of xact */​
this line is a little confusing since there is no lock on the relation at all. So I think it's better to use RelationColse here.
________________________________
From: tender wang <tndrwang(at)gmail(dot)com>
Sent: Wednesday, May 10, 2023 10:57 AM
To: Xiaoran Wang <wxiaoran(at)vmware(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Use RelationClose rather than table_close in heap_create_with_catalog

!! External Email

Xiaoran Wang <wxiaoran(at)vmware(dot)com<mailto:wxiaoran(at)vmware(dot)com>> 于2023年3月18日周六 15:04写道:
Hi hackers,

In heap_create_with_catalog, the Relation new_rel_desc is created
by RelationBuildLocalRelation, not table_open. So it's better to
call RelationClose to release it.
Why it's better to call RelationClose? Is there a problem if using table_close()?
What's more, the comment for it seems useless, just delete it.

Thanks!

regard, tender wang

!! External Email: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2023-05-10 14:17:24 Re: [PATCH] Use RelationClose rather than table_close in heap_create_with_catalog
Previous Message Bharath Rupireddy 2023-05-10 13:33:59 Re: Tables getting stuck at 's' state during logical replication