@@ -2991,6 +2991,7 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
2991
2991
ResultRelInfo * partrelinfo_new ;
2992
2992
Relation partrel_new ;
2993
2993
bool found ;
2994
+ EPQState epqstate ;
2994
2995
2995
2996
/* Get the matching local tuple from the partition. */
2996
2997
found = FindReplTupleInLocalRel (edata , partrel ,
@@ -3021,6 +3022,9 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
3021
3022
newtup );
3022
3023
MemoryContextSwitchTo (oldctx );
3023
3024
3025
+ EvalPlanQualInit (& epqstate , estate , NULL , NIL , -1 , NIL );
3026
+ ExecOpenIndices (partrelinfo , false);
3027
+
3024
3028
/*
3025
3029
* Does the updated tuple still satisfy the current
3026
3030
* partition's constraint?
@@ -3036,18 +3040,11 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
3036
3040
* work already done above to find the local tuple in the
3037
3041
* partition.
3038
3042
*/
3039
- EPQState epqstate ;
3040
-
3041
- EvalPlanQualInit (& epqstate , estate , NULL , NIL , -1 , NIL );
3042
- ExecOpenIndices (partrelinfo , false);
3043
-
3044
3043
EvalPlanQualSetSlot (& epqstate , remoteslot_part );
3045
3044
TargetPrivilegesCheck (partrelinfo -> ri_RelationDesc ,
3046
3045
ACL_UPDATE );
3047
3046
ExecSimpleRelationUpdate (partrelinfo , estate , & epqstate ,
3048
3047
localslot , remoteslot_part );
3049
- ExecCloseIndices (partrelinfo );
3050
- EvalPlanQualEnd (& epqstate );
3051
3048
}
3052
3049
else
3053
3050
{
@@ -3091,9 +3088,9 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
3091
3088
RelationGetRelationName (partrel_new ));
3092
3089
3093
3090
/* DELETE old tuple found in the old partition. */
3094
- apply_handle_delete_internal ( edata , partrelinfo ,
3095
- localslot ,
3096
- part_entry -> localindexoid );
3091
+ EvalPlanQualSetSlot ( & epqstate , localslot );
3092
+ TargetPrivilegesCheck ( partrelinfo -> ri_RelationDesc , ACL_DELETE );
3093
+ ExecSimpleRelationDelete ( partrelinfo , estate , & epqstate , localslot );
3097
3094
3098
3095
/* INSERT new tuple into the new partition. */
3099
3096
@@ -3123,6 +3120,9 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
3123
3120
apply_handle_insert_internal (edata , partrelinfo_new ,
3124
3121
remoteslot_part );
3125
3122
}
3123
+
3124
+ ExecCloseIndices (partrelinfo );
3125
+ EvalPlanQualEnd (& epqstate );
3126
3126
}
3127
3127
break ;
3128
3128
0 commit comments