v21-0006-Do-not-lock-all-partitions-at-the-beginning.patch

text/plain

Filename: v21-0006-Do-not-lock-all-partitions-at-the-beginning.patch
Type: text/plain
Part: 5
Message: Re: speeding up planning with partitions

Patch

Format: format-patch
Series: patch v21-0006
Subject: Do not lock all partitions at the beginning
File+
src/backend/optimizer/util/inherit.c 5 10
From d98292ebd9a4470e2ab9f5cc01a08b559c4e46cc Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Fri, 12 Oct 2018 19:12:53 +0900
Subject: [PATCH v21 6/6] Do not lock all partitions at the beginning

---
 src/backend/optimizer/util/inherit.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c
index fa719a0222..9c4465c014 100644
--- a/src/backend/optimizer/util/inherit.c
+++ b/src/backend/optimizer/util/inherit.c
@@ -332,10 +332,6 @@ expand_nonpartitioned_inherited_rtentry(PlannerInfo *root,
  *
  * Partitions are added to the query in order in which they are found in
  * the parent's PartitionDesc.
- *
- * Note: even though only the unpruned partitions will be added to the
- * resulting plan, this still locks *all* partitions via find_all_inheritors
- * when this function is called for the root partitioned table.
  */
 static void
 expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
@@ -349,10 +345,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
 									parentrel->inh_root_parent :
 									parentRTindex;
 
-	/* If root partitioned table, lock *all* partitions in the tree. */
-	if (parentRTindex == rootParentRTindex)
-		(void) find_all_inheritors(parentrte->relid, lockmode, NULL);
-
 	/*
 	 * Initialize partitioned_child_rels to contain this RT index.
 	 *
@@ -389,8 +381,11 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
 		RangeTblEntry *childrte;
 		Index		childRTindex;
 
-		/* Open rel; we already have required locks */
-		newrelation = table_open(childOID, NoLock);
+		/*
+		 * Open rel; this's the first time of opening partitions for this
+		 * query, so take the appropriate locks.
+		 */
+		newrelation = table_open(childOID, lockmode);
 		Assert(!RELATION_IS_OTHER_TEMP(newrelation));
 
 		/*
-- 
2.11.0