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_TRANSACTIONID(n)   DatumGetTransactionId(PG_GETARG_DATUM(n))
 
#define PG_RETURN_TRANSACTIONID(x)   return TransactionIdGetDatum(x)
 
#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 29 of file xid.c.

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

◆ PG_GETARG_TRANSACTIONID

#define PG_GETARG_TRANSACTIONID (   n)    DatumGetTransactionId(PG_GETARG_DATUM(n))

Definition at line 26 of file xid.c.

Referenced by mxid_age(), xid_age(), xideq(), xidneq(), xidout(), and xidsend().

◆ PG_RETURN_COMMANDID

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 30 of file xid.c.

Referenced by cidin(), and cidrecv().

◆ PG_RETURN_TRANSACTIONID

#define PG_RETURN_TRANSACTIONID (   x)    return TransactionIdGetDatum(x)

Definition at line 27 of file xid.c.

Referenced by xid8toxid(), xidin(), and xidrecv().

Function Documentation

◆ cideq()

Datum cideq ( PG_FUNCTION_ARGS  )

Definition at line 320 of file xid.c.

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

321 {
322  CommandId arg1 = PG_GETARG_COMMANDID(0);
323  CommandId arg2 = PG_GETARG_COMMANDID(1);
324 
325  PG_RETURN_BOOL(arg1 == arg2);
326 }
uint32 CommandId
Definition: c.h:527
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:29
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ cidin()

Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 274 of file xid.c.

References PG_GETARG_CSTRING, PG_RETURN_COMMANDID, and generate_unaccent_rules::str.

275 {
276  char *str = PG_GETARG_CSTRING(0);
277 
278  PG_RETURN_COMMANDID((CommandId) strtoul(str, NULL, 0));
279 }
uint32 CommandId
Definition: c.h:527
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:30
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 285 of file xid.c.

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

286 {
288  char *result = (char *) palloc(16);
289 
290  snprintf(result, 16, "%lu", (unsigned long) c);
291  PG_RETURN_CSTRING(result);
292 }
uint32 CommandId
Definition: c.h:527
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:29
char * c
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:949
#define snprintf
Definition: port.h:193

◆ cidrecv()

Datum cidrecv ( PG_FUNCTION_ARGS  )

Definition at line 298 of file xid.c.

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

299 {
301 
303 }
uint32 CommandId
Definition: c.h:527
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:30
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ cidsend()

Datum cidsend ( PG_FUNCTION_ARGS  )

Definition at line 309 of file xid.c.

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

310 {
311  CommandId arg1 = PG_GETARG_COMMANDID(0);
313 
314  pq_begintypsend(&buf);
315  pq_sendint32(&buf, arg1);
317 }
uint32 CommandId
Definition: c.h:527
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:29
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
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:67

◆ mxid_age()

Datum mxid_age ( PG_FUNCTION_ARGS  )

Definition at line 120 of file xid.c.

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

121 {
124 
125  if (!MultiXactIdIsValid(xid))
126  PG_RETURN_INT32(INT_MAX);
127 
128  PG_RETURN_INT32((int32) (now - xid));
129 }
uint32 TransactionId
Definition: c.h:513
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
signed int int32
Definition: c.h:355
#define MultiXactIdIsValid(multi)
Definition: multixact.h:27
TransactionId MultiXactId
Definition: c.h:523
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:26
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1538
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:723

◆ xid8cmp()

Datum xid8cmp ( PG_FUNCTION_ARGS  )

Definition at line 253 of file xid.c.

References FullTransactionIdEquals, FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_INT32.

254 {
257 
258  if (FullTransactionIdFollows(fxid1, fxid2))
259  PG_RETURN_INT32(1);
260  else if (FullTransactionIdEquals(fxid1, fxid2))
261  PG_RETURN_INT32(0);
262  else
263  PG_RETURN_INT32(-1);
264 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#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 199 of file xid.c.

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

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

◆ xid8ge()

Datum xid8ge ( PG_FUNCTION_ARGS  )

Definition at line 244 of file xid.c.

References FullTransactionIdFollowsOrEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

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

◆ xid8gt()

Datum xid8gt ( PG_FUNCTION_ARGS  )

Definition at line 226 of file xid.c.

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

227 {
230 
232 }
#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:358

◆ xid8in()

Datum xid8in ( PG_FUNCTION_ARGS  )

Definition at line 160 of file xid.c.

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

161 {
162  char *str = PG_GETARG_CSTRING(0);
163 
165 }
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:20
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:79
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 235 of file xid.c.

References FullTransactionIdPrecedesOrEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

236 {
239 
241 }
#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:358

◆ xid8lt()

Datum xid8lt ( PG_FUNCTION_ARGS  )

Definition at line 217 of file xid.c.

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

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

◆ xid8ne()

Datum xid8ne ( PG_FUNCTION_ARGS  )

Definition at line 208 of file xid.c.

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

209 {
212 
213  PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2));
214 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50

◆ xid8out()

Datum xid8out ( PG_FUNCTION_ARGS  )

Definition at line 168 of file xid.c.

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

169 {
171  char *result = (char *) palloc(21);
172 
173  snprintf(result, 21, UINT64_FORMAT, U64FromFullTransactionId(fxid));
174  PG_RETURN_CSTRING(result);
175 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define U64FromFullTransactionId(x)
Definition: transam.h:49
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:949
#define snprintf
Definition: port.h:193
#define UINT64_FORMAT
Definition: c.h:410

◆ xid8recv()

Datum xid8recv ( PG_FUNCTION_ARGS  )

Definition at line 178 of file xid.c.

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

179 {
181  uint64 value;
182 
183  value = (uint64) pq_getmsgint64(buf);
185 }
#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:79
static char * buf
Definition: pg_test_fsync.c:67
static struct @143 value
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ xid8send()

Datum xid8send ( PG_FUNCTION_ARGS  )

Definition at line 188 of file xid.c.

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

189 {
192 
193  pq_begintypsend(&buf);
194  pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1));
196 }
#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:369
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:67
#define U64FromFullTransactionId(x)
Definition: transam.h:49

◆ xid8toxid()

Datum xid8toxid ( PG_FUNCTION_ARGS  )

Definition at line 152 of file xid.c.

References PG_GETARG_FULLTRANSACTIONID, PG_RETURN_TRANSACTIONID, and XidFromFullTransactionId.

153 {
155 
157 }
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:19
#define XidFromFullTransactionId(x)
Definition: transam.h:48
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:27

◆ xid_age()

Datum xid_age ( PG_FUNCTION_ARGS  )

Definition at line 104 of file xid.c.

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

105 {
108 
109  /* Permanent XIDs are always infinitely old */
110  if (!TransactionIdIsNormal(xid))
111  PG_RETURN_INT32(INT_MAX);
112 
113  PG_RETURN_INT32((int32) (now - xid));
114 }
uint32 TransactionId
Definition: c.h:513
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
signed int int32
Definition: c.h:355
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:526
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:26
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1538

◆ xidComparator()

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

Definition at line 139 of file xid.c.

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

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

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 80 of file xid.c.

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

81 {
84 
86 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:513
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:26

◆ xidin()

Datum xidin ( PG_FUNCTION_ARGS  )

Definition at line 34 of file xid.c.

References PG_GETARG_CSTRING, PG_RETURN_TRANSACTIONID, and generate_unaccent_rules::str.

35 {
36  char *str = PG_GETARG_CSTRING(0);
37 
38  PG_RETURN_TRANSACTIONID((TransactionId) strtoul(str, NULL, 0));
39 }
uint32 TransactionId
Definition: c.h:513
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:27

◆ xidneq()

Datum xidneq ( PG_FUNCTION_ARGS  )

Definition at line 92 of file xid.c.

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

93 {
96 
97  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
98 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:513
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:26

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 42 of file xid.c.

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

43 {
44  TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
45  char *result = (char *) palloc(16);
46 
47  snprintf(result, 16, "%lu", (unsigned long) transactionId);
48  PG_RETURN_CSTRING(result);
49 }
uint32 TransactionId
Definition: c.h:513
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:26
#define snprintf
Definition: port.h:193

◆ xidrecv()

Datum xidrecv ( PG_FUNCTION_ARGS  )

Definition at line 55 of file xid.c.

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

56 {
58 
60 }
uint32 TransactionId
Definition: c.h:513
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:27

◆ xidsend()

Datum xidsend ( PG_FUNCTION_ARGS  )

Definition at line 66 of file xid.c.

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

67 {
70 
71  pq_begintypsend(&buf);
72  pq_sendint32(&buf, arg1);
74 }
uint32 TransactionId
Definition: c.h:513
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
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:67
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:26