PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
conflict.h File Reference
#include "access/xlogdefs.h"
#include "nodes/pg_list.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 EState EState
 
typedef struct ResultRelInfo ResultRelInfo
 
typedef struct TupleTableSlot TupleTableSlot
 
typedef struct ConflictTupleInfo ConflictTupleInfo
 

Enumerations

enum  ConflictType {
  CT_INSERT_EXISTS , CT_UPDATE_ORIGIN_DIFFERS , CT_UPDATE_EXISTS , CT_UPDATE_DELETED ,
  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 64 of file conflict.h.

Typedef Documentation

◆ ConflictTupleInfo

◆ EState

typedef struct EState EState

Definition at line 17 of file conflict.h.

◆ ResultRelInfo

typedef struct ResultRelInfo ResultRelInfo

Definition at line 18 of file conflict.h.

◆ TupleTableSlot

Definition at line 19 of file conflict.h.

Enumeration Type Documentation

◆ ConflictType

Enumerator
CT_INSERT_EXISTS 
CT_UPDATE_ORIGIN_DIFFERS 
CT_UPDATE_EXISTS 
CT_UPDATE_DELETED 
CT_UPDATE_MISSING 
CT_DELETE_ORIGIN_DIFFERS 
CT_DELETE_MISSING 
CT_MULTIPLE_UNIQUE_CONFLICTS 

Definition at line 31 of file conflict.h.

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

Function Documentation

◆ GetTupleTransactionInfo()

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

Definition at line 63 of file conflict.c.

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

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 139 of file conflict.c.

140{
141 List *uniqueIndexes = NIL;
142
143 for (int i = 0; i < relInfo->ri_NumIndices; i++)
144 {
145 Relation indexRelation = relInfo->ri_IndexRelationDescs[i];
146
147 if (indexRelation == NULL)
148 continue;
149
150 /* Detect conflict only for unique indexes */
151 if (!relInfo->ri_IndexRelationInfo[i]->ii_Unique)
152 continue;
153
154 /* Don't support conflict detection for deferrable index */
155 if (!indexRelation->rd_index->indimmediate)
156 continue;
157
158 uniqueIndexes = lappend_oid(uniqueIndexes,
159 RelationGetRelid(indexRelation));
160 }
161
162 relInfo->ri_onConflictArbiterIndexes = uniqueIndexes;
163}
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:514
bool ii_Unique
Definition: execnodes.h:200
Definition: pg_list.h:54
Form_pg_index rd_index
Definition: rel.h:192
int ri_NumIndices
Definition: execnodes.h:483
List * ri_onConflictArbiterIndexes
Definition: execnodes.h:580
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:486
IndexInfo ** ri_IndexRelationInfo
Definition: execnodes.h:489

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 104 of file conflict.c.

107{
108 Relation localrel = relinfo->ri_RelationDesc;
109 StringInfoData err_detail;
110
111 initStringInfo(&err_detail);
112
113 /* Form errdetail message by combining conflicting tuples information. */
114 foreach_ptr(ConflictTupleInfo, conflicttuple, conflicttuples)
115 errdetail_apply_conflict(estate, relinfo, type, searchslot,
116 conflicttuple->slot, remoteslot,
117 conflicttuple->indexoid,
118 conflicttuple->xmin,
119 conflicttuple->origin,
120 conflicttuple->ts,
121 &err_detail);
122
124
125 ereport(elevel,
127 errmsg("conflict detected on relation \"%s.%s\": conflict=%s",
129 RelationGetRelationName(localrel),
131 errdetail_internal("%s", err_detail.data));
132}
Subscription * MySubscription
Definition: worker.c:479
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:200
static const char *const ConflictTypeNames[]
Definition: conflict.c:26
static int errcode_apply_conflict(ConflictType type)
Definition: conflict.c:169
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1234
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereport(elevel,...)
Definition: elog.h:150
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3533
#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:548
#define RelationGetNamespace(relation)
Definition: rel.h:555
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
Relation ri_RelationDesc
Definition: execnodes.h:480
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().