mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
pg_lsn macro naming and type behavior revisions.
Change pg_lsn_mi so that it can return negative values when subtracting LSNs, and clean up some perhaps ill-considered macro names.
This commit is contained in:
parent
7d03a83f4d
commit
844a28a9dd
@ -50,13 +50,13 @@ pg_lsn_in(PG_FUNCTION_ARGS)
|
||||
off = (uint32) strtoul(str + len1 + 1, NULL, 16);
|
||||
result = (XLogRecPtr) ((uint64) id << 32) | off;
|
||||
|
||||
PG_RETURN_PG_LSN(result);
|
||||
PG_RETURN_LSN(result);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_lsn_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
char buf[MAXPG_LSNLEN + 1];
|
||||
char *result;
|
||||
uint32 id, off;
|
||||
@ -77,13 +77,13 @@ pg_lsn_recv(PG_FUNCTION_ARGS)
|
||||
XLogRecPtr result;
|
||||
|
||||
result = pq_getmsgint64(buf);
|
||||
PG_RETURN_PG_LSN(result);
|
||||
PG_RETURN_LSN(result);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_lsn_send(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
StringInfoData buf;
|
||||
|
||||
pq_begintypsend(&buf);
|
||||
@ -99,8 +99,8 @@ pg_lsn_send(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_eq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
|
||||
PG_RETURN_BOOL(lsn1 == lsn2);
|
||||
}
|
||||
@ -108,8 +108,8 @@ pg_lsn_eq(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_ne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
|
||||
PG_RETURN_BOOL(lsn1 != lsn2);
|
||||
}
|
||||
@ -117,8 +117,8 @@ pg_lsn_ne(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_lt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
|
||||
PG_RETURN_BOOL(lsn1 < lsn2);
|
||||
}
|
||||
@ -126,8 +126,8 @@ pg_lsn_lt(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_gt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
|
||||
PG_RETURN_BOOL(lsn1 > lsn2);
|
||||
}
|
||||
@ -135,8 +135,8 @@ pg_lsn_gt(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_le(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
|
||||
PG_RETURN_BOOL(lsn1 <= lsn2);
|
||||
}
|
||||
@ -144,8 +144,8 @@ pg_lsn_le(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_ge(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
|
||||
PG_RETURN_BOOL(lsn1 >= lsn2);
|
||||
}
|
||||
@ -158,19 +158,18 @@ pg_lsn_ge(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_lsn_mi(PG_FUNCTION_ARGS)
|
||||
{
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_PG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_PG_LSN(1);
|
||||
XLogRecPtr lsn1 = (XLogRecPtr) PG_GETARG_LSN(0);
|
||||
XLogRecPtr lsn2 = (XLogRecPtr) PG_GETARG_LSN(1);
|
||||
char buf[256];
|
||||
Datum result;
|
||||
|
||||
/* Negative results are not allowed. */
|
||||
/* Output could be as large as plus or minus 2^63 - 1. */
|
||||
if (lsn1 < lsn2)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
|
||||
errmsg("transaction log location out of range")));
|
||||
snprintf(buf, sizeof buf, "-" UINT64_FORMAT, lsn2 - lsn1);
|
||||
else
|
||||
snprintf(buf, sizeof buf, UINT64_FORMAT, lsn1 - lsn2);
|
||||
|
||||
/* Convert to numeric. */
|
||||
snprintf(buf, sizeof buf, UINT64_FORMAT, lsn1 - lsn2);
|
||||
result = DirectFunctionCall3(numeric_in,
|
||||
CStringGetDatum(buf),
|
||||
ObjectIdGetDatum(0),
|
||||
|
@ -230,7 +230,7 @@ extern struct varlena *pg_detoast_datum_packed(struct varlena * datum);
|
||||
#define PG_GETARG_CHAR(n) DatumGetChar(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_BOOL(n) DatumGetBool(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_OID(n) DatumGetObjectId(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_PG_LSN(n) DatumGetPgLsn(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_LSN(n) DatumGetLSN(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_NAME(n) DatumGetName(PG_GETARG_DATUM(n))
|
||||
@ -303,7 +303,7 @@ extern struct varlena *pg_detoast_datum_packed(struct varlena * datum);
|
||||
#define PG_RETURN_CHAR(x) return CharGetDatum(x)
|
||||
#define PG_RETURN_BOOL(x) return BoolGetDatum(x)
|
||||
#define PG_RETURN_OID(x) return ObjectIdGetDatum(x)
|
||||
#define PG_RETURN_PG_LSN(x) return PgLsnGetDatum(x)
|
||||
#define PG_RETURN_LSN(x) return LSNGetDatum(x)
|
||||
#define PG_RETURN_POINTER(x) return PointerGetDatum(x)
|
||||
#define PG_RETURN_CSTRING(x) return CStringGetDatum(x)
|
||||
#define PG_RETURN_NAME(x) return NameGetDatum(x)
|
||||
|
@ -484,18 +484,18 @@ typedef Datum *DatumPtr;
|
||||
#define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
|
||||
|
||||
/*
|
||||
* DatumGetPgLsn
|
||||
* DatumGetLSN
|
||||
* Returns PostgreSQL log sequence number of a datum.
|
||||
*/
|
||||
|
||||
#define DatumGetPgLsn(X) ((XLogRecPtr) GET_8_BYTES(X))
|
||||
#define DatumGetLSN(X) ((XLogRecPtr) GET_8_BYTES(X))
|
||||
|
||||
/*
|
||||
* PG_LSNGetDatum
|
||||
* LSNGetDatum
|
||||
* Returns datum representation for a PostgreSQL log sequence number.
|
||||
*/
|
||||
|
||||
#define PgLsnGetDatum(X) ((Datum) SET_8_BYTES(X))
|
||||
#define LSNGetDatum(X) ((Datum) SET_8_BYTES(X))
|
||||
|
||||
/*
|
||||
* DatumGetTransactionId
|
||||
|
@ -53,7 +53,11 @@ SELECT '0/16AE7F8' > pg_lsn '0/16AE7F7';
|
||||
(1 row)
|
||||
|
||||
SELECT '0/16AE7F7'::pg_lsn - '0/16AE7F8'::pg_lsn; -- No negative results
|
||||
ERROR: transaction log location out of range
|
||||
?column?
|
||||
----------
|
||||
-1
|
||||
(1 row)
|
||||
|
||||
SELECT '0/16AE7F8'::pg_lsn - '0/16AE7F7'::pg_lsn; -- correct
|
||||
?column?
|
||||
----------
|
||||
|
Loading…
Reference in New Issue
Block a user