PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
conflict.h File Reference
#include "nodes/execnodes.h"
#include "utils/timestamp.h"
Include dependency graph for conflict.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ConflictTupleInfo
 

Macros

#define CONFLICT_NUM_TYPES   (CT_MULTIPLE_UNIQUE_CONFLICTS + 1)
 

Typedefs

typedef struct ConflictTupleInfo ConflictTupleInfo
 

Enumerations

enum  ConflictType {
  CT_INSERT_EXISTS , CT_UPDATE_ORIGIN_DIFFERS , CT_UPDATE_EXISTS , CT_UPDATE_MISSING ,
  CT_DELETE_ORIGIN_DIFFERS , CT_DELETE_MISSING , CT_MULTIPLE_UNIQUE_CONFLICTS
}
 

Functions

bool GetTupleTransactionInfo (TupleTableSlot *localslot, TransactionId *xmin, RepOriginId *localorigin, TimestampTz *localts)
 
void ReportApplyConflict (EState *estate, ResultRelInfo *relinfo, int elevel, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *remoteslot, List *conflicttuples)
 
void InitConflictIndexes (ResultRelInfo *relInfo)
 

Macro Definition Documentation

◆ CONFLICT_NUM_TYPES

#define CONFLICT_NUM_TYPES   (CT_MULTIPLE_UNIQUE_CONFLICTS + 1)

Definition at line 54 of file conflict.h.

Typedef Documentation

◆ ConflictTupleInfo

Enumeration Type Documentation

◆ ConflictType

Enumerator
CT_INSERT_EXISTS 
CT_UPDATE_ORIGIN_DIFFERS 
CT_UPDATE_EXISTS 
CT_UPDATE_MISSING 
CT_DELETE_ORIGIN_DIFFERS 
CT_DELETE_MISSING 
CT_MULTIPLE_UNIQUE_CONFLICTS 

Definition at line 24 of file conflict.h.

25{
26 /* The row to be inserted violates unique constraint */
28
29 /* The row to be updated was modified by a different origin */
31
32 /* The updated row value violates unique constraint */
34
35 /* The row to be updated is missing */
37
38 /* The row to be deleted was modified by a different origin */
40
41 /* The row to be deleted is missing */
43
44 /* The row to be inserted/updated violates multiple unique constraint */
46
47 /*
48 * Other conflicts, such as exclusion constraint violations, involve more
49 * complex rules than simple equality checks. These conflicts are left for
50 * future improvements.
51 */
ConflictType
Definition: conflict.h:25
@ CT_MULTIPLE_UNIQUE_CONFLICTS
Definition: conflict.h:45
@ CT_DELETE_MISSING
Definition: conflict.h:42
@ CT_UPDATE_ORIGIN_DIFFERS
Definition: conflict.h:30
@ CT_INSERT_EXISTS
Definition: conflict.h:27
@ CT_UPDATE_EXISTS
Definition: conflict.h:33
@ CT_UPDATE_MISSING
Definition: conflict.h:36
@ CT_DELETE_ORIGIN_DIFFERS
Definition: conflict.h:39

Function Documentation

◆ GetTupleTransactionInfo()

bool GetTupleTransactionInfo ( TupleTableSlot localslot,
TransactionId xmin,
RepOriginId localorigin,
TimestampTz localts 
)

Definition at line 62 of file conflict.c.

64{
65 Datum xminDatum;
66 bool isnull;
67
69 &isnull);
70 *xmin = DatumGetTransactionId(xminDatum);
71 Assert(!isnull);
72
73 /*
74 * The commit timestamp data is not available if track_commit_timestamp is
75 * disabled.
76 */
78 {
79 *localorigin = InvalidRepOriginId;
80 *localts = 0;
81 return false;
82 }
83
84 return TransactionIdGetCommitTsData(*xmin, localts, localorigin);
85}
bool track_commit_timestamp
Definition: commit_ts.c:109
bool TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts, RepOriginId *nodeid)
Definition: commit_ts.c:274
Assert(PointerIsAligned(start, uint64))
#define InvalidRepOriginId
Definition: origin.h:33
uintptr_t Datum
Definition: postgres.h:69
static TransactionId DatumGetTransactionId(Datum X)
Definition: postgres.h:267
#define MinTransactionIdAttributeNumber
Definition: sysattr.h:22
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:420

References Assert(), DatumGetTransactionId(), InvalidRepOriginId, MinTransactionIdAttributeNumber, slot_getsysattr(), track_commit_timestamp, and TransactionIdGetCommitTsData().

Referenced by apply_handle_delete_internal(), apply_handle_tuple_routing(), apply_handle_update_internal(), and CheckAndReportConflict().

◆ InitConflictIndexes()

void InitConflictIndexes ( ResultRelInfo relInfo)

Definition at line 138 of file conflict.c.

139{
140 List *uniqueIndexes = NIL;
141
142 for (int i = 0; i < relInfo->ri_NumIndices; i++)
143 {
144 Relation indexRelation = relInfo->ri_IndexRelationDescs[i];
145
146 if (indexRelation == NULL)
147 continue;
148
149 /* Detect conflict only for unique indexes */
150 if (!relInfo->ri_IndexRelationInfo[i]->ii_Unique)
151 continue;
152
153 /* Don't support conflict detection for deferrable index */
154 if (!indexRelation->rd_index->indimmediate)
155 continue;
156
157 uniqueIndexes = lappend_oid(uniqueIndexes,
158 RelationGetRelid(indexRelation));
159 }
160
161 relInfo->ri_onConflictArbiterIndexes = uniqueIndexes;
162}
int i
Definition: isn.c:77
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
#define NIL
Definition: pg_list.h:68
#define RelationGetRelid(relation)
Definition: rel.h:516
bool ii_Unique
Definition: execnodes.h:209
Definition: pg_list.h:54
Form_pg_index rd_index
Definition: rel.h:192
int ri_NumIndices
Definition: execnodes.h:478
List * ri_onConflictArbiterIndexes
Definition: execnodes.h:575
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:481
IndexInfo ** ri_IndexRelationInfo
Definition: execnodes.h:484

References i, IndexInfo::ii_Unique, lappend_oid(), NIL, RelationData::rd_index, RelationGetRelid, ResultRelInfo::ri_IndexRelationDescs, ResultRelInfo::ri_IndexRelationInfo, ResultRelInfo::ri_NumIndices, and ResultRelInfo::ri_onConflictArbiterIndexes.

Referenced by apply_handle_insert_internal(), apply_handle_tuple_routing(), and apply_handle_update_internal().

◆ ReportApplyConflict()

void ReportApplyConflict ( EState estate,
ResultRelInfo relinfo,
int  elevel,
ConflictType  type,
TupleTableSlot searchslot,
TupleTableSlot remoteslot,
List conflicttuples 
)

Definition at line 103 of file conflict.c.

106{
107 Relation localrel = relinfo->ri_RelationDesc;
108 StringInfoData err_detail;
109
110 initStringInfo(&err_detail);
111
112 /* Form errdetail message by combining conflicting tuples information. */
113 foreach_ptr(ConflictTupleInfo, conflicttuple, conflicttuples)
114 errdetail_apply_conflict(estate, relinfo, type, searchslot,
115 conflicttuple->slot, remoteslot,
116 conflicttuple->indexoid,
117 conflicttuple->xmin,
118 conflicttuple->origin,
119 conflicttuple->ts,
120 &err_detail);
121
123
124 ereport(elevel,
126 errmsg("conflict detected on relation \"%s.%s\": conflict=%s",
128 RelationGetRelationName(localrel),
130 errdetail_internal("%s", err_detail.data));
131}
Subscription * MySubscription
Definition: worker.c:299
static void errdetail_apply_conflict(EState *estate, ResultRelInfo *relinfo, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *localslot, TupleTableSlot *remoteslot, Oid indexoid, TransactionId localxmin, RepOriginId localorigin, TimestampTz localts, StringInfo err_msg)
Definition: conflict.c:198
static const char *const ConflictTypeNames[]
Definition: conflict.c:26
static int errcode_apply_conflict(ConflictType type)
Definition: conflict.c:168
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1231
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereport(elevel,...)
Definition: elog.h:149
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3506
#define foreach_ptr(type, var, lst)
Definition: pg_list.h:469
void pgstat_report_subscription_conflict(Oid subid, ConflictType type)
#define RelationGetRelationName(relation)
Definition: rel.h:550
#define RelationGetNamespace(relation)
Definition: rel.h:557
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
Relation ri_RelationDesc
Definition: execnodes.h:475
const char * type

References ConflictTypeNames, StringInfoData::data, ereport, errcode_apply_conflict(), errdetail_apply_conflict(), errdetail_internal(), errmsg(), foreach_ptr, get_namespace_name(), initStringInfo(), MySubscription, Subscription::oid, pgstat_report_subscription_conflict(), RelationGetNamespace, RelationGetRelationName, ResultRelInfo::ri_RelationDesc, and type.

Referenced by apply_handle_delete_internal(), apply_handle_tuple_routing(), apply_handle_update_internal(), and CheckAndReportConflict().