0001-Don-t-building-a-relcache-entry-since-we-don-t-need-.patch

application/octet-stream

Filename: 0001-Don-t-building-a-relcache-entry-since-we-don-t-need-.patch
Type: application/octet-stream
Part: 0
Message: Re: Dropping a partitioned table takes too long

Patch

Format: format-patch
Series: patch 0001
Subject: Don't building a relcache entry since we don't need it when dropping partitioned table.
File+
src/backend/catalog/heap.c 6 6
From f6ad5abe8895e1d5167804c165a314d6d226daf9 Mon Sep 17 00:00:00 2001
From: gaozq <gaozq@upbase.com.cn>
Date: Tue, 25 Apr 2017 11:07:04 +0000
Subject: [PATCH] Don't building a relcache entry since we don't need it when
 dropping partitioned table.

---
 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 ece4df0..ab3d83f 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 */
 	}
 }
 
-- 
2.7.4