PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xid8funcs.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * xid8funcs.c
3 *
4 * Export internal transaction IDs to user level.
5 *
6 * Note that only top-level transaction IDs are exposed to user sessions.
7 * This is important because xid8s frequently persist beyond the global
8 * xmin horizon, or may even be shipped to other machines, so we cannot
9 * rely on being able to correlate subtransaction IDs with their parents
10 * via functions such as SubTransGetTopmostTransaction().
11 *
12 * These functions are used to support the txid_XXX functions and the newer
13 * pg_current_xact_id, pg_current_snapshot and related fmgr functions, since
14 * the only difference between them is whether they expose xid8 or int8 values
15 * to users. The txid_XXX variants should eventually be dropped.
16 *
17 *
18 * Copyright (c) 2003-2025, PostgreSQL Global Development Group
19 * Author: Jan Wieck, Afilias USA INC.
20 * 64-bit txids: Marko Kreen, Skype Technologies
21 *
22 * src/backend/utils/adt/xid8funcs.c
23 *
24 *-------------------------------------------------------------------------
25 */
26
27#include "postgres.h"
28
29#include "access/transam.h"
30#include "access/xact.h"
31#include "funcapi.h"
32#include "lib/qunique.h"
33#include "libpq/pqformat.h"
34#include "miscadmin.h"
35#include "storage/lwlock.h"
36#include "storage/procarray.h"
37#include "storage/procnumber.h"
38#include "utils/builtins.h"
39#include "utils/memutils.h"
40#include "utils/snapmgr.h"
41#include "utils/xid8.h"
42
43
44/*
45 * If defined, use bsearch() function for searching for xid8s in snapshots
46 * that have more than the specified number of values.
47 */
48#define USE_BSEARCH_IF_NXIP_GREATER 30
49
50
51/*
52 * Snapshot containing FullTransactionIds.
53 */
54typedef struct
55{
56 /*
57 * 4-byte length hdr, should not be touched directly.
58 *
59 * Explicit embedding is ok as we want always correct alignment anyway.
60 */
62
63 uint32 nxip; /* number of fxids in xip array */
66 /* in-progress fxids, xmin <= xip[i] < xmax: */
69
70#define PG_SNAPSHOT_SIZE(nxip) \
71 (offsetof(pg_snapshot, xip) + sizeof(FullTransactionId) * (nxip))
72#define PG_SNAPSHOT_MAX_NXIP \
73 ((MaxAllocSize - offsetof(pg_snapshot, xip)) / sizeof(FullTransactionId))
74
75/*
76 * Compile-time limits on the procarray (MAX_BACKENDS processes plus
77 * MAX_BACKENDS prepared transactions) guarantee nxip won't be too large.
78 */
80 "possible overflow in pg_current_snapshot()");
81
82
83/*
84 * Helper to get a TransactionId from a 64-bit xid with wraparound detection.
85 *
86 * It is an ERROR if the xid is in the future. Otherwise, returns true if
87 * the transaction is still new enough that we can determine whether it
88 * committed and false otherwise. If *extracted_xid is not NULL, it is set
89 * to the low 32 bits of the transaction ID (i.e. the actual XID, without the
90 * epoch).
91 *
92 * The caller must hold XactTruncationLock since it's dealing with arbitrary
93 * XIDs, and must continue to hold it until it's done with any clog lookups
94 * relating to those XIDs.
95 */
96static bool
98{
100 FullTransactionId now_fullxid;
101 TransactionId oldest_clog_xid;
102 FullTransactionId oldest_clog_fxid;
103
104 now_fullxid = ReadNextFullTransactionId();
105
106 if (extracted_xid != NULL)
107 *extracted_xid = xid;
108
109 if (!TransactionIdIsValid(xid))
110 return false;
111
112 /* For non-normal transaction IDs, we can ignore the epoch. */
113 if (!TransactionIdIsNormal(xid))
114 return true;
115
116 /* If the transaction ID is in the future, throw an error. */
117 if (!FullTransactionIdPrecedes(fxid, now_fullxid))
119 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
120 errmsg("transaction ID %" PRIu64 " is in the future",
122
123 /*
124 * TransamVariables->oldestClogXid is protected by XactTruncationLock, but
125 * we don't acquire that lock here. Instead, we require the caller to
126 * acquire it, because the caller is presumably going to look up the
127 * returned XID. If we took and released the lock within this function, a
128 * CLOG truncation could occur before the caller finished with the XID.
129 */
130 Assert(LWLockHeldByMe(XactTruncationLock));
131
132 /*
133 * If fxid is not older than TransamVariables->oldestClogXid, the relevant
134 * CLOG entry is guaranteed to still exist.
135 *
136 * TransamVariables->oldestXid governs allowable XIDs. Usually,
137 * oldestClogXid==oldestXid. It's also possible for oldestClogXid to
138 * follow oldestXid, in which case oldestXid might advance after our
139 * ReadNextFullTransactionId() call. If oldestXid has advanced, that
140 * advancement reinstated the usual oldestClogXid==oldestXid. Whether or
141 * not that happened, oldestClogXid is allowable relative to now_fullxid.
142 */
143 oldest_clog_xid = TransamVariables->oldestClogXid;
144 oldest_clog_fxid =
145 FullTransactionIdFromAllowableAt(now_fullxid, oldest_clog_xid);
146 return !FullTransactionIdPrecedes(fxid, oldest_clog_fxid);
147}
148
149/*
150 * txid comparator for qsort/bsearch
151 */
152static int
153cmp_fxid(const void *aa, const void *bb)
154{
155 FullTransactionId a = *(const FullTransactionId *) aa;
156 FullTransactionId b = *(const FullTransactionId *) bb;
157
159 return -1;
161 return 1;
162 return 0;
163}
164
165/*
166 * Sort a snapshot's txids, so we can use bsearch() later. Also remove
167 * any duplicates.
168 *
169 * For consistency of on-disk representation, we always sort even if bsearch
170 * will not be used.
171 */
172static void
174{
175 if (snap->nxip > 1)
176 {
177 qsort(snap->xip, snap->nxip, sizeof(FullTransactionId), cmp_fxid);
178 snap->nxip = qunique(snap->xip, snap->nxip, sizeof(FullTransactionId),
179 cmp_fxid);
180 }
181}
182
183/*
184 * check fxid visibility.
185 */
186static bool
188{
190 return true;
191 else if (!FullTransactionIdPrecedes(value, snap->xmax))
192 return false;
193#ifdef USE_BSEARCH_IF_NXIP_GREATER
194 else if (snap->nxip > USE_BSEARCH_IF_NXIP_GREATER)
195 {
196 void *res;
197
198 res = bsearch(&value, snap->xip, snap->nxip, sizeof(FullTransactionId),
199 cmp_fxid);
200 /* if found, transaction is still in progress */
201 return (res) ? false : true;
202 }
203#endif
204 else
205 {
206 uint32 i;
207
208 for (i = 0; i < snap->nxip; i++)
209 {
210 if (FullTransactionIdEquals(value, snap->xip[i]))
211 return false;
212 }
213 return true;
214 }
215}
216
217/*
218 * helper functions to use StringInfo for pg_snapshot creation.
219 */
220
221static StringInfo
223{
224 pg_snapshot snap;
226
227 snap.xmin = xmin;
228 snap.xmax = xmax;
229 snap.nxip = 0;
230
233 return buf;
234}
235
236static void
238{
239 pg_snapshot *snap = (pg_snapshot *) buf->data;
240
241 /* do this before possible realloc */
242 snap->nxip++;
243
244 appendBinaryStringInfo(buf, &fxid, sizeof(fxid));
245}
246
247static pg_snapshot *
249{
250 pg_snapshot *snap = (pg_snapshot *) buf->data;
251
252 SET_VARSIZE(snap, buf->len);
253
254 /* buf is not needed anymore */
255 buf->data = NULL;
256 pfree(buf);
257
258 return snap;
259}
260
261/*
262 * parse snapshot from cstring
263 */
264static pg_snapshot *
265parse_snapshot(const char *str, Node *escontext)
266{
271 const char *str_start = str;
272 char *endp;
274
275 xmin = FullTransactionIdFromU64(strtou64(str, &endp, 10));
276 if (*endp != ':')
277 goto bad_format;
278 str = endp + 1;
279
280 xmax = FullTransactionIdFromU64(strtou64(str, &endp, 10));
281 if (*endp != ':')
282 goto bad_format;
283 str = endp + 1;
284
285 /* it should look sane */
286 if (!FullTransactionIdIsValid(xmin) ||
288 FullTransactionIdPrecedes(xmax, xmin))
289 goto bad_format;
290
291 /* allocate buffer */
292 buf = buf_init(xmin, xmax);
293
294 /* loop over values */
295 while (*str != '\0')
296 {
297 /* read next value */
298 val = FullTransactionIdFromU64(strtou64(str, &endp, 10));
299 str = endp;
300
301 /* require the input to be in order */
302 if (FullTransactionIdPrecedes(val, xmin) ||
305 goto bad_format;
306
307 /* skip duplicates */
308 if (!FullTransactionIdEquals(val, last_val))
310 last_val = val;
311
312 if (*str == ',')
313 str++;
314 else if (*str != '\0')
315 goto bad_format;
316 }
317
318 return buf_finalize(buf);
319
320bad_format:
321 ereturn(escontext, NULL,
322 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
323 errmsg("invalid input syntax for type %s: \"%s\"",
324 "pg_snapshot", str_start)));
325}
326
327/*
328 * pg_current_xact_id() returns xid8
329 *
330 * Return the current toplevel full transaction ID.
331 * If the current transaction does not have one, one is assigned.
332 */
333Datum
335{
336 /*
337 * Must prevent during recovery because if an xid is not assigned we try
338 * to assign one, which would fail. Programs already rely on this function
339 * to always return a valid current xid, so we should not change this to
340 * return NULL or similar invalid xid.
341 */
342 PreventCommandDuringRecovery("pg_current_xact_id()");
343
345}
346
347/*
348 * Same as pg_current_xact_id() but doesn't assign a new xid if there
349 * isn't one yet.
350 */
351Datum
353{
355
356 if (!FullTransactionIdIsValid(topfxid))
358
360}
361
362/*
363 * pg_current_snapshot() returns pg_snapshot
364 *
365 * Return current snapshot
366 *
367 * Note that only top-transaction XIDs are included in the snapshot.
368 */
369Datum
371{
372 pg_snapshot *snap;
373 uint32 nxip,
374 i;
377
379 if (cur == NULL)
380 elog(ERROR, "no active snapshot set");
381
382 /* allocate */
383 nxip = cur->xcnt;
384 snap = palloc(PG_SNAPSHOT_SIZE(nxip));
385
386 /*
387 * Fill. This is the current backend's active snapshot, so MyProc->xmin
388 * is <= all these XIDs. As long as that remains so, oldestXid can't
389 * advance past any of these XIDs. Hence, these XIDs remain allowable
390 * relative to next_fxid.
391 */
392 snap->xmin = FullTransactionIdFromAllowableAt(next_fxid, cur->xmin);
393 snap->xmax = FullTransactionIdFromAllowableAt(next_fxid, cur->xmax);
394 snap->nxip = nxip;
395 for (i = 0; i < nxip; i++)
396 snap->xip[i] =
397 FullTransactionIdFromAllowableAt(next_fxid, cur->xip[i]);
398
399 /*
400 * We want them guaranteed to be in ascending order. This also removes
401 * any duplicate xids. Normally, an XID can only be assigned to one
402 * backend, but when preparing a transaction for two-phase commit, there
403 * is a transient state when both the original backend and the dummy
404 * PGPROC entry reserved for the prepared transaction hold the same XID.
405 */
406 sort_snapshot(snap);
407
408 /* set size after sorting, because it may have removed duplicate xips */
409 SET_VARSIZE(snap, PG_SNAPSHOT_SIZE(snap->nxip));
410
411 PG_RETURN_POINTER(snap);
412}
413
414/*
415 * pg_snapshot_in(cstring) returns pg_snapshot
416 *
417 * input function for type pg_snapshot
418 */
419Datum
421{
422 char *str = PG_GETARG_CSTRING(0);
423 pg_snapshot *snap;
424
425 snap = parse_snapshot(str, fcinfo->context);
426
427 PG_RETURN_POINTER(snap);
428}
429
430/*
431 * pg_snapshot_out(pg_snapshot) returns cstring
432 *
433 * output function for type pg_snapshot
434 */
435Datum
437{
440 uint32 i;
441
443
448
449 for (i = 0; i < snap->nxip; i++)
450 {
451 if (i > 0)
455 }
456
458}
459
460/*
461 * pg_snapshot_recv(internal) returns pg_snapshot
462 *
463 * binary input function for type pg_snapshot
464 *
465 * format: int4 nxip, int8 xmin, int8 xmax, int8 xip
466 */
467Datum
469{
471 pg_snapshot *snap;
473 int nxip;
474 int i;
477
478 /* load and validate nxip */
479 nxip = pq_getmsgint(buf, 4);
480 if (nxip < 0 || nxip > PG_SNAPSHOT_MAX_NXIP)
481 goto bad_format;
482
485 if (!FullTransactionIdIsValid(xmin) ||
487 FullTransactionIdPrecedes(xmax, xmin))
488 goto bad_format;
489
490 snap = palloc(PG_SNAPSHOT_SIZE(nxip));
491 snap->xmin = xmin;
492 snap->xmax = xmax;
493
494 for (i = 0; i < nxip; i++)
495 {
498
499 if (FullTransactionIdPrecedes(cur, last) ||
502 goto bad_format;
503
504 /* skip duplicate xips */
505 if (FullTransactionIdEquals(cur, last))
506 {
507 i--;
508 nxip--;
509 continue;
510 }
511
512 snap->xip[i] = cur;
513 last = cur;
514 }
515 snap->nxip = nxip;
516 SET_VARSIZE(snap, PG_SNAPSHOT_SIZE(nxip));
517 PG_RETURN_POINTER(snap);
518
519bad_format:
521 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
522 errmsg("invalid external pg_snapshot data")));
523 PG_RETURN_POINTER(NULL); /* keep compiler quiet */
524}
525
526/*
527 * pg_snapshot_send(pg_snapshot) returns bytea
528 *
529 * binary output function for type pg_snapshot
530 *
531 * format: int4 nxip, u64 xmin, u64 xmax, u64 xip...
532 */
533Datum
535{
538 uint32 i;
539
541 pq_sendint32(&buf, snap->nxip);
544 for (i = 0; i < snap->nxip; i++)
547}
548
549/*
550 * pg_visible_in_snapshot(xid8, pg_snapshot) returns bool
551 *
552 * is txid visible in snapshot ?
553 */
554Datum
556{
559
561}
562
563/*
564 * pg_snapshot_xmin(pg_snapshot) returns xid8
565 *
566 * return snapshot's xmin
567 */
568Datum
570{
572
574}
575
576/*
577 * pg_snapshot_xmax(pg_snapshot) returns xid8
578 *
579 * return snapshot's xmax
580 */
581Datum
583{
585
587}
588
589/*
590 * pg_snapshot_xip(pg_snapshot) returns setof xid8
591 *
592 * return in-progress xid8s in snapshot.
593 */
594Datum
596{
597 FuncCallContext *fctx;
598 pg_snapshot *snap;
600
601 /* on first call initialize fctx and get copy of snapshot */
602 if (SRF_IS_FIRSTCALL())
603 {
605
606 fctx = SRF_FIRSTCALL_INIT();
607
608 /* make a copy of user snapshot */
610 memcpy(snap, arg, VARSIZE(arg));
611
612 fctx->user_fctx = snap;
613 }
614
615 /* return values one-by-one */
616 fctx = SRF_PERCALL_SETUP();
617 snap = fctx->user_fctx;
618 if (fctx->call_cntr < snap->nxip)
619 {
620 value = snap->xip[fctx->call_cntr];
622 }
623 else
624 {
625 SRF_RETURN_DONE(fctx);
626 }
627}
628
629/*
630 * Report the status of a recent transaction ID, or null for wrapped,
631 * truncated away or otherwise too old XIDs.
632 *
633 * The passed epoch-qualified xid is treated as a normal xid, not a
634 * multixact id.
635 *
636 * If it points to a committed subxact the result is the subxact status even
637 * though the parent xact may still be in progress or may have aborted.
638 */
639Datum
641{
642 const char *status;
644 TransactionId xid;
645
646 /*
647 * We must protect against concurrent truncation of clog entries to avoid
648 * an I/O error on SLRU lookup.
649 */
650 LWLockAcquire(XactTruncationLock, LW_SHARED);
651 if (TransactionIdInRecentPast(fxid, &xid))
652 {
654
655 /*
656 * Like when doing visibility checks on a row, check whether the
657 * transaction is still in progress before looking into the CLOG.
658 * Otherwise we would incorrectly return "committed" for a transaction
659 * that is committing and has already updated the CLOG, but hasn't
660 * removed its XID from the proc array yet. (See comment on that race
661 * condition at the top of heapam_visibility.c)
662 */
664 status = "in progress";
665 else if (TransactionIdDidCommit(xid))
666 status = "committed";
667 else
668 {
669 /* it must have aborted or crashed */
670 status = "aborted";
671 }
672 }
673 else
674 {
675 status = NULL;
676 }
677 LWLockRelease(XactTruncationLock);
678
679 if (status == NULL)
681 else
683}
int64_t int64
Definition: c.h:499
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
#define UINT64_FORMAT
Definition: c.h:521
int32_t int32
Definition: c.h:498
uint64_t uint64
Definition: c.h:503
uint32_t uint32
Definition: c.h:502
uint32 TransactionId
Definition: c.h:623
struct cursor * cur
Definition: ecpg.c:29
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereturn(context, dummy_value,...)
Definition: elog.h:278
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_VARLENA_P(n)
Definition: fmgr.h:287
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
Assert(PointerIsAligned(start, uint64))
const char * str
long val
Definition: informix.c:689
static struct @165 value
int b
Definition: isn.c:74
return false
Definition: isn.c:135
int a
Definition: isn.c:73
int i
Definition: isn.c:77
bool LWLockHeldByMe(LWLock *lock)
Definition: lwlock.c:1970
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1182
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1902
@ LW_SHARED
Definition: lwlock.h:115
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1256
void pfree(void *pointer)
Definition: mcxt.c:2147
void * palloc(Size size)
Definition: mcxt.c:1940
void * arg
static char * buf
Definition: pg_test_fsync.c:72
#define qsort(a, b, c, d)
Definition: port.h:479
uintptr_t Datum
Definition: postgres.h:69
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:415
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:326
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:453
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:346
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:144
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:152
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1402
#define MAX_BACKENDS
Definition: procnumber.h:39
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition: qunique.h:21
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:787
StringInfo makeStringInfo(void)
Definition: stringinfo.c:72
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:281
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
StringInfoData * StringInfo
Definition: stringinfo.h:54
void * user_fctx
Definition: funcapi.h:82
uint64 call_cntr
Definition: funcapi.h:65
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
Definition: nodes.h:135
TransactionId oldestClogXid
Definition: transam.h:253
FullTransactionId xip[FLEXIBLE_ARRAY_MEMBER]
Definition: xid8funcs.c:67
int32 __varsz
Definition: xid8funcs.c:61
FullTransactionId xmax
Definition: xid8funcs.c:65
uint32 nxip
Definition: xid8funcs.c:63
FullTransactionId xmin
Definition: xid8funcs.c:64
bool TransactionIdDidCommit(TransactionId transactionId)
Definition: transam.c:126
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50
static FullTransactionId FullTransactionIdFromAllowableAt(FullTransactionId nextFullXid, TransactionId xid)
Definition: transam.h:381
#define U64FromFullTransactionId(x)
Definition: transam.h:49
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81
#define FullTransactionIdFollowsOrEquals(a, b)
Definition: transam.h:54
#define XidFromFullTransactionId(x)
Definition: transam.h:48
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
#define InvalidFullTransactionId
Definition: transam.h:56
#define FullTransactionIdPrecedes(a, b)
Definition: transam.h:51
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:441
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARSIZE(PTR)
Definition: varatt.h:279
text * cstring_to_text(const char *s)
Definition: varlena.c:192
FullTransactionId ReadNextFullTransactionId(void)
Definition: varsup.c:288
TransamVariablesData * TransamVariables
Definition: varsup.c:34
FullTransactionId GetTopFullTransactionId(void)
Definition: xact.c:483
FullTransactionId GetTopFullTransactionIdIfAny(void)
Definition: xact.c:499
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:29
static Datum FullTransactionIdGetDatum(FullTransactionId X)
Definition: xid8.h:24
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:30
static bool TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid)
Definition: xid8funcs.c:97
Datum pg_snapshot_send(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:534
static pg_snapshot * buf_finalize(StringInfo buf)
Definition: xid8funcs.c:248
Datum pg_current_xact_id_if_assigned(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:352
static StringInfo buf_init(FullTransactionId xmin, FullTransactionId xmax)
Definition: xid8funcs.c:222
static bool is_visible_fxid(FullTransactionId value, const pg_snapshot *snap)
Definition: xid8funcs.c:187
static int cmp_fxid(const void *aa, const void *bb)
Definition: xid8funcs.c:153
#define USE_BSEARCH_IF_NXIP_GREATER
Definition: xid8funcs.c:48
Datum pg_snapshot_out(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:436
#define PG_SNAPSHOT_SIZE(nxip)
Definition: xid8funcs.c:70
#define PG_SNAPSHOT_MAX_NXIP
Definition: xid8funcs.c:72
Datum pg_current_xact_id(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:334
static pg_snapshot * parse_snapshot(const char *str, Node *escontext)
Definition: xid8funcs.c:265
Datum pg_snapshot_recv(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:468
Datum pg_snapshot_in(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:420
Datum pg_xact_status(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:640
Datum pg_current_snapshot(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:370
static void buf_add_txid(StringInfo buf, FullTransactionId fxid)
Definition: xid8funcs.c:237
Datum pg_snapshot_xmin(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:569
Datum pg_snapshot_xip(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:595
static void sort_snapshot(pg_snapshot *snap)
Definition: xid8funcs.c:173
Datum pg_visible_in_snapshot(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:555
StaticAssertDecl(MAX_BACKENDS *2<=PG_SNAPSHOT_MAX_NXIP, "possible overflow in pg_current_snapshot()")
Datum pg_snapshot_xmax(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:582