Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 079797e

Browse filesBrowse files
committed
Purge potentially created bounds cache entries if build_pathman_relation_info failed.
Otherwise they might contain obsolete data, e.g. - create range partitioned table T with a couple of partitions - make pathman forget about it - create another table P inherited from previously partitioned one, but with no pathman constraints - attempt to add_to_pathman_config T as range partitioned table it will fail as P has no constraint, but might register other partitions in bounds cache - now add_to_pathman_config T as hash partitioned table will fail in attempt to use this cache (part_idx not initialized)
1 parent e251d2a commit 079797e
Copy full SHA for 079797e

File tree

1 file changed

+27
-1
lines changed
Filter options

1 file changed

+27
-1
lines changed

‎src/relation_info.c

Copy file name to clipboardExpand all lines: src/relation_info.c
+27-1Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ build_pathman_relation_info(Oid relid, Datum *values)
408408
prel->fresh = true;
409409
prel->mcxt = prel_mcxt;
410410

411-
/* Memory leak protection */
411+
/* Memory leak and cache protection */
412412
PG_TRY();
413413
{
414414
MemoryContext old_mcxt;
@@ -496,6 +496,32 @@ build_pathman_relation_info(Oid relid, Datum *values)
496496
}
497497
PG_CATCH();
498498
{
499+
/*
500+
* If we managed to create some children but failed later, bounds
501+
* cache now might have obsolete data for something that probably is
502+
* not a partitioned table at all. Remove it.
503+
*/
504+
if (prel->children != NULL)
505+
{
506+
uint32 i;
507+
508+
for (i = 0; i < PrelChildrenCount(prel); i++)
509+
{
510+
Oid child;
511+
512+
/*
513+
* We rely on children and ranges array allocated with 0s, not
514+
* random data
515+
*/
516+
if (prel->parttype == PT_HASH)
517+
child = prel->children[i];
518+
else if (prel->parttype == PT_RANGE)
519+
child = prel->ranges[i].child_oid;
520+
521+
forget_bounds_of_partition(child);
522+
}
523+
}
524+
499525
/* Free this entry */
500526
free_pathman_relation_info(prel);
501527

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.