PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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

Definition at line 17 of file conflict.h.

◆ ResultRelInfo

Definition at line 18 of file conflict.h.

◆ TupleTableSlot

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 
)
extern

Definition at line 63 of file conflict.c.

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

References Assert, DatumGetTransactionId(), fb(), 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)
extern

Definition at line 139 of file conflict.c.

140{
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
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
Definition pg_list.h:54
Form_pg_index rd_index
Definition rel.h:192

References fb(), i, lappend_oid(), NIL, RelationData::rd_index, and RelationGetRelid.

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 
)
extern

Definition at line 104 of file conflict.c.

107{
108 Relation localrel = relinfo->ri_RelationDesc;
110
112
113 /* Form errdetail message by combining conflicting tuples information. */
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:252
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:1243
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516
#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
const char * type

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

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