Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 26e7709

Browse files
tglsfdcCommitfest Bot
authored and
Commitfest Bot
committed
Avoid duplicate ExecOpenIndices/ExecCloseIndices in logrep worker.
During a cross-partition update, apply_handle_tuple_routing calls ExecFindPartition which does ExecOpenIndices (and expects that ExecCleanupTupleRouting will close the indexes again). Therefore, we must avoid re-opening/closing the table's indexes when the update code path calls apply_handle_insert_internal or apply_handle_delete_internal. That leaves us with only one caller of each function that needs indexes to be opened/closed, so we can just move those calls to the callers. Also, remove the entirely-duplicative open/close calls within apply_handle_tuple_routing itself. Bug: #18815 Reported-by: Sergey Belyashov <sergey.belyashov@gmail.com> Discussion: https://postgr.es/m/18815-2a0407cc7f40b327@postgresql.org Backpatch-through: TBD
1 parent 8d80010 commit 26e7709

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/backend/replication/logical/worker.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,8 +2454,13 @@ apply_handle_insert(StringInfo s)
24542454
apply_handle_tuple_routing(edata,
24552455
remoteslot, NULL, CMD_INSERT);
24562456
else
2457-
apply_handle_insert_internal(edata, edata->targetRelInfo,
2458-
remoteslot);
2457+
{
2458+
ResultRelInfo *relinfo = edata->targetRelInfo;
2459+
2460+
ExecOpenIndices(relinfo, true);
2461+
apply_handle_insert_internal(edata, relinfo, remoteslot);
2462+
ExecCloseIndices(relinfo);
2463+
}
24592464

24602465
finish_edata(edata);
24612466

@@ -2482,16 +2487,13 @@ apply_handle_insert_internal(ApplyExecutionData *edata,
24822487
{
24832488
EState *estate = edata->estate;
24842489

2485-
/* We must open indexes here. */
2486-
ExecOpenIndices(relinfo, true);
2490+
/* Caller will not have done this bit. */
2491+
Assert(relinfo->ri_onConflictArbiterIndexes == NIL);
24872492
InitConflictIndexes(relinfo);
24882493

24892494
/* Do the insert. */
24902495
TargetPrivilegesCheck(relinfo->ri_RelationDesc, ACL_INSERT);
24912496
ExecSimpleRelationInsert(relinfo, estate, remoteslot);
2492-
2493-
/* Cleanup. */
2494-
ExecCloseIndices(relinfo);
24952497
}
24962498

24972499
/*
@@ -2816,8 +2818,14 @@ apply_handle_delete(StringInfo s)
28162818
apply_handle_tuple_routing(edata,
28172819
remoteslot, NULL, CMD_DELETE);
28182820
else
2819-
apply_handle_delete_internal(edata, edata->targetRelInfo,
2821+
{
2822+
ResultRelInfo *relinfo = edata->targetRelInfo;
2823+
2824+
ExecOpenIndices(relinfo, false);
2825+
apply_handle_delete_internal(edata, relinfo,
28202826
remoteslot, rel->localindexoid);
2827+
ExecCloseIndices(relinfo);
2828+
}
28212829

28222830
finish_edata(edata);
28232831

@@ -2851,7 +2859,6 @@ apply_handle_delete_internal(ApplyExecutionData *edata,
28512859
bool found;
28522860

28532861
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1, NIL);
2854-
ExecOpenIndices(relinfo, false);
28552862

28562863
found = FindReplTupleInLocalRel(edata, localrel, remoterel, localindexoid,
28572864
remoteslot, &localslot);
@@ -2892,7 +2899,6 @@ apply_handle_delete_internal(ApplyExecutionData *edata,
28922899
}
28932900

28942901
/* Cleanup. */
2895-
ExecCloseIndices(relinfo);
28962902
EvalPlanQualEnd(&epqstate);
28972903
}
28982904

@@ -3131,7 +3137,6 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
31313137
* work already done above to find the local tuple in the
31323138
* partition.
31333139
*/
3134-
ExecOpenIndices(partrelinfo, true);
31353140
InitConflictIndexes(partrelinfo);
31363141

31373142
EvalPlanQualSetSlot(&epqstate, remoteslot_part);
@@ -3181,8 +3186,6 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
31813186
get_namespace_name(RelationGetNamespace(partrel_new)),
31823187
RelationGetRelationName(partrel_new));
31833188

3184-
ExecOpenIndices(partrelinfo, false);
3185-
31863189
/* DELETE old tuple found in the old partition. */
31873190
EvalPlanQualSetSlot(&epqstate, localslot);
31883191
TargetPrivilegesCheck(partrelinfo->ri_RelationDesc, ACL_DELETE);
@@ -3217,7 +3220,6 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
32173220
remoteslot_part);
32183221
}
32193222

3220-
ExecCloseIndices(partrelinfo);
32213223
EvalPlanQualEnd(&epqstate);
32223224
}
32233225
break;

0 commit comments

Comments
 (0)