Commit 313f87a1 authored by Michael Paquier's avatar Michael Paquier

Add min() and max() aggregates for pg_lsn

This is useful for monitoring, when it comes for example to calculations
of WAL retention with replication slots and delays with a set of
standbys.

Bump catalog version.

Author: Fabrízio de Royes Mello
Reviewed-by: Surafel Temesgen
Discussion: https://postgr.es/m/CAFcNs+oc8ZoHhowA4rR1GGCgG8QNgK_TOwPRVYQo5rYy8_PXzA@mail.gmail.com
parent 8a810a17
...@@ -14804,7 +14804,7 @@ NULL baz</literallayout>(3 rows)</entry> ...@@ -14804,7 +14804,7 @@ NULL baz</literallayout>(3 rows)</entry>
</indexterm> </indexterm>
<function>max(<replaceable class="parameter">expression</replaceable>)</function> <function>max(<replaceable class="parameter">expression</replaceable>)</function>
</entry> </entry>
<entry>any numeric, string, date/time, network, or enum type, <entry>any numeric, string, date/time, network, pg_lsn, or enum type,
or arrays of these types</entry> or arrays of these types</entry>
<entry>same as argument type</entry> <entry>same as argument type</entry>
<entry>Yes</entry> <entry>Yes</entry>
...@@ -14822,7 +14822,7 @@ NULL baz</literallayout>(3 rows)</entry> ...@@ -14822,7 +14822,7 @@ NULL baz</literallayout>(3 rows)</entry>
</indexterm> </indexterm>
<function>min(<replaceable class="parameter">expression</replaceable>)</function> <function>min(<replaceable class="parameter">expression</replaceable>)</function>
</entry> </entry>
<entry>any numeric, string, date/time, network, or enum type, <entry>any numeric, string, date/time, network, pg_lsn, or enum type,
or arrays of these types</entry> or arrays of these types</entry>
<entry>same as argument type</entry> <entry>same as argument type</entry>
<entry>Yes</entry> <entry>Yes</entry>
......
...@@ -171,6 +171,24 @@ pg_lsn_ge(PG_FUNCTION_ARGS) ...@@ -171,6 +171,24 @@ pg_lsn_ge(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(lsn1 >= lsn2); PG_RETURN_BOOL(lsn1 >= lsn2);
} }
Datum
pg_lsn_larger(PG_FUNCTION_ARGS)
{
XLogRecPtr lsn1 = PG_GETARG_LSN(0);
XLogRecPtr lsn2 = PG_GETARG_LSN(1);
PG_RETURN_LSN((lsn1 > lsn2) ? lsn1 : lsn2);
}
Datum
pg_lsn_smaller(PG_FUNCTION_ARGS)
{
XLogRecPtr lsn1 = PG_GETARG_LSN(0);
XLogRecPtr lsn2 = PG_GETARG_LSN(1);
PG_RETURN_LSN((lsn1 < lsn2) ? lsn1 : lsn2);
}
/* btree index opclass support */ /* btree index opclass support */
Datum Datum
pg_lsn_cmp(PG_FUNCTION_ARGS) pg_lsn_cmp(PG_FUNCTION_ARGS)
......
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201907052 #define CATALOG_VERSION_NO 201907053
#endif #endif
...@@ -146,6 +146,9 @@ ...@@ -146,6 +146,9 @@
{ aggfnoid => 'max(inet)', aggtransfn => 'network_larger', { aggfnoid => 'max(inet)', aggtransfn => 'network_larger',
aggcombinefn => 'network_larger', aggsortop => '>(inet,inet)', aggcombinefn => 'network_larger', aggsortop => '>(inet,inet)',
aggtranstype => 'inet' }, aggtranstype => 'inet' },
{ aggfnoid => 'max(pg_lsn)', aggtransfn => 'pg_lsn_larger',
aggcombinefn => 'pg_lsn_larger', aggsortop => '>(pg_lsn,pg_lsn)',
aggtranstype => 'pg_lsn' },
# min # min
{ aggfnoid => 'min(int8)', aggtransfn => 'int8smaller', { aggfnoid => 'min(int8)', aggtransfn => 'int8smaller',
...@@ -208,6 +211,9 @@ ...@@ -208,6 +211,9 @@
{ aggfnoid => 'min(inet)', aggtransfn => 'network_smaller', { aggfnoid => 'min(inet)', aggtransfn => 'network_smaller',
aggcombinefn => 'network_smaller', aggsortop => '<(inet,inet)', aggcombinefn => 'network_smaller', aggsortop => '<(inet,inet)',
aggtranstype => 'inet' }, aggtranstype => 'inet' },
{ aggfnoid => 'min(pg_lsn)', aggtransfn => 'pg_lsn_smaller',
aggcombinefn => 'pg_lsn_smaller', aggsortop => '<(pg_lsn,pg_lsn)',
aggtranstype => 'pg_lsn' },
# count # count
{ aggfnoid => 'count(any)', aggtransfn => 'int8inc_any', { aggfnoid => 'count(any)', aggtransfn => 'int8inc_any',
......
...@@ -6219,6 +6219,9 @@ ...@@ -6219,6 +6219,9 @@
{ oid => '3564', descr => 'maximum value of all inet input values', { oid => '3564', descr => 'maximum value of all inet input values',
proname => 'max', prokind => 'a', proisstrict => 'f', prorettype => 'inet', proname => 'max', prokind => 'a', proisstrict => 'f', prorettype => 'inet',
proargtypes => 'inet', prosrc => 'aggregate_dummy' }, proargtypes => 'inet', prosrc => 'aggregate_dummy' },
{ oid => '4189', descr => 'maximum value of all pg_lsn input values',
proname => 'max', prokind => 'a', proisstrict => 'f', prorettype => 'pg_lsn',
proargtypes => 'pg_lsn', prosrc => 'aggregate_dummy' },
{ oid => '2131', descr => 'minimum value of all bigint input values', { oid => '2131', descr => 'minimum value of all bigint input values',
proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'int8', proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'int8',
...@@ -6283,6 +6286,9 @@ ...@@ -6283,6 +6286,9 @@
{ oid => '3565', descr => 'minimum value of all inet input values', { oid => '3565', descr => 'minimum value of all inet input values',
proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'inet', proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'inet',
proargtypes => 'inet', prosrc => 'aggregate_dummy' }, proargtypes => 'inet', prosrc => 'aggregate_dummy' },
{ oid => '4190', descr => 'minimum value of all pg_lsn input values',
proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'pg_lsn',
proargtypes => 'pg_lsn', prosrc => 'aggregate_dummy' },
# count has two forms: count(any) and count(*) # count has two forms: count(any) and count(*)
{ oid => '2147', { oid => '2147',
...@@ -8385,6 +8391,12 @@ ...@@ -8385,6 +8391,12 @@
{ oid => '3413', descr => 'hash', { oid => '3413', descr => 'hash',
proname => 'pg_lsn_hash_extended', prorettype => 'int8', proname => 'pg_lsn_hash_extended', prorettype => 'int8',
proargtypes => 'pg_lsn int8', prosrc => 'pg_lsn_hash_extended' }, proargtypes => 'pg_lsn int8', prosrc => 'pg_lsn_hash_extended' },
{ oid => '4187', descr => 'larger of two',
proname => 'pg_lsn_larger', prorettype => 'pg_lsn',
proargtypes => 'pg_lsn pg_lsn', prosrc => 'pg_lsn_larger' },
{ oid => '4188', descr => 'smaller of two',
proname => 'pg_lsn_smaller', prorettype => 'pg_lsn',
proargtypes => 'pg_lsn pg_lsn', prosrc => 'pg_lsn_smaller' },
# enum related procs # enum related procs
{ oid => '3504', descr => 'I/O', { oid => '3504', descr => 'I/O',
......
...@@ -26,6 +26,13 @@ INSERT INTO PG_LSN_TBL VALUES ('/ABCD'); ...@@ -26,6 +26,13 @@ INSERT INTO PG_LSN_TBL VALUES ('/ABCD');
ERROR: invalid input syntax for type pg_lsn: "/ABCD" ERROR: invalid input syntax for type pg_lsn: "/ABCD"
LINE 1: INSERT INTO PG_LSN_TBL VALUES ('/ABCD'); LINE 1: INSERT INTO PG_LSN_TBL VALUES ('/ABCD');
^ ^
-- Min/Max aggregation
SELECT MIN(f1), MAX(f1) FROM PG_LSN_TBL;
min | max
-----+-------------------
0/0 | FFFFFFFF/FFFFFFFF
(1 row)
DROP TABLE PG_LSN_TBL; DROP TABLE PG_LSN_TBL;
-- Operators -- Operators
SELECT '0/16AE7F8' = '0/16AE7F8'::pg_lsn; SELECT '0/16AE7F8' = '0/16AE7F8'::pg_lsn;
......
...@@ -14,6 +14,10 @@ INSERT INTO PG_LSN_TBL VALUES ('-1/0'); ...@@ -14,6 +14,10 @@ INSERT INTO PG_LSN_TBL VALUES ('-1/0');
INSERT INTO PG_LSN_TBL VALUES (' 0/12345678'); INSERT INTO PG_LSN_TBL VALUES (' 0/12345678');
INSERT INTO PG_LSN_TBL VALUES ('ABCD/'); INSERT INTO PG_LSN_TBL VALUES ('ABCD/');
INSERT INTO PG_LSN_TBL VALUES ('/ABCD'); INSERT INTO PG_LSN_TBL VALUES ('/ABCD');
-- Min/Max aggregation
SELECT MIN(f1), MAX(f1) FROM PG_LSN_TBL;
DROP TABLE PG_LSN_TBL; DROP TABLE PG_LSN_TBL;
-- Operators -- Operators
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment