mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
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
This commit is contained in:
@ -317,6 +317,9 @@ check_hash_func_signature(Oid funcid, int16 amprocnum, Oid argtype)
|
||||
(argtype == DATEOID ||
|
||||
argtype == XIDOID || argtype == CIDOID))
|
||||
/* okay, allowed use of hashint4() */ ;
|
||||
else if ((funcid == F_HASHINT8 || funcid == F_HASHINT8EXTENDED) &&
|
||||
(argtype == XID8OID))
|
||||
/* okay, allowed use of hashint8() */ ;
|
||||
else if ((funcid == F_TIMESTAMP_HASH ||
|
||||
funcid == F_TIMESTAMP_HASH_EXTENDED) &&
|
||||
argtype == TIMESTAMPTZOID)
|
||||
|
@ -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 *
|
||||
*****************************************************************************/
|
||||
|
Reference in New Issue
Block a user