aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-11-27 19:22:08 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-11-27 19:22:08 -0500
commit64487044966d6246052ff974f0ce98cac5a0c79b (patch)
tree6d005d16eec7832b31ec1af38b01ae0677fbb0ad /src
parenta57aa430b613250270cf5cc78a34a3454e61acda (diff)
downloadpostgresql-64487044966d6246052ff974f0ce98cac5a0c79b.tar.gz
postgresql-64487044966d6246052ff974f0ce98cac5a0c79b.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/heap.c5
-rw-r--r--src/backend/commands/tablecmds.c3
2 files changed, 5 insertions, 3 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index a376b99f1ed..bb21e58a454 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1769,6 +1769,8 @@ heap_drop_with_catalog(Oid relid)
* shared-cache-inval notice that will make them update their index lists.
*/
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "cache lookup failed for relation %u", relid);
if (((Form_pg_class) GETSTRUCT(tuple))->relispartition)
{
parentOid = get_partition_parent(relid);
@@ -3105,9 +3107,6 @@ StorePartitionKey(Relation rel,
Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
- tuple = SearchSysCache1(PARTRELID,
- ObjectIdGetDatum(RelationGetRelid(rel)));
-
/* Copy the partition attribute numbers, opclass OIDs into arrays */
partattrs_vec = buildint2vector(partattrs, partnatts);
partopclass_vec = buildoidvector(partopclass, partnatts);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 33c99b3777e..18c9f21617d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -13815,6 +13815,9 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
classRel = heap_open(RelationRelationId, RowExclusiveLock);
tuple = SearchSysCacheCopy1(RELOID,
ObjectIdGetDatum(RelationGetRelid(partRel)));
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "cache lookup failed for relation %u",
+ RelationGetRelid(partRel));
Assert(((Form_pg_class) GETSTRUCT(tuple))->relispartition);
(void) SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound,