MCPcopy Create free account
hub / github.com/apache/cloudberry / CheckCmdReplicaIdentity

Function CheckCmdReplicaIdentity

src/backend/executor/execReplication.c:567–599  ·  view source on GitHub ↗

* Check if command can be executed with current replica identity. */

Source from the content-addressed store, hash-verified

565 * Check if command can be executed with current replica identity.
566 */
567void
568CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
569{
570 PublicationActions *pubactions;
571
572 /* We only need to do checks for UPDATE and DELETE. */
573 if (cmd != CMD_UPDATE && cmd != CMD_DELETE)
574 return;
575
576 /* If relation has replica identity we are always good. */
577 if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
578 OidIsValid(RelationGetReplicaIndex(rel)))
579 return;
580
581 /*
582 * This is either UPDATE OR DELETE and there is no replica identity.
583 *
584 * Check if the table publishes UPDATES or DELETES.
585 */
586 pubactions = GetRelationPublicationActions(rel);
587 if (cmd == CMD_UPDATE && pubactions->pubupdate)
588 ereport(ERROR,
589 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
590 errmsg("cannot update table \"%s\" because it does not have a replica identity and publishes updates",
591 RelationGetRelationName(rel)),
592 errhint("To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.")));
593 else if (cmd == CMD_DELETE && pubactions->pubdelete)
594 ereport(ERROR,
595 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
596 errmsg("cannot delete from table \"%s\" because it does not have a replica identity and publishes deletes",
597 RelationGetRelationName(rel)),
598 errhint("To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE.")));
599}
600
601
602/*

Callers 4

CheckValidResultRelFunction · 0.85
ExecSimpleRelationInsertFunction · 0.85
ExecSimpleRelationUpdateFunction · 0.85
ExecSimpleRelationDeleteFunction · 0.85

Calls 5

RelationGetReplicaIndexFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected