Commit c1e0e7e1 authored by Robert Haas's avatar Robert Haas

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
parent 504c2205
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#include "parser/parse_collate.h" #include "parser/parse_collate.h"
#include "parser/parse_expr.h" #include "parser/parse_expr.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "storage/lmgr.h"
#include "storage/predicate.h" #include "storage/predicate.h"
#include "storage/smgr.h" #include "storage/smgr.h"
#include "utils/acl.h" #include "utils/acl.h"
...@@ -1760,8 +1761,7 @@ heap_drop_with_catalog(Oid relid) ...@@ -1760,8 +1761,7 @@ heap_drop_with_catalog(Oid relid)
{ {
Relation rel; Relation rel;
HeapTuple tuple; HeapTuple tuple;
Oid parentOid; Oid parentOid = InvalidOid;
Relation parent = NULL;
/* /*
* To drop a partition safely, we must grab exclusive lock on its parent, * To drop a partition safely, we must grab exclusive lock on its parent,
...@@ -1776,7 +1776,7 @@ heap_drop_with_catalog(Oid relid) ...@@ -1776,7 +1776,7 @@ heap_drop_with_catalog(Oid relid)
if (((Form_pg_class) GETSTRUCT(tuple))->relispartition) if (((Form_pg_class) GETSTRUCT(tuple))->relispartition)
{ {
parentOid = get_partition_parent(relid); parentOid = get_partition_parent(relid);
parent = heap_open(parentOid, AccessExclusiveLock); LockRelationOid(parentOid, AccessExclusiveLock);
} }
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
...@@ -1885,14 +1885,14 @@ heap_drop_with_catalog(Oid relid) ...@@ -1885,14 +1885,14 @@ heap_drop_with_catalog(Oid relid)
*/ */
DeleteRelationTuple(relid); DeleteRelationTuple(relid);
if (parent) if (OidIsValid(parentOid))
{ {
/* /*
* Invalidate the parent's relcache so that the partition is no longer * Invalidate the parent's relcache so that the partition is no longer
* included in its partition descriptor. * included in its partition descriptor.
*/ */
CacheInvalidateRelcache(parent); CacheInvalidateRelcacheByRelid(parentOid);
heap_close(parent, NoLock); /* keep the lock */ /* keep the lock */
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment