On Wed, Sep  3, 2014 at 05:17:17PM -0400, Robert Haas wrote:
> > I had a look at this and came upon a problem --- there is no multi-xid
> > SQL data type, and in fact the system catalogs that store mxid values
> > use xid, e.g.:
> >
> >          relminmxid     | xid       | not null
> >
> > With no mxid data type, there is no way to do function overloading to
> > cause age to call the mxid variant.
> >
> > Should we use an explicit mxid_age() function name?  Add an mxid data
> > type?
> 
> Maybe both.  But mxid_age() is probably the simpler way forward just to start.

OK, patch applied using mxid_age() and no new data type.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +
diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml
new file mode 100644
index cf174f0..d692308
*** a/doc/src/sgml/maintenance.sgml
--- b/doc/src/sgml/maintenance.sgml
*************** HINT:  Stop the postmaster and vacuum th
*** 640,646 ****
       possible multixact ID still appearing in any tuple of that table.
       If this value is older than
       <xref linkend="guc-vacuum-multixact-freeze-table-age">, a whole-table
!      scan is forced.  Whole-table <command>VACUUM</> scans, regardless of
       what causes them, enable advancing the value for that table.
       Eventually, as all tables in all databases are scanned and their
       oldest multixact values are advanced, on-disk storage for older
--- 640,651 ----
       possible multixact ID still appearing in any tuple of that table.
       If this value is older than
       <xref linkend="guc-vacuum-multixact-freeze-table-age">, a whole-table
!      scan is forced.  <function>mxid_age()</> can be used on
!      <structname>pg_class</>.<structfield>relminmxid</> to find its age.
!     </para>
! 
!     <para>
!      Whole-table <command>VACUUM</> scans, regardless of
       what causes them, enable advancing the value for that table.
       Eventually, as all tables in all databases are scanned and their
       oldest multixact values are advanced, on-disk storage for older
diff --git a/src/backend/utils/adt/xid.c b/src/backend/utils/adt/xid.c
new file mode 100644
index 602a9e5..ecb3cf5
*** a/src/backend/utils/adt/xid.c
--- b/src/backend/utils/adt/xid.c
***************
*** 16,21 ****
--- 16,22 ----
  
  #include <limits.h>
  
+ #include "access/multixact.h"
  #include "access/transam.h"
  #include "access/xact.h"
  #include "libpq/pqformat.h"
*************** xid_age(PG_FUNCTION_ARGS)
*** 100,105 ****
--- 101,121 ----
  		PG_RETURN_INT32(INT_MAX);
  
  	PG_RETURN_INT32((int32) (now - xid));
+ }
+ 
+ /*
+  *		mxid_age			- compute age of a multi XID (relative to latest stable mxid)
+  */
+ Datum
+ mxid_age(PG_FUNCTION_ARGS)
+ {
+ 	TransactionId xid = PG_GETARG_TRANSACTIONID(0);
+ 	MultiXactId now = ReadNextMultiXactId();
+ 
+ 	if (!MultiXactIdIsValid(xid))
+ 		PG_RETURN_INT32(INT_MAX);
+ 
+ 	PG_RETURN_INT32((int32) (now - xid));
  }
  
  /*
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
new file mode 100644
index e1b62a5..e0875b7
*** a/src/include/catalog/catversion.h
--- b/src/include/catalog/catversion.h
***************
*** 53,58 ****
   */
  
  /*							yyyymmddN */
! #define CATALOG_VERSION_NO	201408281
  
  #endif
--- 53,58 ----
   */
  
  /*							yyyymmddN */
! #define CATALOG_VERSION_NO	201409021
  
  #endif
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
new file mode 100644
index 5176ed0..09e138b
*** a/src/include/catalog/pg_proc.h
--- b/src/include/catalog/pg_proc.h
*************** DATA(insert OID = 1180 (  abstime		   PG
*** 1277,1282 ****
--- 1277,1284 ----
  DESCR("convert timestamp with time zone to abstime");
  DATA(insert OID = 1181 (  age			   PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "28" _null_ _null_ _null_ _null_ xid_age _null_ _null_ _null_ ));
  DESCR("age of a transaction ID, in transactions before current transaction");
+ DATA(insert OID = 3218 (  mxid_age		   PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "28" _null_ _null_ _null_ _null_ mxid_age _null_ _null_ _null_ ));
+ DESCR("age of a multi-transaction ID, in multi-transactions before current multi-transaction");
  
  DATA(insert OID = 1188 (  timestamptz_mi   PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1184 1184" _null_ _null_ _null_ _null_ timestamp_mi _null_ _null_ _null_ ));
  DATA(insert OID = 1189 (  timestamptz_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "1184 1186" _null_ _null_ _null_ _null_ timestamptz_pl_interval _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
new file mode 100644
index 78cc0a0..d88e7a3
*** a/src/include/utils/builtins.h
--- b/src/include/utils/builtins.h
*************** extern Datum xidrecv(PG_FUNCTION_ARGS);
*** 845,850 ****
--- 845,851 ----
  extern Datum xidsend(PG_FUNCTION_ARGS);
  extern Datum xideq(PG_FUNCTION_ARGS);
  extern Datum xid_age(PG_FUNCTION_ARGS);
+ extern Datum mxid_age(PG_FUNCTION_ARGS);
  extern int	xidComparator(const void *arg1, const void *arg2);
  extern Datum cidin(PG_FUNCTION_ARGS);
  extern Datum cidout(PG_FUNCTION_ARGS);
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to