Skip to content

Commit 6448704

Browse files
committed
Fix assorted syscache lookup sloppiness in partition-related code.
heap_drop_with_catalog and ATExecDetachPartition neglected to check for SearchSysCache failures, as noted in bugs #14927 and #14928 from Pan Bian. Such failures are pretty unlikely, since we should already have some sort of lock on the rel at these points, but it's neither a good idea nor per project style to omit a check for failure. Also, StorePartitionKey contained a syscache lookup that it never did anything with, including never releasing the result. Presumably the reason why we don't see refcount-leak complaints is that the lookup always fails; but in any case it's pretty useless, so remove it. All of these errors were evidently introduced by the relation partitioning feature. Back-patch to v10 where that came in. Amit Langote and Tom Lane Discussion: https://postgr.es/m/20171127090105.1463.3962@wrigleys.postgresql.org Discussion: https://postgr.es/m/20171127091341.1468.72696@wrigleys.postgresql.org
1 parent a57aa43 commit 6448704

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/backend/catalog/heap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,8 @@ heap_drop_with_catalog(Oid relid)
17691769
* shared-cache-inval notice that will make them update their index lists.
17701770
*/
17711771
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
1772+
if (!HeapTupleIsValid(tuple))
1773+
elog(ERROR, "cache lookup failed for relation %u", relid);
17721774
if (((Form_pg_class) GETSTRUCT(tuple))->relispartition)
17731775
{
17741776
parentOid = get_partition_parent(relid);
@@ -3105,9 +3107,6 @@ StorePartitionKey(Relation rel,
31053107

31063108
Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
31073109

3108-
tuple = SearchSysCache1(PARTRELID,
3109-
ObjectIdGetDatum(RelationGetRelid(rel)));
3110-
31113110
/* Copy the partition attribute numbers, opclass OIDs into arrays */
31123111
partattrs_vec = buildint2vector(partattrs, partnatts);
31133112
partopclass_vec = buildoidvector(partopclass, partnatts);

src/backend/commands/tablecmds.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13815,6 +13815,9 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
1381513815
classRel = heap_open(RelationRelationId, RowExclusiveLock);
1381613816
tuple = SearchSysCacheCopy1(RELOID,
1381713817
ObjectIdGetDatum(RelationGetRelid(partRel)));
13818+
if (!HeapTupleIsValid(tuple))
13819+
elog(ERROR, "cache lookup failed for relation %u",
13820+
RelationGetRelid(partRel));
1381813821
Assert(((Form_pg_class) GETSTRUCT(tuple))->relispartition);
1381913822

1382013823
(void) SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy