Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1e0e7e

Browse files
committed
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
1 parent 504c220 commit c1e0e7e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/backend/catalog/heap.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "parser/parse_collate.h"
6969
#include "parser/parse_expr.h"
7070
#include "parser/parse_relation.h"
71+
#include "storage/lmgr.h"
7172
#include "storage/predicate.h"
7273
#include "storage/smgr.h"
7374
#include "utils/acl.h"
@@ -1760,8 +1761,7 @@ heap_drop_with_catalog(Oid relid)
17601761
{
17611762
Relation rel;
17621763
HeapTuple tuple;
1763-
Oid parentOid;
1764-
Relation parent = NULL;
1764+
Oid parentOid = InvalidOid;
17651765

17661766
/*
17671767
* To drop a partition safely, we must grab exclusive lock on its parent,
@@ -1776,7 +1776,7 @@ heap_drop_with_catalog(Oid relid)
17761776
if (((Form_pg_class) GETSTRUCT(tuple))->relispartition)
17771777
{
17781778
parentOid = get_partition_parent(relid);
1779-
parent = heap_open(parentOid, AccessExclusiveLock);
1779+
LockRelationOid(parentOid, AccessExclusiveLock);
17801780
}
17811781

17821782
ReleaseSysCache(tuple);
@@ -1885,14 +1885,14 @@ heap_drop_with_catalog(Oid relid)
18851885
*/
18861886
DeleteRelationTuple(relid);
18871887

1888-
if (parent)
1888+
if (OidIsValid(parentOid))
18891889
{
18901890
/*
18911891
* Invalidate the parent's relcache so that the partition is no longer
18921892
* included in its partition descriptor.
18931893
*/
1894-
CacheInvalidateRelcache(parent);
1895-
heap_close(parent, NoLock); /* keep the lock */
1894+
CacheInvalidateRelcacheByRelid(parentOid);
1895+
/* keep the lock */
18961896
}
18971897
}
18981898

0 commit comments

Comments
 (0)