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 <tndrw...@gmail.com>
Sent: Wednesday, May 10, 2023 10:57 AM
To: Xiaoran Wang <wxiao...@vmware.com>
Cc: PostgreSQL-development <pgsql-hack...@postgresql.org>
Subject: Re: [PATCH] Use RelationClose rather than table_close in 
heap_create_with_catalog

!! External Email


Xiaoran Wang <wxiao...@vmware.com<mailto:wxiao...@vmware.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.

Reply via email to