diff options
author | Thomas Munro <tmunro@postgresql.org> | 2020-04-07 11:08:14 +1200 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2020-04-07 12:03:59 +1200 |
commit | aeec457de8a8820368e343e791accffe24dc7198 (patch) | |
tree | 1e95e2de03595a459bc26717cf4a3bb22163fb83 /src/backend/utils/adt/xid.c | |
parent | 4bea576b032d6e5435ef0946194aada314e67691 (diff) | |
download | postgresql-aeec457de8a8820368e343e791accffe24dc7198.tar.gz postgresql-aeec457de8a8820368e343e791accffe24dc7198.zip |
Add SQL type xid8 to expose FullTransactionId to users.
Similar to xid, but 64 bits wide. This new type is suitable for use in
various system views and administration functions.
Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com>
Reviewed-by: Takao Fujii <btfujiitkp@oss.nttdata.com>
Reviewed-by: Yoshikazu Imai <imai.yoshikazu@fujitsu.com>
Reviewed-by: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://postgr.es/m/20190725000636.666m5mad25wfbrri%40alap3.anarazel.de
Diffstat (limited to 'src/backend/utils/adt/xid.c')
-rw-r--r-- | src/backend/utils/adt/xid.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/backend/utils/adt/xid.c b/src/backend/utils/adt/xid.c index db6fc9dd6b8..20389aff1d1 100644 --- a/src/backend/utils/adt/xid.c +++ b/src/backend/utils/adt/xid.c @@ -21,6 +21,7 @@ #include "access/xact.h" #include "libpq/pqformat.h" #include "utils/builtins.h" +#include "utils/xid8.h" #define PG_GETARG_TRANSACTIONID(n) DatumGetTransactionId(PG_GETARG_DATUM(n)) #define PG_RETURN_TRANSACTIONID(x) return TransactionIdGetDatum(x) @@ -147,6 +148,121 @@ xidComparator(const void *arg1, const void *arg2) return 0; } +Datum +xid8toxid(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid = PG_GETARG_FULLTRANSACTIONID(0); + + PG_RETURN_TRANSACTIONID(XidFromFullTransactionId(fxid)); +} + +Datum +xid8in(PG_FUNCTION_ARGS) +{ + char *str = PG_GETARG_CSTRING(0); + + PG_RETURN_FULLTRANSACTIONID(FullTransactionIdFromU64(pg_strtouint64(str, NULL, 0))); +} + +Datum +xid8out(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid = PG_GETARG_FULLTRANSACTIONID(0); + char *result = (char *) palloc(21); + + snprintf(result, 21, UINT64_FORMAT, U64FromFullTransactionId(fxid)); + PG_RETURN_CSTRING(result); +} + +Datum +xid8recv(PG_FUNCTION_ARGS) +{ + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + uint64 value; + + value = (uint64) pq_getmsgint64(buf); + PG_RETURN_FULLTRANSACTIONID(FullTransactionIdFromU64(value)); +} + +Datum +xid8send(PG_FUNCTION_ARGS) +{ + FullTransactionId arg1 = PG_GETARG_FULLTRANSACTIONID(0); + StringInfoData buf; + + pq_begintypsend(&buf); + pq_sendint64(&buf, (uint64) U64FromFullTransactionId(arg1)); + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} + +Datum +xid8eq(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + PG_RETURN_BOOL(FullTransactionIdEquals(fxid1, fxid2)); +} + +Datum +xid8ne(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + PG_RETURN_BOOL(!FullTransactionIdEquals(fxid1, fxid2)); +} + +Datum +xid8lt(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + PG_RETURN_BOOL(FullTransactionIdPrecedes(fxid1, fxid2)); +} + +Datum +xid8gt(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + PG_RETURN_BOOL(FullTransactionIdFollows(fxid1, fxid2)); +} + +Datum +xid8le(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + PG_RETURN_BOOL(FullTransactionIdPrecedesOrEquals(fxid1, fxid2)); +} + +Datum +xid8ge(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + PG_RETURN_BOOL(FullTransactionIdFollowsOrEquals(fxid1, fxid2)); +} + +Datum +xid8cmp(PG_FUNCTION_ARGS) +{ + FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0); + FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1); + + if (FullTransactionIdFollows(fxid1, fxid2)) + PG_RETURN_INT32(1); + else if (FullTransactionIdEquals(fxid1, fxid2)) + PG_RETURN_INT32(0); + else + PG_RETURN_INT32(-1); +} + /***************************************************************************** * COMMAND IDENTIFIER ROUTINES * *****************************************************************************/ |