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)
 
int xidLogicalComparator (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 xid8_larger (PG_FUNCTION_ARGS)
 
Datum xid8_smaller (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.

◆ PG_RETURN_COMMANDID

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 27 of file xid.c.

Function Documentation

◆ cideq()

Datum cideq ( PG_FUNCTION_ARGS  )

Definition at line 373 of file xid.c.

374 {
375  CommandId arg1 = PG_GETARG_COMMANDID(0);
376  CommandId arg2 = PG_GETARG_COMMANDID(1);
377 
378  PG_RETURN_BOOL(arg1 == arg2);
379 }
uint32 CommandId
Definition: c.h:650
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:26

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

◆ cidin()

Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 325 of file xid.c.

326 {
327  char *str = PG_GETARG_CSTRING(0);
328  CommandId result;
329 
330  result = uint32in_subr(str, NULL, "cid", fcinfo->context);
331  PG_RETURN_COMMANDID(result);
332 }
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
uint32 uint32in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:649
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:27

References PG_GETARG_CSTRING, PG_RETURN_COMMANDID, generate_unaccent_rules::str, and uint32in_subr().

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 338 of file xid.c.

339 {
341  char *result = (char *) palloc(16);
342 
343  snprintf(result, 16, "%lu", (unsigned long) c);
344  PG_RETURN_CSTRING(result);
345 }
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1226
#define snprintf
Definition: port.h:238
char * c

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

◆ cidrecv()

Datum cidrecv ( PG_FUNCTION_ARGS  )

Definition at line 351 of file xid.c.

352 {
354 
356 }
#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:418
StringInfoData * StringInfo
Definition: stringinfo.h:44

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

◆ cidsend()

Datum cidsend ( PG_FUNCTION_ARGS  )

Definition at line 362 of file xid.c.

363 {
364  CommandId arg1 = PG_GETARG_COMMANDID(0);
366 
368  pq_sendint32(&buf, arg1);
370 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:349
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145

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

◆ mxid_age()

Datum mxid_age ( PG_FUNCTION_ARGS  )

Definition at line 119 of file xid.c.

120 {
123 
124  if (!MultiXactIdIsValid(xid))
125  PG_RETURN_INT32(INT_MAX);
126 
127  PG_RETURN_INT32((int32) (now - xid));
128 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1547
signed int int32
Definition: c.h:478
TransactionId MultiXactId
Definition: c.h:646
uint32 TransactionId
Definition: c.h:636
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:724
#define MultiXactIdIsValid(multi)
Definition: multixact.h:28

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

◆ xid8_larger()

Datum xid8_larger ( PG_FUNCTION_ARGS  )

Definition at line 294 of file xid.c.

295 {
298 
299  if (FullTransactionIdFollows(fxid1, fxid2))
301  else
303 }
#define FullTransactionIdFollows(a, b)
Definition: transam.h:53
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:29
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:30

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_FULLTRANSACTIONID.

◆ xid8_smaller()

Datum xid8_smaller ( PG_FUNCTION_ARGS  )

Definition at line 306 of file xid.c.

307 {
310 
311  if (FullTransactionIdPrecedes(fxid1, fxid2))
313  else
315 }
#define FullTransactionIdPrecedes(a, b)
Definition: transam.h:51

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_FULLTRANSACTIONID.

◆ xid8cmp()

Datum xid8cmp ( PG_FUNCTION_ARGS  )

Definition at line 280 of file xid.c.

281 {
284 
285  if (FullTransactionIdFollows(fxid1, fxid2))
286  PG_RETURN_INT32(1);
287  else if (FullTransactionIdEquals(fxid1, fxid2))
288  PG_RETURN_INT32(0);
289  else
290  PG_RETURN_INT32(-1);
291 }
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50

References FullTransactionIdEquals, FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_INT32.

◆ xid8eq()

Datum xid8eq ( PG_FUNCTION_ARGS  )

Definition at line 226 of file xid.c.

227 {
230 
232 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ge()

Datum xid8ge ( PG_FUNCTION_ARGS  )

Definition at line 271 of file xid.c.

272 {
275 
277 }
#define FullTransactionIdFollowsOrEquals(a, b)
Definition: transam.h:54

References FullTransactionIdFollowsOrEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8gt()

Datum xid8gt ( PG_FUNCTION_ARGS  )

Definition at line 253 of file xid.c.

254 {
257 
259 }

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8in()

Datum xid8in ( PG_FUNCTION_ARGS  )

Definition at line 185 of file xid.c.

186 {
187  char *str = PG_GETARG_CSTRING(0);
188  uint64 result;
189 
190  result = uint64in_subr(str, NULL, "xid8", fcinfo->context);
192 }
uint64 uint64in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:736
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81

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

◆ xid8le()

Datum xid8le ( PG_FUNCTION_ARGS  )

Definition at line 262 of file xid.c.

263 {
266 
268 }
#define FullTransactionIdPrecedesOrEquals(a, b)
Definition: transam.h:52

References FullTransactionIdPrecedesOrEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8lt()

Datum xid8lt ( PG_FUNCTION_ARGS  )

Definition at line 244 of file xid.c.

245 {
248 
250 }

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ne()

Datum xid8ne ( PG_FUNCTION_ARGS  )

Definition at line 235 of file xid.c.

236 {
239 
240  PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2));
241 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8out()

Datum xid8out ( PG_FUNCTION_ARGS  )

Definition at line 195 of file xid.c.

196 {
198  char *result = (char *) palloc(21);
199 
200  snprintf(result, 21, UINT64_FORMAT, U64FromFullTransactionId(fxid));
201  PG_RETURN_CSTRING(result);
202 }
#define UINT64_FORMAT
Definition: c.h:533
#define U64FromFullTransactionId(x)
Definition: transam.h:49

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

◆ xid8recv()

Datum xid8recv ( PG_FUNCTION_ARGS  )

Definition at line 205 of file xid.c.

206 {
208  uint64 value;
209 
210  value = (uint64) pq_getmsgint64(buf);
212 }
static struct @147 value
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:456

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

◆ xid8send()

Datum xid8send ( PG_FUNCTION_ARGS  )

Definition at line 215 of file xid.c.

216 {
219 
221  pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1));
223 }
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153

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

◆ xid8toxid()

Datum xid8toxid ( PG_FUNCTION_ARGS  )

Definition at line 177 of file xid.c.

178 {
180 
182 }
#define PG_RETURN_TRANSACTIONID(x)
Definition: fmgr.h:364
#define XidFromFullTransactionId(x)
Definition: transam.h:48

References PG_GETARG_FULLTRANSACTIONID, PG_RETURN_TRANSACTIONID, and XidFromFullTransactionId.

◆ xid_age()

Datum xid_age ( PG_FUNCTION_ARGS  )

Definition at line 103 of file xid.c.

104 {
107 
108  /* Permanent XIDs are always infinitely old */
109  if (!TransactionIdIsNormal(xid))
110  PG_RETURN_INT32(INT_MAX);
111 
112  PG_RETURN_INT32((int32) (now - xid));
113 }
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:598

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

◆ xidComparator()

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

Definition at line 138 of file xid.c.

139 {
140  TransactionId xid1 = *(const TransactionId *) arg1;
141  TransactionId xid2 = *(const TransactionId *) arg2;
142 
143  if (xid1 > xid2)
144  return 1;
145  if (xid1 < xid2)
146  return -1;
147  return 0;
148 }

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

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 79 of file xid.c.

80 {
83 
85 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

◆ xidin()

Datum xidin ( PG_FUNCTION_ARGS  )

Definition at line 31 of file xid.c.

32 {
33  char *str = PG_GETARG_CSTRING(0);
34  TransactionId result;
35 
36  result = uint32in_subr(str, NULL, "xid", fcinfo->context);
38 }

References PG_GETARG_CSTRING, PG_RETURN_TRANSACTIONID, generate_unaccent_rules::str, and uint32in_subr().

◆ xidLogicalComparator()

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

Definition at line 159 of file xid.c.

160 {
161  TransactionId xid1 = *(const TransactionId *) arg1;
162  TransactionId xid2 = *(const TransactionId *) arg2;
163 
166 
167  if (TransactionIdPrecedes(xid1, xid2))
168  return -1;
169 
170  if (TransactionIdPrecedes(xid2, xid1))
171  return 1;
172 
173  return 0;
174 }
Assert(fmt[strlen(fmt) - 1] !='\n')
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280

References Assert(), TransactionIdIsNormal, and TransactionIdPrecedes().

Referenced by ProcArrayApplyRecoveryInfo().

◆ xidneq()

Datum xidneq ( PG_FUNCTION_ARGS  )

Definition at line 91 of file xid.c.

92 {
95 
96  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
97 }

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 41 of file xid.c.

42 {
43  TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
44  char *result = (char *) palloc(16);
45 
46  snprintf(result, 16, "%lu", (unsigned long) transactionId);
47  PG_RETURN_CSTRING(result);
48 }

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

◆ xidrecv()

Datum xidrecv ( PG_FUNCTION_ARGS  )

Definition at line 54 of file xid.c.

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

◆ xidsend()