PostgreSQL Source Code git master
Loading...
Searching...
No Matches
conflict.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * conflict.h
3 * Exports for conflicts logging.
4 *
5 * Copyright (c) 2024-2026, PostgreSQL Global Development Group
6 *
7 *-------------------------------------------------------------------------
8 */
9#ifndef CONFLICT_H
10#define CONFLICT_H
11
12#include "access/xlogdefs.h"
13#include "datatype/timestamp.h"
14#include "nodes/pg_list.h"
15
16/* Avoid including execnodes.h here */
17typedef struct EState EState;
20
21
22/*
23 * Conflict types that could occur while applying remote changes.
24 *
25 * This enum is used in statistics collection (see
26 * PgStat_StatSubEntry::conflict_count and
27 * PgStat_BackendSubEntry::conflict_count) as well, therefore, when adding new
28 * values or reordering existing ones, ensure to review and potentially adjust
29 * the corresponding statistics collection codes.
30 */
31typedef enum
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 */
63
64#define CONFLICT_NUM_TYPES (CT_MULTIPLE_UNIQUE_CONFLICTS + 1)
65
66/*
67 * Information for the local row that caused the conflict.
68 */
69typedef struct ConflictTupleInfo
70{
71 TupleTableSlot *slot; /* tuple slot holding the conflicting local
72 * tuple */
73 Oid indexoid; /* OID of the index where the conflict
74 * occurred */
75 TransactionId xmin; /* transaction ID of the modification causing
76 * the conflict */
77 ReplOriginId origin; /* origin identifier of the modification */
78 TimestampTz ts; /* timestamp of when the modification on the
79 * conflicting local row occurred */
81
82/*
83 * Defines where logical replication conflict details are recorded.
84 *
85 * While stored as a text-based array/string in
86 * pg_subscription.subconflictlogdest for user readability and extensibility,
87 * we map these to an internal enum to allow for efficient checks.
88 */
89typedef enum ConflictLogDest
90{
91 CONFLICT_LOG_DEST_LOG = 0, /* Emit to server logs */
92 CONFLICT_LOG_DEST_TABLE, /* Insert into the conflict log table */
93 CONFLICT_LOG_DEST_ALL /* Both log and table */
95
96#define CONFLICTS_LOGGED_TO_TABLE(dest) \
97 ((dest == CONFLICT_LOG_DEST_TABLE) || (dest == CONFLICT_LOG_DEST_ALL))
98#define CONFLICTS_LOGGED_TO_LOG(dest) \
99 ((dest == CONFLICT_LOG_DEST_LOG) || (dest == CONFLICT_LOG_DEST_ALL))
100
101/*
102 * Array mapping for converting internal enum to string.
103 */
104extern PGDLLIMPORT const char *const ConflictLogDestNames[];
105
107extern ConflictLogDest GetConflictLogDest(const char *dest);
109 TransactionId *xmin,
112extern void ReportApplyConflict(EState *estate, ResultRelInfo *relinfo,
113 int elevel, ConflictType type,
118#endif
#define PGDLLIMPORT
Definition c.h:1478
uint32 TransactionId
Definition c.h:795
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
bool GetTupleTransactionInfo(TupleTableSlot *localslot, TransactionId *xmin, ReplOriginId *localorigin, TimestampTz *localts)
Definition conflict.c:236
void ReportApplyConflict(EState *estate, ResultRelInfo *relinfo, int elevel, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *remoteslot, List *conflicttuples)
Definition conflict.c:277
ConflictLogDest
Definition conflict.h:90
@ CONFLICT_LOG_DEST_TABLE
Definition conflict.h:92
@ CONFLICT_LOG_DEST_ALL
Definition conflict.h:93
@ CONFLICT_LOG_DEST_LOG
Definition conflict.h:91
void InitConflictIndexes(ResultRelInfo *relInfo)
Definition conflict.c:312
Oid create_conflict_log_table(Oid subid, char *subname, Oid subowner)
Definition conflict.c:147
ConflictLogDest GetConflictLogDest(const char *dest)
Definition conflict.c:210
PGDLLIMPORT const char *const ConflictLogDestNames[]
Definition conflict.c:34
int64 TimestampTz
Definition timestamp.h:39
NameData subname
unsigned int Oid
static int fb(int x)
TimestampTz ts
Definition conflict.h:78
ReplOriginId origin
Definition conflict.h:77
TransactionId xmin
Definition conflict.h:75
TupleTableSlot * slot
Definition conflict.h:71
Definition pg_list.h:54
const char * type
uint16 ReplOriginId
Definition xlogdefs.h:69