Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8653f4

Browse files
committed
Refactor code to look up local replication tuple
This unifies some duplicate code.Author: Amit Langote <amitlangote09@gmail.com>Discussion:https://www.postgresql.org/message-id/CA+HiwqFjYE5anArxvkjr37AQMd52L-LZtz9Ld2QrLQ3YfcYhTw@mail.gmail.com
1 parent3696234 commitd8653f4

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

‎src/backend/replication/logical/worker.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ static void apply_handle_update_internal(ResultRelInfo *relinfo,
122122
staticvoidapply_handle_delete_internal(ResultRelInfo*relinfo,EState*estate,
123123
TupleTableSlot*remoteslot,
124124
LogicalRepRelation*remoterel);
125+
staticboolFindReplTupleInLocalRel(EState*estate,Relationlocalrel,
126+
LogicalRepRelation*remoterel,
127+
TupleTableSlot*remoteslot,
128+
TupleTableSlot**localslot);
125129

126130
/*
127131
* Should this worker apply changes for given relation.
@@ -788,33 +792,17 @@ apply_handle_update_internal(ResultRelInfo *relinfo,
788792
LogicalRepRelMapEntry*relmapentry)
789793
{
790794
Relationlocalrel=relinfo->ri_RelationDesc;
791-
Oididxoid;
792795
EPQStateepqstate;
793796
TupleTableSlot*localslot;
794797
boolfound;
795798
MemoryContextoldctx;
796799

797-
localslot=table_slot_create(localrel,&estate->es_tupleTable);
798800
EvalPlanQualInit(&epqstate,estate,NULL,NIL,-1);
799-
800801
ExecOpenIndices(relinfo, false);
801802

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);
818806
ExecClearTuple(remoteslot);
819807

820808
/*
@@ -922,31 +910,15 @@ apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
922910
LogicalRepRelation*remoterel)
923911
{
924912
Relationlocalrel=relinfo->ri_RelationDesc;
925-
Oididxoid;
926913
EPQStateepqstate;
927914
TupleTableSlot*localslot;
928915
boolfound;
929916

930-
localslot=table_slot_create(localrel,&estate->es_tupleTable);
931917
EvalPlanQualInit(&epqstate,estate,NULL,NIL,-1);
932-
933918
ExecOpenIndices(relinfo, false);
934919

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);
950922

951923
/* If found delete it. */
952924
if (found)
@@ -970,6 +942,39 @@ apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
970942
EvalPlanQualEnd(&epqstate);
971943
}
972944

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+
staticbool
953+
FindReplTupleInLocalRel(EState*estate,Relationlocalrel,
954+
LogicalRepRelation*remoterel,
955+
TupleTableSlot*remoteslot,
956+
TupleTableSlot**localslot)
957+
{
958+
Oididxoid;
959+
boolfound;
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+
returnfound;
976+
}
977+
973978
/*
974979
* Handle TRUNCATE message.
975980
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp