Re: May cause infinite loop when initializing rel-cache contains partitioned table

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: 甄明洋 <18612389267(at)yeah(dot)net>, pg开发者 <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: May cause infinite loop when initializing rel-cache contains partitioned table
Date: 2017-05-08 09:07:20
Message-ID: 57e3c5e2-454f-72c0-c568-46deae7e3091@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2017/05/05 17:26, 甄明洋 wrote:
> The function of initializing rel-cache is RelationCacheInitializePhase3 and in src/backend/utils/cache/relcache.c file.
> When initializing the partition description information, we forget to check if partition key or descriptor is NULL.
> Therefore, after the loop restarts, the partition information will be initialized again, resulting in an infinite loop.
> Code:
> /*
> * Reload partition key and descriptor for a partitioned table.
> */
> if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
> {
> RelationBuildPartitionKey(relation);
> Assert(relation->rd_partkey != NULL);
>
>
> RelationBuildPartitionDesc(relation);
> Assert(relation->rd_partdesc != NULL);
>
>
> restart = true;
> }

Thanks for bringing it to the notice. The above code should follow what's
done for other fields that are initialized by
RelationCacheInitializePhase3(). Although, since none of the entries in
the relcache init file are partitioned tables, infinite loop won't occur
in practice, but it's a good idea to fix the code anyway.

Attached patch does that.

Thanks,
Amit

Attachment Content-Type Size
0001-Check-partitioning-fields-are-NULL-in-RelationCacheI.patch text/x-diff 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2017-05-08 09:27:30 Get stuck when dropping a subscription during synchronizing table
Previous Message Tsunakawa, Takayuki 2017-05-08 08:29:34 Re: [PATCH v1] Add and report the new "in_hot_standby" GUC pseudo-variable.