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

◆ PG_RETURN_COMMANDID

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 28 of file xid.c.

Function Documentation

◆ cideq()

Datum cideq ( PG_FUNCTION_ARGS  )

Definition at line 370 of file xid.c.

371 {
372  CommandId arg1 = PG_GETARG_COMMANDID(0);
373  CommandId arg2 = PG_GETARG_COMMANDID(1);
374 
375  PG_RETURN_BOOL(arg1 == arg2);
376 }
uint32 CommandId
Definition: c.h:653
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:27

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

◆ cidin()

Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 322 of file xid.c.

323 {
324  char *str = PG_GETARG_CSTRING(0);
325  CommandId result;
326 
327  result = uint32in_subr(str, NULL, "cid", fcinfo->context);
328  PG_RETURN_COMMANDID(result);
329 }
#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:900
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:28

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

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 335 of file xid.c.

336 {
338  char *result = (char *) palloc(16);
339 
340  snprintf(result, 16, "%lu", (unsigned long) c);
341  PG_RETURN_CSTRING(result);
342 }
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
void * palloc(Size size)
Definition: mcxt.c:1304
#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 348 of file xid.c.

349 {
351 
353 }
#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 359 of file xid.c.

360 {
361  CommandId arg1 = PG_GETARG_COMMANDID(0);
363 
365  pq_sendint32(&buf, arg1);
367 }
#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().

◆ mxid_age()

Datum mxid_age ( PG_FUNCTION_ARGS  )

Definition at line 120 of file xid.c.

121 {
124 
125  if (!MultiXactIdIsValid(xid))
126  PG_RETURN_INT32(INT_MAX);
127 
128  PG_RETURN_INT32((int32) (now - xid));
129 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1618
signed int int32
Definition: c.h:481
TransactionId MultiXactId
Definition: c.h:649
uint32 TransactionId
Definition: c.h:639
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:722
#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 291 of file xid.c.

292 {
295 
296  if (FullTransactionIdFollows(fxid1, fxid2))
298  else
300 }
#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 303 of file xid.c.

304 {
307 
308  if (FullTransactionIdPrecedes(fxid1, fxid2))
310  else
312 }
#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 277 of file xid.c.

278 {
281 
282  if (FullTransactionIdFollows(fxid1, fxid2))
283  PG_RETURN_INT32(1);
284  else if (FullTransactionIdEquals(fxid1, fxid2))
285  PG_RETURN_INT32(0);
286  else
287  PG_RETURN_INT32(-1);
288 }
#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 223 of file xid.c.

224 {
227 
229 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ge()

Datum xid8ge ( PG_FUNCTION_ARGS  )

Definition at line 268 of file xid.c.

269 {
272 
274 }
#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 250 of file xid.c.

251 {
254 
256 }

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8in()

Datum xid8in ( PG_FUNCTION_ARGS  )

Definition at line 182 of file xid.c.

183 {
184  char *str = PG_GETARG_CSTRING(0);
185  uint64 result;
186 
187  result = uint64in_subr(str, NULL, "xid8", fcinfo->context);
189 }
uint64 uint64in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:987
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 259 of file xid.c.

260 {
263 
265 }
#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 241 of file xid.c.

242 {
245 
247 }

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ne()

Datum xid8ne ( PG_FUNCTION_ARGS  )

Definition at line 232 of file xid.c.

233 {
236 
237  PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2));
238 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8out()

Datum xid8out ( PG_FUNCTION_ARGS  )

Definition at line 192 of file xid.c.

193 {
195  char *result = (char *) palloc(21);
196 
197  snprintf(result, 21, UINT64_FORMAT, U64FromFullTransactionId(fxid));
198  PG_RETURN_CSTRING(result);
199 }
#define UINT64_FORMAT
Definition: c.h:536
#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 202 of file xid.c.

203 {
205  uint64 value;
206 
207  value = (uint64) pq_getmsgint64(buf);
209 }
static struct @150 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 212 of file xid.c.

213 {
216 
218  pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1));
220 }
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 174 of file xid.c.

175 {
177 
179 }
#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 104 of file xid.c.

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 }
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:599

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

◆ xidComparator()

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

Definition at line 139 of file xid.c.

140 {
141  TransactionId xid1 = *(const TransactionId *) arg1;
142  TransactionId xid2 = *(const TransactionId *) arg2;
143 
144  return pg_cmp_u32(xid1, xid2);
145 }
static int pg_cmp_u32(uint32 a, uint32 b)
Definition: int.h:489

References pg_cmp_u32().

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

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 80 of file xid.c.

81 {
84 
86 }
#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 32 of file xid.c.

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

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

157 {
158  TransactionId xid1 = *(const TransactionId *) arg1;
159  TransactionId xid2 = *(const TransactionId *) arg2;
160 
163 
164  if (TransactionIdPrecedes(xid1, xid2))
165  return -1;
166 
167  if (TransactionIdPrecedes(xid2, xid1))
168  return 1;
169 
170  return 0;
171 }
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 92 of file xid.c.

93 {
96 
97  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
98 }

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 42 of file xid.c.

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 }

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

◆ 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().

◆ xidsend()