mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
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
This commit is contained in:
@ -122,6 +122,10 @@ static void apply_handle_update_internal(ResultRelInfo *relinfo,
|
|||||||
static void apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
|
static void apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
|
||||||
TupleTableSlot *remoteslot,
|
TupleTableSlot *remoteslot,
|
||||||
LogicalRepRelation *remoterel);
|
LogicalRepRelation *remoterel);
|
||||||
|
static bool FindReplTupleInLocalRel(EState *estate, Relation localrel,
|
||||||
|
LogicalRepRelation *remoterel,
|
||||||
|
TupleTableSlot *remoteslot,
|
||||||
|
TupleTableSlot **localslot);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Should this worker apply changes for given relation.
|
* Should this worker apply changes for given relation.
|
||||||
@ -788,33 +792,17 @@ apply_handle_update_internal(ResultRelInfo *relinfo,
|
|||||||
LogicalRepRelMapEntry *relmapentry)
|
LogicalRepRelMapEntry *relmapentry)
|
||||||
{
|
{
|
||||||
Relation localrel = relinfo->ri_RelationDesc;
|
Relation localrel = relinfo->ri_RelationDesc;
|
||||||
Oid idxoid;
|
|
||||||
EPQState epqstate;
|
EPQState epqstate;
|
||||||
TupleTableSlot *localslot;
|
TupleTableSlot *localslot;
|
||||||
bool found;
|
bool found;
|
||||||
MemoryContext oldctx;
|
MemoryContext oldctx;
|
||||||
|
|
||||||
localslot = table_slot_create(localrel, &estate->es_tupleTable);
|
|
||||||
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1);
|
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1);
|
||||||
|
|
||||||
ExecOpenIndices(relinfo, false);
|
ExecOpenIndices(relinfo, false);
|
||||||
|
|
||||||
/*
|
found = FindReplTupleInLocalRel(estate, localrel,
|
||||||
* Try to find tuple using either replica identity index, primary key or
|
&relmapentry->remoterel,
|
||||||
* if needed, sequential scan.
|
remoteslot, &localslot);
|
||||||
*/
|
|
||||||
idxoid = GetRelationIdentityOrPK(localrel);
|
|
||||||
Assert(OidIsValid(idxoid) ||
|
|
||||||
(relmapentry->remoterel.replident == REPLICA_IDENTITY_FULL));
|
|
||||||
|
|
||||||
if (OidIsValid(idxoid))
|
|
||||||
found = RelationFindReplTupleByIndex(localrel, idxoid,
|
|
||||||
LockTupleExclusive,
|
|
||||||
remoteslot, localslot);
|
|
||||||
else
|
|
||||||
found = RelationFindReplTupleSeq(localrel, LockTupleExclusive,
|
|
||||||
remoteslot, localslot);
|
|
||||||
|
|
||||||
ExecClearTuple(remoteslot);
|
ExecClearTuple(remoteslot);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -922,31 +910,15 @@ apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
|
|||||||
LogicalRepRelation *remoterel)
|
LogicalRepRelation *remoterel)
|
||||||
{
|
{
|
||||||
Relation localrel = relinfo->ri_RelationDesc;
|
Relation localrel = relinfo->ri_RelationDesc;
|
||||||
Oid idxoid;
|
|
||||||
EPQState epqstate;
|
EPQState epqstate;
|
||||||
TupleTableSlot *localslot;
|
TupleTableSlot *localslot;
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
localslot = table_slot_create(localrel, &estate->es_tupleTable);
|
|
||||||
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1);
|
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1);
|
||||||
|
|
||||||
ExecOpenIndices(relinfo, false);
|
ExecOpenIndices(relinfo, false);
|
||||||
|
|
||||||
/*
|
found = FindReplTupleInLocalRel(estate, localrel, remoterel,
|
||||||
* Try to find tuple using either replica identity index, primary key or
|
remoteslot, &localslot);
|
||||||
* if needed, sequential scan.
|
|
||||||
*/
|
|
||||||
idxoid = GetRelationIdentityOrPK(localrel);
|
|
||||||
Assert(OidIsValid(idxoid) ||
|
|
||||||
(remoterel->replident == REPLICA_IDENTITY_FULL));
|
|
||||||
|
|
||||||
if (OidIsValid(idxoid))
|
|
||||||
found = RelationFindReplTupleByIndex(localrel, idxoid,
|
|
||||||
LockTupleExclusive,
|
|
||||||
remoteslot, localslot);
|
|
||||||
else
|
|
||||||
found = RelationFindReplTupleSeq(localrel, LockTupleExclusive,
|
|
||||||
remoteslot, localslot);
|
|
||||||
|
|
||||||
/* If found delete it. */
|
/* If found delete it. */
|
||||||
if (found)
|
if (found)
|
||||||
@ -970,6 +942,39 @@ apply_handle_delete_internal(ResultRelInfo *relinfo, EState *estate,
|
|||||||
EvalPlanQualEnd(&epqstate);
|
EvalPlanQualEnd(&epqstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to find a tuple received from the publication side (in 'remoteslot') in
|
||||||
|
* the corresponding local relation using either replica identity index,
|
||||||
|
* primary key or if needed, sequential scan.
|
||||||
|
*
|
||||||
|
* Local tuple, if found, is returned in '*localslot'.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
FindReplTupleInLocalRel(EState *estate, Relation localrel,
|
||||||
|
LogicalRepRelation *remoterel,
|
||||||
|
TupleTableSlot *remoteslot,
|
||||||
|
TupleTableSlot **localslot)
|
||||||
|
{
|
||||||
|
Oid idxoid;
|
||||||
|
bool found;
|
||||||
|
|
||||||
|
*localslot = table_slot_create(localrel, &estate->es_tupleTable);
|
||||||
|
|
||||||
|
idxoid = GetRelationIdentityOrPK(localrel);
|
||||||
|
Assert(OidIsValid(idxoid) ||
|
||||||
|
(remoterel->replident == REPLICA_IDENTITY_FULL));
|
||||||
|
|
||||||
|
if (OidIsValid(idxoid))
|
||||||
|
found = RelationFindReplTupleByIndex(localrel, idxoid,
|
||||||
|
LockTupleExclusive,
|
||||||
|
remoteslot, *localslot);
|
||||||
|
else
|
||||||
|
found = RelationFindReplTupleSeq(localrel, LockTupleExclusive,
|
||||||
|
remoteslot, *localslot);
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle TRUNCATE message.
|
* Handle TRUNCATE message.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user