diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-04-28 14:00:58 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-04-28 14:02:24 -0400 |
commit | c1e0e7e1d790bf18c913e6a452dea811e858b554 (patch) | |
tree | f82e3ff635c13f03524e5f84bf317d23c15b2e30 | |
parent | 504c2205abc7de67386f9c95630f38ee15626f07 (diff) | |
download | postgresql-c1e0e7e1d790bf18c913e6a452dea811e858b554.tar.gz postgresql-c1e0e7e1d790bf18c913e6a452dea811e858b554.zip |
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
-rw-r--r-- | src/backend/catalog/heap.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index ece4df02cde..ab3d83f29bb 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 */ } } |