@@ -122,6 +122,10 @@ static void apply_handle_update_internal(ResultRelInfo *relinfo,
122
122
static void apply_handle_delete_internal (ResultRelInfo * relinfo , EState * estate ,
123
123
TupleTableSlot * remoteslot ,
124
124
LogicalRepRelation * remoterel );
125
+ static bool FindReplTupleInLocalRel (EState * estate , Relation localrel ,
126
+ LogicalRepRelation * remoterel ,
127
+ TupleTableSlot * remoteslot ,
128
+ TupleTableSlot * * localslot );
125
129
126
130
/*
127
131
* Should this worker apply changes for given relation.
@@ -788,33 +792,17 @@ apply_handle_update_internal(ResultRelInfo *relinfo,
788
792
LogicalRepRelMapEntry * relmapentry )
789
793
{
790
794
Relation localrel = relinfo -> ri_RelationDesc ;
791
- Oid idxoid ;
792
795
EPQState epqstate ;
793
796
TupleTableSlot * localslot ;
794
797
bool found ;
795
798
MemoryContext oldctx ;
796
799
797
- localslot = table_slot_create (localrel , & estate -> es_tupleTable );
798
800
EvalPlanQualInit (& epqstate , estate , NULL , NIL , -1 );
799
-
800
801
ExecOpenIndices (relinfo , false);
801
802
802
- /*
803
- * Try to find tuple using either replica identity index, primary key or
804
- * if needed, sequential scan.
805
- */
806
- idxoid = GetRelationIdentityOrPK (localrel );
807
- Assert (OidIsValid (idxoid ) ||
808
- (relmapentry -> remoterel .replident == REPLICA_IDENTITY_FULL ));
809
-
810
- if (OidIsValid (idxoid ))
811
- found = RelationFindReplTupleByIndex (localrel , idxoid ,
812
- LockTupleExclusive ,
813
- remoteslot , localslot );
814
- else
815
- found = RelationFindReplTupleSeq (localrel , LockTupleExclusive ,
816
- remoteslot , localslot );
817
-
803
+ found = FindReplTupleInLocalRel (estate , localrel ,
804
+ & relmapentry -> remoterel ,
805
+ remoteslot , & localslot );
818
806
ExecClearTuple (remoteslot );
819
807
820
808
/*
@@ -922,31 +910,15 @@ apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
922
910
LogicalRepRelation * remoterel )
923
911
{
924
912
Relation localrel = relinfo -> ri_RelationDesc ;
925
- Oid idxoid ;
926
913
EPQState epqstate ;
927
914
TupleTableSlot * localslot ;
928
915
bool found ;
929
916
930
- localslot = table_slot_create (localrel , & estate -> es_tupleTable );
931
917
EvalPlanQualInit (& epqstate , estate , NULL , NIL , -1 );
932
-
933
918
ExecOpenIndices (relinfo , false);
934
919
935
- /*
936
- * Try to find tuple using either replica identity index, primary key or
937
- * if needed, sequential scan.
938
- */
939
- idxoid = GetRelationIdentityOrPK (localrel );
940
- Assert (OidIsValid (idxoid ) ||
941
- (remoterel -> replident == REPLICA_IDENTITY_FULL ));
942
-
943
- if (OidIsValid (idxoid ))
944
- found = RelationFindReplTupleByIndex (localrel , idxoid ,
945
- LockTupleExclusive ,
946
- remoteslot , localslot );
947
- else
948
- found = RelationFindReplTupleSeq (localrel , LockTupleExclusive ,
949
- remoteslot , localslot );
920
+ found = FindReplTupleInLocalRel (estate , localrel , remoterel ,
921
+ remoteslot , & localslot );
950
922
951
923
/* If found delete it. */
952
924
if (found )
@@ -970,6 +942,39 @@ apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
970
942
EvalPlanQualEnd (& epqstate );
971
943
}
972
944
945
+ /*
946
+ * Try to find a tuple received from the publication side (in 'remoteslot') in
947
+ * the corresponding local relation using either replica identity index,
948
+ * primary key or if needed, sequential scan.
949
+ *
950
+ * Local tuple, if found, is returned in '*localslot'.
951
+ */
952
+ static bool
953
+ FindReplTupleInLocalRel (EState * estate , Relation localrel ,
954
+ LogicalRepRelation * remoterel ,
955
+ TupleTableSlot * remoteslot ,
956
+ TupleTableSlot * * localslot )
957
+ {
958
+ Oid idxoid ;
959
+ bool found ;
960
+
961
+ * localslot = table_slot_create (localrel , & estate -> es_tupleTable );
962
+
963
+ idxoid = GetRelationIdentityOrPK (localrel );
964
+ Assert (OidIsValid (idxoid ) ||
965
+ (remoterel -> replident == REPLICA_IDENTITY_FULL ));
966
+
967
+ if (OidIsValid (idxoid ))
968
+ found = RelationFindReplTupleByIndex (localrel , idxoid ,
969
+ LockTupleExclusive ,
970
+ remoteslot , * localslot );
971
+ else
972
+ found = RelationFindReplTupleSeq (localrel , LockTupleExclusive ,
973
+ remoteslot , * localslot );
974
+
975
+ return found ;
976
+ }
977
+
973
978
/*
974
979
* Handle TRUNCATE message.
975
980
*
0 commit comments