From c1e0e7e1d790bf18c913e6a452dea811e858b554 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Fri, 28 Apr 2017 14:00:58 -0400 Subject: [PATCH] Speed up dropping tables with many partitions. We need to lock the parent, but we don't need a relcache entry for it. Gao Zeng Qi, reviewed by Amit Langote Discussion: http://postgr.es/m/CAFmBtr0ukqJjRJEhPWL5wt4rNMrJUUxggVAGXPR3SyYh3E+HDQ@mail.gmail.com --- src/backend/catalog/heap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index ece4df02cd..ab3d83f29b 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -68,6 +68,7 @@ #include "parser/parse_collate.h" #include "parser/parse_expr.h" #include "parser/parse_relation.h" +#include "storage/lmgr.h" #include "storage/predicate.h" #include "storage/smgr.h" #include "utils/acl.h" @@ -1760,8 +1761,7 @@ heap_drop_with_catalog(Oid relid) { Relation rel; HeapTuple tuple; - Oid parentOid; - Relation parent = NULL; + Oid parentOid = InvalidOid; /* * To drop a partition safely, we must grab exclusive lock on its parent, @@ -1776,7 +1776,7 @@ heap_drop_with_catalog(Oid relid) if (((Form_pg_class) GETSTRUCT(tuple))->relispartition) { parentOid = get_partition_parent(relid); - parent = heap_open(parentOid, AccessExclusiveLock); + LockRelationOid(parentOid, AccessExclusiveLock); } ReleaseSysCache(tuple); @@ -1885,14 +1885,14 @@ heap_drop_with_catalog(Oid relid) */ DeleteRelationTuple(relid); - if (parent) + if (OidIsValid(parentOid)) { /* * Invalidate the parent's relcache so that the partition is no longer * included in its partition descriptor. */ - CacheInvalidateRelcache(parent); - heap_close(parent, NoLock); /* keep the lock */ + CacheInvalidateRelcacheByRelid(parentOid); + /* keep the lock */ } }