PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
conflict.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * conflict.h
3 * Exports for conflicts logging.
4 *
5 * Copyright (c) 2024-2025, PostgreSQL Global Development Group
6 *
7 *-------------------------------------------------------------------------
8 */
9#ifndef CONFLICT_H
10#define CONFLICT_H
11
12#include "nodes/execnodes.h"
13#include "utils/timestamp.h"
14
15/*
16 * Conflict types that could occur while applying remote changes.
17 *
18 * This enum is used in statistics collection (see
19 * PgStat_StatSubEntry::conflict_count and
20 * PgStat_BackendSubEntry::conflict_count) as well, therefore, when adding new
21 * values or reordering existing ones, ensure to review and potentially adjust
22 * the corresponding statistics collection codes.
23 */
24typedef enum
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 */
53
54#define CONFLICT_NUM_TYPES (CT_MULTIPLE_UNIQUE_CONFLICTS + 1)
55
56/*
57 * Information for the existing local tuple that caused the conflict.
58 */
59typedef struct ConflictTupleInfo
60{
61 TupleTableSlot *slot; /* tuple slot holding the conflicting local
62 * tuple */
63 Oid indexoid; /* OID of the index where the conflict
64 * occurred */
65 TransactionId xmin; /* transaction ID of the modification causing
66 * the conflict */
67 RepOriginId origin; /* origin identifier of the modification */
68 TimestampTz ts; /* timestamp of when the modification on the
69 * conflicting local tuple occurred */
71
72extern bool GetTupleTransactionInfo(TupleTableSlot *localslot,
73 TransactionId *xmin,
74 RepOriginId *localorigin,
75 TimestampTz *localts);
76extern void ReportApplyConflict(EState *estate, ResultRelInfo *relinfo,
77 int elevel, ConflictType type,
78 TupleTableSlot *searchslot,
79 TupleTableSlot *remoteslot,
80 List *conflicttuples);
81extern void InitConflictIndexes(ResultRelInfo *relInfo);
82#endif
uint32 TransactionId
Definition: c.h:623
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
struct ConflictTupleInfo ConflictTupleInfo
void ReportApplyConflict(EState *estate, ResultRelInfo *relinfo, int elevel, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *remoteslot, List *conflicttuples)
Definition: conflict.c:103
void InitConflictIndexes(ResultRelInfo *relInfo)
Definition: conflict.c:138
bool GetTupleTransactionInfo(TupleTableSlot *localslot, TransactionId *xmin, RepOriginId *localorigin, TimestampTz *localts)
Definition: conflict.c:62
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:30
TimestampTz ts
Definition: conflict.h:68
RepOriginId origin
Definition: conflict.h:67
TransactionId xmin
Definition: conflict.h:65
TupleTableSlot * slot
Definition: conflict.h:61
Definition: pg_list.h:54
const char * type
uint16 RepOriginId
Definition: xlogdefs.h:65