Обсуждение: tablecmds: Open pg_class only when an update is required

Поиск
Список
Период
Сортировка

tablecmds: Open pg_class only when an update is required

От
Chao Li
Дата:
Hi Hackers,

I just noticed that relation_mark_replica_identity() unconditionally opened pg_class with RowExclusiveLock even in cases where relreplident has no change, which incurred unnecessary relation opens, lock acquisition.

I just made a tiny refactor that defers opening pg_class until we know that an update to relreplident is required.

I have manually tested the change, and "make check" passed.

Best regards,
Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/
Вложения

Re: tablecmds: Open pg_class only when an update is required

От
Ashutosh Bapat
Дата:
On Thu, Dec 11, 2025 at 12:45 PM Chao Li <li.evan.chao@gmail.com> wrote:
>
> Hi Hackers,
>
> I just noticed that relation_mark_replica_identity() unconditionally opened pg_class with RowExclusiveLock even in
caseswhere relreplident has no change, which incurred unnecessary relation opens, lock acquisition. 
>
> I just made a tiny refactor that defers opening pg_class until we know that an update to relreplident is required.

I think we need to lock the relation before fetching the tuple so that
the field being read remains consistent. Instead of upgrading the lock
which can deadlock, we get hold of row exclusive lock right at the
beginning.

--
Best Wishes,
Ashutosh Bapat



Re: tablecmds: Open pg_class only when an update is required

От
Chao Li
Дата:

> On Dec 11, 2025, at 21:17, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote:
>
> On Thu, Dec 11, 2025 at 12:45 PM Chao Li <li.evan.chao@gmail.com> wrote:
>>
>> Hi Hackers,
>>
>> I just noticed that relation_mark_replica_identity() unconditionally opened pg_class with RowExclusiveLock even in
caseswhere relreplident has no change, which incurred unnecessary relation opens, lock acquisition. 
>>
>> I just made a tiny refactor that defers opening pg_class until we know that an update to relreplident is required.
>
> I think we need to lock the relation before fetching the tuple so that
> the field being read remains consistent. Instead of upgrading the lock
> which can deadlock, we get hold of row exclusive lock right at the
> beginning.
>
> --
> Best Wishes,
> Ashutosh Bapat

Hi Ashutosh,

Thanks for the explanation, so I withdraw this patch.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/