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

368 {
369  CommandId arg1 = PG_GETARG_COMMANDID(0);
370  CommandId arg2 = PG_GETARG_COMMANDID(1);
371 
372  PG_RETURN_BOOL(arg1 == arg2);
373 }
uint32 CommandId
Definition: c.h:602
#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 321 of file xid.c.

322 {
323  char *str = PG_GETARG_CSTRING(0);
324 
325  PG_RETURN_COMMANDID((CommandId) strtoul(str, NULL, 0));
326 }
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:27

References PG_GETARG_CSTRING, PG_RETURN_COMMANDID, and generate_unaccent_rules::str.

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 332 of file xid.c.

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

346 {
348 
350 }
#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
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 356 of file xid.c.

357 {
358  CommandId arg1 = PG_GETARG_COMMANDID(0);
360 
362  pq_sendint32(&buf, arg1);
364 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
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 117 of file xid.c.

118 {
121 
122  if (!MultiXactIdIsValid(xid))
123  PG_RETURN_INT32(INT_MAX);
124 
125  PG_RETURN_INT32((int32) (now - xid));
126 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1537
signed int int32
Definition: c.h:430
TransactionId MultiXactId
Definition: c.h:598
uint32 TransactionId
Definition: c.h:588
#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 290 of file xid.c.

291 {
294 
295  if (FullTransactionIdFollows(fxid1, fxid2))
297  else
299 }
#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 302 of file xid.c.

303 {
306 
307  if (FullTransactionIdPrecedes(fxid1, fxid2))
309  else
311 }
#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 276 of file xid.c.

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

223 {
226 
228 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ge()

Datum xid8ge ( PG_FUNCTION_ARGS  )

Definition at line 267 of file xid.c.

268 {
271 
273 }
#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 249 of file xid.c.

250 {
253 
255 }

References FullTransactionIdFollows, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8in()

Datum xid8in ( PG_FUNCTION_ARGS  )

Definition at line 183 of file xid.c.

184 {
185  char *str = PG_GETARG_CSTRING(0);
186 
188 }
#define strtou64(str, endptr, base)
Definition: c.h:1234
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81

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

◆ xid8le()

Datum xid8le ( PG_FUNCTION_ARGS  )

Definition at line 258 of file xid.c.

259 {
262 
264 }
#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 240 of file xid.c.

241 {
244 
246 }

References FullTransactionIdPrecedes, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8ne()

Datum xid8ne ( PG_FUNCTION_ARGS  )

Definition at line 231 of file xid.c.

232 {
235 
236  PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2));
237 }

References FullTransactionIdEquals, PG_GETARG_FULLTRANSACTIONID, and PG_RETURN_BOOL.

◆ xid8out()

Datum xid8out ( PG_FUNCTION_ARGS  )

Definition at line 191 of file xid.c.

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

202 {
204  uint64 value;
205 
206  value = (uint64) pq_getmsgint64(buf);
208 }
static struct @143 value
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

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

◆ xid8send()

Datum xid8send ( PG_FUNCTION_ARGS  )

Definition at line 211 of file xid.c.

212 {
215 
217  pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1));
219 }
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 175 of file xid.c.

176 {
178 
180 }
#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 101 of file xid.c.

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

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

◆ xidComparator()

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

Definition at line 136 of file xid.c.

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 }

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

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 77 of file xid.c.

78 {
81 
83 }
#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 
35  PG_RETURN_TRANSACTIONID((TransactionId) strtoul(str, NULL, 0));
36 }

References PG_GETARG_CSTRING, PG_RETURN_TRANSACTIONID, and generate_unaccent_rules::str.

◆ xidLogicalComparator()

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

Definition at line 157 of file xid.c.

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

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

Referenced by ProcArrayApplyRecoveryInfo().

◆ xidneq()

Datum xidneq ( PG_FUNCTION_ARGS  )

Definition at line 89 of file xid.c.

90 {
93 
94  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
95 }

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 39 of file xid.c.

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 }

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

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

◆ xidsend()