v23-0003-Do-not-lock-all-partitions-at-the-beginning.patch
text/plain
Filename: v23-0003-Do-not-lock-all-partitions-at-the-beginning.patch
Type: text/plain
Part: 2
Patch
Format: format-patch
Series: patch v23-0003
Subject: Do not lock all partitions at the beginning
| File | + | − |
|---|---|---|
| src/backend/optimizer/util/inherit.c | 5 | 13 |
From ada6af7a33e6289243595ed4b54bc55505c6d581 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Fri, 12 Oct 2018 19:12:53 +0900
Subject: [PATCH v23 3/3] Do not lock all partitions at the beginning
---
src/backend/optimizer/util/inherit.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c
index d01b4de583..1fb36b3e39 100644
--- a/src/backend/optimizer/util/inherit.c
+++ b/src/backend/optimizer/util/inherit.c
@@ -360,10 +360,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,
@@ -374,10 +370,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
LOCKMODE lockmode = parentrte->rellockmode;
int i;
- /* If root partitioned table, lock *all* partitions in the tree. */
- if (parentRTindex == rootParentRTindex)
- (void) find_all_inheritors(parentrte->relid, lockmode, NULL);
-
/* Already locked. */
parentrel = table_open(parentrte->relid, NoLock);
partdesc = RelationGetPartitionDesc(parentrel);
@@ -392,8 +384,8 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
for (i = 0; i < partdesc->nparts; i++)
{
Oid childOID = partdesc->oids[i];
- /* Already locked. */
- Relation childrel = table_open(childOID, NoLock);
+ /* Lock the child as it's the first time it's being opened. */
+ Relation childrel = table_open(childOID, lockmode);
RangeTblEntry *childrte = NULL;
Index childRTindex = 0;
AppendRelInfo *appinfo = NULL;
@@ -444,7 +436,7 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
/* Perform pruning. */
partindexes = prune_append_rel_partitions(parent);
- parentrel->live_parts = partindexes;
+ parent->live_parts = partindexes;
/* Must expand PlannerInfo arrays before we can add children. */
if (bms_num_members(partindexes) > 0)
@@ -463,8 +455,8 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
while ((i = bms_next_member(partindexes, i)) >= 0)
{
Oid childOID = partdesc->oids[i];
- /* Already locked. */
- Relation childrel = table_open(childOID, NoLock);
+ /* Lock the child as it's the first time it's being opened. */
+ Relation childrel = table_open(childOID, lockmode);
RangeTblEntry *childrte = NULL;
Index childRTindex = 0;
AppendRelInfo *appinfo = NULL;
--
2.11.0