1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-14 08:21:07 +03:00

Add btree and hash opclasses for pg_lsn.

This is needed to allow ORDER BY, DISTINCT, etc to work as expected for
pg_lsn values.

We had previously decided to put this off for 9.5, but in view of commit
eeca4cd35e there's no reason to avoid a
catversion bump for 9.4beta2, and this does make a pretty significant
usability difference for pg_lsn.

Michael Paquier, with fixes from Andres Freund and Tom Lane
This commit is contained in:
Tom Lane
2014-06-04 20:45:56 -04:00
parent eeca4cd35e
commit 4c8ab1b91d
11 changed files with 196 additions and 4 deletions

View File

@ -1,9 +1,9 @@
/*-------------------------------------------------------------------------
*
* pg_lsn.c
* Internal PostgreSQL LSN operations
* Operations for the pg_lsn datatype.
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
@ -13,6 +13,7 @@
*/
#include "postgres.h"
#include "access/hash.h"
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
@ -153,6 +154,29 @@ pg_lsn_ge(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(lsn1 >= lsn2);
}
/* btree index opclass support */
Datum
pg_lsn_cmp(PG_FUNCTION_ARGS)
{
XLogRecPtr a = PG_GETARG_LSN(0);
XLogRecPtr b = PG_GETARG_LSN(1);
if (a > b)
PG_RETURN_INT32(1);
else if (a == b)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(-1);
}
/* hash index opclass support */
Datum
pg_lsn_hash(PG_FUNCTION_ARGS)
{
/* We can use hashint8 directly */
return hashint8(fcinfo);
}
/*----------------------------------------------------------
* Arithmetic operators on PostgreSQL LSNs.