PostgreSQL Source Code  git master
xid.c File Reference
#include "postgres.h"
#include <limits.h>
#include "access/multixact.h"
#include "access/transam.h"
#include "access/xact.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
#include "utils/xid8.h"
Include dependency graph for xid.c:

Go to the source code of this file.

Macros

#define PG_GETARG_COMMANDID(n)   DatumGetCommandId(PG_GETARG_DATUM(n))
 
#define PG_RETURN_COMMANDID(x)   return CommandIdGetDatum(x)
 

Functions

Datum xidin (PG_FUNCTION_ARGS)
 
Datum xidout (PG_FUNCTION_ARGS)
 
Datum xidrecv (PG_FUNCTION_ARGS)
 
Datum xidsend (PG_FUNCTION_ARGS)
 
Datum xideq (PG_FUNCTION_ARGS)
 
Datum xidneq (PG_FUNCTION_ARGS)
 
Datum xid_age (PG_FUNCTION_ARGS)
 
Datum mxid_age (PG_FUNCTION_ARGS)
 
int xidComparator (const void *arg1, const void *arg2)
 
Datum xid8toxid (PG_FUNCTION_ARGS)
 
Datum xid8in (PG_FUNCTION_ARGS)
 
Datum xid8out (PG_FUNCTION_ARGS)
 
Datum xid8recv (PG_FUNCTION_ARGS)
 
Datum xid8send (PG_FUNCTION_ARGS)
 
Datum xid8eq (PG_FUNCTION_ARGS)
 
Datum xid8ne (PG_FUNCTION_ARGS)
 
Datum xid8lt (PG_FUNCTION_ARGS)
 
Datum xid8gt (PG_FUNCTION_ARGS)
 
Datum xid8le (PG_FUNCTION_ARGS)
 
Datum xid8ge (PG_FUNCTION_ARGS)
 
Datum xid8cmp (PG_FUNCTION_ARGS)
 
Datum cidin (PG_FUNCTION_ARGS)
 
Datum cidout (PG_FUNCTION_ARGS)
 
Datum cidrecv (PG_FUNCTION_ARGS)
 
Datum cidsend (PG_FUNCTION_ARGS)
 
Datum cideq (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ PG_GETARG_COMMANDID

#define PG_GETARG_COMMANDID (   n)    DatumGetCommandId(PG_GETARG_DATUM(n))

Definition at line 26 of file xid.c.

Referenced by cideq(), cidout(), and cidsend().

◆ PG_RETURN_COMMANDID

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 27 of file xid.c.

Referenced by cidin(), and cidrecv().

Function Documentation

◆ cideq()

Datum cideq ( PG_FUNCTION_ARGS  )

Definition at line 317 of file xid.c.

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

318 {
319  CommandId arg1 = PG_GETARG_COMMANDID(0);
320  CommandId arg2 = PG_GETARG_COMMANDID(1);
321 
322  PG_RETURN_BOOL(arg1 == arg2);
323 }
uint32 CommandId
Definition: c.h:601
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:26
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ cidin()

Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 271 of file xid.c.

References PG_GETARG_CSTRING, PG_RETURN_COMMANDID, and generate_unaccent_rules::str.

272 {
273  char *str = PG_GETARG_CSTRING(0);
274 
275  PG_RETURN_COMMANDID((CommandId) strtoul(str, NULL, 0));
276 }
uint32 CommandId
Definition: c.h:601
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:27
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 282 of file xid.c.

References palloc(), PG_GETARG_COMMANDID, PG_RETURN_CSTRING, and snprintf.

283 {
285  char *result = (char *) palloc(16);
286 
287  snprintf(result, 16, "%lu", (unsigned long) c);
288  PG_RETURN_CSTRING(result);
289 }
uint32 CommandId
Definition: c.h:601
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:26
char * c
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1062
#define snprintf
Definition: port.h:216

◆ cidrecv()

Datum cidrecv ( PG_FUNCTION_ARGS  )

Definition at line 295 of file xid.c.

References buf, PG_GETARG_POINTER, PG_RETURN_COMMANDID, and pq_getmsgint().

296 {
298 
300 }
uint32 CommandId
Definition: c.h:601
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:27
static char * buf
Definition: pg_test_fsync.c:68
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ cidsend()

Datum cidsend ( PG_FUNCTION_ARGS  )

Definition at line 306 of file xid.c.

References buf, PG_GETARG_COMMANDID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

307 {
308  CommandId arg1 = PG_GETARG_COMMANDID(0);
310 
311  pq_begintypsend(&buf);
312  pq_sendint32(&buf, arg1);
314 }
uint32 CommandId
Definition: c.h:601
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:26
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:68

◆ mxid_age()

Datum mxid_age ( PG_FUNCTION_ARGS  )

Definition at line 117 of file xid.c.

References MultiXactIdIsValid, now(), PG_GETARG_TRANSACTIONID, PG_RETURN_INT32, and ReadNextMultiXactId().

118 {
121 
122  if (!MultiXactIdIsValid(xid))
123  PG_RETURN_INT32(INT_MAX);
124 
125  PG_RETURN_INT32((int32) (now - xid));
126 }
uint32 TransactionId
Definition: c.h:587
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
signed int int32
Definition: c.h:429
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
#define MultiXactIdIsValid(multi)
Definition: multixact.h:28
TransactionId MultiXactId
Definition: c.h:597
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1544
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:723

◆ xid8cmp()

Datum xid8cmp ( PG_FUNCTION_ARGS  )

Definition at line 250 of file xid.c.

References FullTransactionIdEquals, FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_INT32.

251 {
254 
255  if (FullTransactionIdFollows(fxid1, fxid2))
256  PG_RETURN_INT32(1);
257  else if (FullTransactionIdEquals(fxid1, fxid2))
258  PG_RETURN_INT32(0);
259  else
260  PG_RETURN_INT32(-1);
261 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define FullTransactionIdFollows(a, b)
Definition: transam.h:53
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50

◆ xid8eq()

Datum xid8eq ( PG_FUNCTION_ARGS  )

Definition at line 196 of file xid.c.

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

197 {
200 
202 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50

◆ xid8ge()

Datum xid8ge ( PG_FUNCTION_ARGS  )

Definition at line 241 of file xid.c.

References FullTransactionIdFollowsOrEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

242 {
245 
247 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define FullTransactionIdFollowsOrEquals(a, b)
Definition: transam.h:54

◆ xid8gt()

Datum xid8gt ( PG_FUNCTION_ARGS  )

Definition at line 223 of file xid.c.

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

224 {
227 
229 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define FullTransactionIdFollows(a, b)
Definition: transam.h:53
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ xid8in()

Datum xid8in ( PG_FUNCTION_ARGS  )

Definition at line 157 of file xid.c.

References FullTransactionIdFromU64(), PG_GETARG_CSTRING, PG_RETURN_FULLTRANSACTIONID, pg_strtouint64(), and generate_unaccent_rules::str.

158 {
159  char *str = PG_GETARG_CSTRING(0);
160 
162 }
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:20
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81
uint64 pg_strtouint64(const char *str, char **endptr, int base)
Definition: numutils.c:621
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

◆ xid8le()

Datum xid8le ( PG_FUNCTION_ARGS  )

Definition at line 232 of file xid.c.

References FullTransactionIdPrecedesOrEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

233 {
236 
238 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define FullTransactionIdPrecedesOrEquals(a, b)
Definition: transam.h:52
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ xid8lt()

Datum xid8lt ( PG_FUNCTION_ARGS  )

Definition at line 214 of file xid.c.

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

215 {
218 
220 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define FullTransactionIdPrecedes(a, b)
Definition: transam.h:51

◆ xid8ne()

Datum xid8ne ( PG_FUNCTION_ARGS  )

Definition at line 205 of file xid.c.

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

206 {
209 
210  PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2));
211 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50

◆ xid8out()

Datum xid8out ( PG_FUNCTION_ARGS  )

Definition at line 165 of file xid.c.

References palloc(), PG_GETARG_FULLTRANSACTIONID, PG_RETURN_CSTRING, snprintf, U64FromFullTransactionId, and UINT64_FORMAT.

166 {
168  char *result = (char *) palloc(21);
169 
170  snprintf(result, 21, UINT64_FORMAT, U64FromFullTransactionId(fxid));
171  PG_RETURN_CSTRING(result);
172 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define U64FromFullTransactionId(x)
Definition: transam.h:49
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1062
#define snprintf
Definition: port.h:216
#define UINT64_FORMAT
Definition: c.h:484

◆ xid8recv()

Datum xid8recv ( PG_FUNCTION_ARGS  )

Definition at line 175 of file xid.c.

References buf, FullTransactionIdFromU64(), PG_GETARG_POINTER, PG_RETURN_FULLTRANSACTIONID, pq_getmsgint64(), and value.

176 {
178  uint64 value;
179 
180  value = (uint64) pq_getmsgint64(buf);
182 }
static struct @142 value
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:20
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81
static char * buf
Definition: pg_test_fsync.c:68
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ xid8send()

Datum xid8send ( PG_FUNCTION_ARGS  )

Definition at line 185 of file xid.c.

References buf, PG_GETARG_FULLTRANSACTIONID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint64(), and U64FromFullTransactionId.

186 {
189 
190  pq_begintypsend(&buf);
191  pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1));
193 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:68
#define U64FromFullTransactionId(x)
Definition: transam.h:49

◆ xid8toxid()

Datum xid8toxid ( PG_FUNCTION_ARGS  )

Definition at line 149 of file xid.c.

References PG_GETARG_FULLTRANSACTIONID, PG_RETURN_TRANSACTIONID, and XidFromFullTransactionId.

150 {
152 
154 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_TRANSACTIONID(x)
Definition: fmgr.h:364
#define XidFromFullTransactionId(x)
Definition: transam.h:48

◆ xid_age()

Datum xid_age ( PG_FUNCTION_ARGS  )

Definition at line 101 of file xid.c.

References GetStableLatestTransactionId(), now(), PG_GETARG_TRANSACTIONID, PG_RETURN_INT32, and TransactionIdIsNormal.

102 {
105 
106  /* Permanent XIDs are always infinitely old */
107  if (!TransactionIdIsNormal(xid))
108  PG_RETURN_INT32(INT_MAX);
109 
110  PG_RETURN_INT32((int32) (now - xid));
111 }
uint32 TransactionId
Definition: c.h:587
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
signed int int32
Definition: c.h:429
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:541
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1544

◆ xidComparator()

int xidComparator ( const void *  arg1,
const void *  arg2 
)

Definition at line 136 of file xid.c.

Referenced by ProcArrayApplyRecoveryInfo(), ReorderBufferCopySnap(), SerializeTransactionState(), SnapBuildBuildSnapshot(), SnapBuildInitialSnapshot(), and TransactionIdInArray().

137 {
138  TransactionId xid1 = *(const TransactionId *) arg1;
139  TransactionId xid2 = *(const TransactionId *) arg2;
140 
141  if (xid1 > xid2)
142  return 1;
143  if (xid1 < xid2)
144  return -1;
145  return 0;
146 }
uint32 TransactionId
Definition: c.h:587

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 77 of file xid.c.

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

78 {
81 
83 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:587
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ xidin()

Datum xidin ( PG_FUNCTION_ARGS  )

Definition at line 31 of file xid.c.

References PG_GETARG_CSTRING, PG_RETURN_TRANSACTIONID, and generate_unaccent_rules::str.

32 {
33  char *str = PG_GETARG_CSTRING(0);
34 
35  PG_RETURN_TRANSACTIONID((TransactionId) strtoul(str, NULL, 0));
36 }
uint32 TransactionId
Definition: c.h:587
#define PG_RETURN_TRANSACTIONID(x)
Definition: fmgr.h:364
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

◆ xidneq()

Datum xidneq ( PG_FUNCTION_ARGS  )

Definition at line 89 of file xid.c.

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

90 {
93 
94  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
95 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:587
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 39 of file xid.c.

References palloc(), PG_GETARG_TRANSACTIONID, PG_RETURN_CSTRING, and snprintf.

40 {
41  TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
42  char *result = (char *) palloc(16);
43 
44  snprintf(result, 16, "%lu", (unsigned long) transactionId);
45  PG_RETURN_CSTRING(result);
46 }
uint32 TransactionId
Definition: c.h:587
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1062
#define snprintf
Definition: port.h:216

◆ xidrecv()

Datum xidrecv ( PG_FUNCTION_ARGS  )

Definition at line 52 of file xid.c.

References buf, PG_GETARG_POINTER, PG_RETURN_TRANSACTIONID, and pq_getmsgint().

53 {
55 
57 }
uint32 TransactionId
Definition: c.h:587
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_RETURN_TRANSACTIONID(x)
Definition: fmgr.h:364
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:68
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ xidsend()

Datum xidsend ( PG_FUNCTION_ARGS  )

Definition at line 63 of file xid.c.

References buf, PG_GETARG_TRANSACTIONID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

64 {
67 
68  pq_begintypsend(&buf);
69  pq_sendint32(&buf, arg1);
71 }
uint32 TransactionId
Definition: c.h:587
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
static char * buf
Definition: pg_test_fsync.c:68