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 "common/hashfn.h"
#include "common/int.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 hashxid (PG_FUNCTION_ARGS)
 
Datum hashxidextended (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 hashxid8 (PG_FUNCTION_ARGS)
 
Datum hashxid8extended (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)
 
Datum hashcid (PG_FUNCTION_ARGS)
 
Datum hashcidextended (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ PG_GETARG_COMMANDID

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

Definition at line 28 of file xid.c.

◆ PG_RETURN_COMMANDID

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 29 of file xid.c.

Function Documentation

◆ cideq()

Datum cideq ( PG_FUNCTION_ARGS  )

Definition at line 395 of file xid.c.

396 {
397  CommandId arg1 = PG_GETARG_COMMANDID(0);
398  CommandId arg2 = PG_GETARG_COMMANDID(1);
399 
400  PG_RETURN_BOOL(arg1 == arg2);
401 }
uint32 CommandId
Definition: c.h:657
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

◆ cidin()

Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 347 of file xid.c.

348 {
349  char *str = PG_GETARG_CSTRING(0);
350  CommandId result;
351 
352  result = uint32in_subr(str, NULL, "cid", fcinfo->context);
353  PG_RETURN_COMMANDID(result);
354 }
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
const char * str
uint32 uint32in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:898
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:29

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

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 360 of file xid.c.

361 {
363  char *result = (char *) palloc(16);
364 
365  snprintf(result, 16, "%lu", (unsigned long) c);
366  PG_RETURN_CSTRING(result);
367 }
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1317
#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 373 of file xid.c.

374 {
376 
378 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static char * buf
Definition: pg_test_fsync.c:73
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:415
StringInfoData * StringInfo
Definition: stringinfo.h:54

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

◆ cidsend()

Datum cidsend ( PG_FUNCTION_ARGS  )

Definition at line 384 of file xid.c.

385 {
386  CommandId arg1 = PG_GETARG_COMMANDID(0);
388 
390  pq_sendint32(&buf, arg1);
392 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:326
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:346
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:144

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

◆ hashcid()

Datum hashcid ( PG_FUNCTION_ARGS  )

Definition at line 404 of file xid.c.

405 {
406  return hash_uint32(PG_GETARG_COMMANDID(0));
407 }
static Datum hash_uint32(uint32 k)
Definition: hashfn.h:43

References hash_uint32(), and PG_GETARG_COMMANDID.

◆ hashcidextended()

Datum hashcidextended ( PG_FUNCTION_ARGS  )

Definition at line 410 of file xid.c.

411 {
413 }
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
static Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.h:49

References hash_uint32_extended(), PG_GETARG_COMMANDID, and PG_GETARG_INT64.

◆ hashxid()

Datum hashxid ( PG_FUNCTION_ARGS  )

Definition at line 102 of file xid.c.

103 {
105 }
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279

References hash_uint32(), and PG_GETARG_TRANSACTIONID.

◆ hashxid8()

Datum hashxid8 ( PG_FUNCTION_ARGS  )

Definition at line 304 of file xid.c.

305 {
306  return hashint8(fcinfo);
307 }
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83

References hashint8().

◆ hashxid8extended()

Datum hashxid8extended ( PG_FUNCTION_ARGS  )

Definition at line 310 of file xid.c.

311 {
312  return hashint8extended(fcinfo);
313 }
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103

References hashint8extended().

◆ hashxidextended()

Datum hashxidextended ( PG_FUNCTION_ARGS  )

Definition at line 108 of file xid.c.

109 {
111 }

References hash_uint32_extended(), PG_GETARG_INT64, and PG_GETARG_TRANSACTIONID.

◆ mxid_age()

Datum mxid_age ( PG_FUNCTION_ARGS  )

Definition at line 133 of file xid.c.

134 {
137 
138  if (!MultiXactIdIsValid(xid))
139  PG_RETURN_INT32(INT_MAX);
140 
141  PG_RETURN_INT32((int32) (now - xid));
142 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1608
signed int int32
Definition: c.h:496
TransactionId MultiXactId
Definition: c.h:653
uint32 TransactionId
Definition: c.h:643
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:771
#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 316 of file xid.c.

317 {
320 
321  if (FullTransactionIdFollows(fxid1, fxid2))
323  else
325 }
#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 328 of file xid.c.

329 {
332 
333  if (FullTransactionIdPrecedes(fxid1, fxid2))
335  else
337 }
#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 290 of file xid.c.

291 {
294 
295  if (FullTransactionIdFollows(fxid1, fxid2))
296  PG_RETURN_INT32(1);
297  else if (FullTransactionIdEquals(fxid1, fxid2))
298  PG_RETURN_INT32(0);
299  else
300  PG_RETURN_INT32(-1);
301 }
#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 236 of file xid.c.

237 {
240 
242 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ge()

Datum xid8ge ( PG_FUNCTION_ARGS  )

Definition at line 281 of file xid.c.

282 {
285 
287 }
#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 263 of file xid.c.

264 {
267 
269 }

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8in()

Datum xid8in ( PG_FUNCTION_ARGS  )

Definition at line 195 of file xid.c.

196 {
197  char *str = PG_GETARG_CSTRING(0);
198  uint64 result;
199 
200  result = uint64in_subr(str, NULL, "xid8", fcinfo->context);
202 }
uint64 uint64in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:985
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81

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

◆ xid8le()

Datum xid8le ( PG_FUNCTION_ARGS  )

Definition at line 272 of file xid.c.

273 {
276 
278 }
#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 254 of file xid.c.

255 {
258 
260 }

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ne()

Datum xid8ne ( PG_FUNCTION_ARGS  )

Definition at line 245 of file xid.c.

246 {
249 
250  PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2));
251 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8out()

Datum xid8out ( PG_FUNCTION_ARGS  )

Definition at line 205 of file xid.c.

206 {
208  char *result = (char *) palloc(21);
209 
210  snprintf(result, 21, UINT64_FORMAT, U64FromFullTransactionId(fxid));
211  PG_RETURN_CSTRING(result);
212 }
#define UINT64_FORMAT
Definition: c.h:540
#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 215 of file xid.c.

216 {
218  uint64 value;
219 
220  value = (uint64) pq_getmsgint64(buf);
222 }
static struct @157 value
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:453

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

◆ xid8send()

Datum xid8send ( PG_FUNCTION_ARGS  )

Definition at line 225 of file xid.c.

226 {
229 
231  pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1));
233 }
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:152

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 187 of file xid.c.

188 {
190 
192 }
#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 117 of file xid.c.

118 {
121 
122  /* Permanent XIDs are always infinitely old */
123  if (!TransactionIdIsNormal(xid))
124  PG_RETURN_INT32(INT_MAX);
125 
126  PG_RETURN_INT32((int32) (now - xid));
127 }
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:606

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

◆ xidComparator()

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

Definition at line 152 of file xid.c.

153 {
154  TransactionId xid1 = *(const TransactionId *) arg1;
155  TransactionId xid2 = *(const TransactionId *) arg2;
156 
157  return pg_cmp_u32(xid1, xid2);
158 }
static int pg_cmp_u32(uint32 a, uint32 b)
Definition: int.h:604

References pg_cmp_u32().

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

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 81 of file xid.c.

82 {
85 
87 }
#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 33 of file xid.c.

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

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

◆ xidLogicalComparator()

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

Definition at line 169 of file xid.c.

170 {
171  TransactionId xid1 = *(const TransactionId *) arg1;
172  TransactionId xid2 = *(const TransactionId *) arg2;
173 
176 
177  if (TransactionIdPrecedes(xid1, xid2))
178  return -1;
179 
180  if (TransactionIdPrecedes(xid2, xid1))
181  return 1;
182 
183  return 0;
184 }
#define Assert(condition)
Definition: c.h:849
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 93 of file xid.c.

94 {
97 
98  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
99 }

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 43 of file xid.c.

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

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

◆ xidrecv()

Datum xidrecv ( PG_FUNCTION_ARGS  )

Definition at line 56 of file xid.c.

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

◆ xidsend()