Thread: [HACKERS] May cause infinite loop when initializing rel-cache containspartitioned table
[HACKERS] May cause infinite loop when initializing rel-cache containspartitioned table
From
甄明洋
Date:
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;
}
Re: [HACKERS] May cause infinite loop when initializing rel-cachecontains partitioned table
From
Amit Langote
Date:
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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Attachment
Re: [HACKERS] May cause infinite loop when initializing rel-cachecontains partitioned table
From
Robert Haas
Date:
On Mon, May 8, 2017 at 5:07 AM, Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> wrote: > 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. Committed. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company