Add min() and max() aggregates for xid8.
authorFujii Masao <fujii@postgresql.org>
Thu, 10 Feb 2022 03:33:41 +0000 (12:33 +0900)
committerFujii Masao <fujii@postgresql.org>
Thu, 10 Feb 2022 03:33:41 +0000 (12:33 +0900)
Bump catalog version.

Author: Ken Kato
Reviewed-by: Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/47d77b18c44f87f8222c4c7a3e2dee6b@oss.nttdata.com

doc/src/sgml/func.sgml
src/backend/utils/adt/xid.c
src/include/catalog/catversion.h
src/include/catalog/pg_aggregate.dat
src/include/catalog/pg_proc.dat
src/test/regress/expected/xid.out
src/test/regress/sql/xid.sql

index 8754f2f89b61b14209d780632d3c956e7c48bfad..1b064b4febf131113fbf60ae5b9e52d9f03e6fa5 100644 (file)
@@ -19973,7 +19973,7 @@ SELECT NULLIF(value, '(none)') ...
         values.  Available for any numeric, string, date/time, or enum type,
         as well as <type>inet</type>, <type>interval</type>,
         <type>money</type>, <type>oid</type>, <type>pg_lsn</type>,
-        <type>tid</type>,
+        <type>tid</type>, <type>xid8</type>,
         and arrays of any of these types.
        </para></entry>
        <entry>Yes</entry>
@@ -19992,7 +19992,7 @@ SELECT NULLIF(value, '(none)') ...
         values.  Available for any numeric, string, date/time, or enum type,
         as well as <type>inet</type>, <type>interval</type>,
         <type>money</type>, <type>oid</type>, <type>pg_lsn</type>,
-        <type>tid</type>,
+        <type>tid</type>, <type>xid8</type>,
         and arrays of any of these types.
        </para></entry>
        <entry>Yes</entry>
index 9b4ceaea47fc06f42772cadad8416e4678421adb..e4b4952a281ee0edeee9e48cb97f44be311bb300 100644 (file)
@@ -286,6 +286,30 @@ xid8cmp(PG_FUNCTION_ARGS)
                PG_RETURN_INT32(-1);
 }
 
+Datum
+xid8_larger(PG_FUNCTION_ARGS)
+{
+       FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0);
+       FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1);
+
+       if (FullTransactionIdFollows(fxid1, fxid2))
+               PG_RETURN_FULLTRANSACTIONID(fxid1);
+       else
+               PG_RETURN_FULLTRANSACTIONID(fxid2);
+}
+
+Datum
+xid8_smaller(PG_FUNCTION_ARGS)
+{
+       FullTransactionId fxid1 = PG_GETARG_FULLTRANSACTIONID(0);
+       FullTransactionId fxid2 = PG_GETARG_FULLTRANSACTIONID(1);
+
+       if (FullTransactionIdPrecedes(fxid1, fxid2))
+               PG_RETURN_FULLTRANSACTIONID(fxid1);
+       else
+               PG_RETURN_FULLTRANSACTIONID(fxid2);
+}
+
 /*****************************************************************************
  *      COMMAND IDENTIFIER ROUTINES                                                                                     *
  *****************************************************************************/
index c864b5a222dd2b3bb5292185dc75f0c1fd05177b..08f9b984d7f2e7bf57ecf261b23f7759279fd248 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     202202031
+#define CATALOG_VERSION_NO     202202101
 
 #endif
index 137f6eef69509c49eafeeac0ab6bc7ee49e2b563..2843f4b415910c854f0d293ebbe0520ead8ae3f5 100644 (file)
 { aggfnoid => 'max(pg_lsn)', aggtransfn => 'pg_lsn_larger',
   aggcombinefn => 'pg_lsn_larger', aggsortop => '>(pg_lsn,pg_lsn)',
   aggtranstype => 'pg_lsn' },
+{ aggfnoid => 'max(xid8)', aggtransfn => 'xid8_larger',
+  aggcombinefn => 'xid8_larger', aggsortop => '>(xid8,xid8)',
+  aggtranstype => 'xid8' },
 
 # min
 { aggfnoid => 'min(int8)', aggtransfn => 'int8smaller',
 { aggfnoid => 'min(pg_lsn)', aggtransfn => 'pg_lsn_smaller',
   aggcombinefn => 'pg_lsn_smaller', aggsortop => '<(pg_lsn,pg_lsn)',
   aggtranstype => 'pg_lsn' },
+{ aggfnoid => 'min(xid8)', aggtransfn => 'xid8_smaller',
+  aggcombinefn => 'xid8_smaller', aggsortop => '<(xid8,xid8)',
+  aggtranstype => 'xid8' },
 
 # count
 { aggfnoid => 'count(any)', aggtransfn => 'int8inc_any',
index 7024dbe10a2144e30b87a1885a7c9d17dfd55ede..62f36daa981bbdceb9ab9a9b9d3cabf55630873a 100644 (file)
 { oid => '5071', descr => 'convert xid8 to xid',
   proname => 'xid', prorettype => 'xid', proargtypes => 'xid8',
   prosrc => 'xid8toxid' },
+{ oid => '5097', descr => 'larger of two',
+  proname => 'xid8_larger', prorettype => 'xid8', proargtypes => 'xid8 xid8',
+  prosrc => 'xid8_larger' },
+{ oid => '5098', descr => 'smaller of two',
+  proname => 'xid8_smaller', prorettype => 'xid8', proargtypes => 'xid8 xid8',
+  prosrc => 'xid8_smaller' },
 { oid => '69',
   proname => 'cideq', proleakproof => 't', prorettype => 'bool',
   proargtypes => 'cid cid', prosrc => 'cideq' },
 { 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 => '5099', descr => 'maximum value of all xid8 input values',
+  proname => 'max', prokind => 'a', proisstrict => 'f', prorettype => 'xid8',
+  proargtypes => 'xid8', prosrc => 'aggregate_dummy' },
 
 { oid => '2131', descr => 'minimum value of all bigint input values',
   proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'int8',
 { 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' },
+{ oid => '5100', descr => 'minimum value of all xid8 input values',
+  proname => 'min', prokind => 'a', proisstrict => 'f', prorettype => 'xid8',
+  proargtypes => 'xid8', prosrc => 'aggregate_dummy' },
 
 # count has two forms: count(any) and count(*)
 { oid => '2147',
index b7a1ed0f9ee4acf43e5c3b7034289a2e45e7b850..d8e76f3321f809db86035eaaaa03c924b1491dd2 100644 (file)
@@ -129,8 +129,16 @@ select xid8cmp('1', '2'), xid8cmp('2', '2'), xid8cmp('2', '1');
       -1 |       0 |       1
 (1 row)
 
--- xid8 has btree and hash opclasses
+-- min() and max() for xid8
 create table xid8_t1 (x xid8);
+insert into xid8_t1 values ('0'), ('010'), ('42'), ('0xffffffffffffffff'), ('-1');
+select min(x), max(x) from xid8_t1;
+ min |         max          
+-----+----------------------
+   0 | 18446744073709551615
+(1 row)
+
+-- xid8 has btree and hash opclasses
 create index on xid8_t1 using btree(x);
 create index on xid8_t1 using hash(x);
 drop table xid8_t1;
index 565714d4620d54bf21d8f74e722c04831e87d3d1..bee17e63643df6a8ef9e24a43f8bf469859ccbf7 100644 (file)
@@ -41,8 +41,12 @@ select '1'::xid8 >= '2'::xid8, '2'::xid8 >= '2'::xid8, '2'::xid8 >= '1'::xid8;
 -- we also have a 3way compare for btrees
 select xid8cmp('1', '2'), xid8cmp('2', '2'), xid8cmp('2', '1');
 
--- xid8 has btree and hash opclasses
+-- min() and max() for xid8
 create table xid8_t1 (x xid8);
+insert into xid8_t1 values ('0'), ('010'), ('42'), ('0xffffffffffffffff'), ('-1');
+select min(x), max(x) from xid8_t1;
+
+-- xid8 has btree and hash opclasses
 create index on xid8_t1 using btree(x);
 create index on xid8_t1 using hash(x);
 drop table xid8_t1;