diff -dcrpN pgsql-float4-float8-byval/src/backend/optimizer/plan/planagg.c pgsql-float4-float8-int64-byval/src/backend/optimizer/plan/planagg.c
*** pgsql-float4-float8-byval/src/backend/optimizer/plan/planagg.c	2008-01-01 20:45:50.000000000 +0100
--- pgsql-float4-float8-int64-byval/src/backend/optimizer/plan/planagg.c	2008-03-31 09:34:39.000000000 +0200
*************** make_agg_subplan(PlannerInfo *root, MinM
*** 503,509 ****
  	subparse->limitOffset = NULL;
  	subparse->limitCount = (Node *) makeConst(INT8OID, -1, sizeof(int64),
  											  Int64GetDatum(1),
! 											  false, false /* not by val */ );
  
  	/*
  	 * Generate the plan for the subquery.	We already have a Path for the
--- 503,509 ----
  	subparse->limitOffset = NULL;
  	subparse->limitCount = (Node *) makeConst(INT8OID, -1, sizeof(int64),
  											  Int64GetDatum(1),
! 											  false, INT64PASSBYVALUE);
  
  	/*
  	 * Generate the plan for the subquery.	We already have a Path for the
diff -dcrpN pgsql-float4-float8-byval/src/backend/parser/parse_node.c pgsql-float4-float8-int64-byval/src/backend/parser/parse_node.c
*** pgsql-float4-float8-byval/src/backend/parser/parse_node.c	2008-01-01 20:45:51.000000000 +0100
--- pgsql-float4-float8-int64-byval/src/backend/parser/parse_node.c	2008-03-31 09:34:39.000000000 +0200
*************** make_const(Value *value)
*** 375,381 ****
  
  					typeid = INT8OID;
  					typelen = sizeof(int64);
! 					typebyval = false;	/* XXX might change someday */
  				}
  			}
  			else
--- 375,381 ----
  
  					typeid = INT8OID;
  					typelen = sizeof(int64);
! 					typebyval = INT64PASSBYVALUE;
  				}
  			}
  			else
diff -dcrpN pgsql-float4-float8-byval/src/backend/utils/adt/int8.c pgsql-float4-float8-int64-byval/src/backend/utils/adt/int8.c
*** pgsql-float4-float8-byval/src/backend/utils/adt/int8.c	2008-01-01 20:45:52.000000000 +0100
--- pgsql-float4-float8-int64-byval/src/backend/utils/adt/int8.c	2008-03-31 09:34:39.000000000 +0200
*************** int8mod(PG_FUNCTION_ARGS)
*** 657,662 ****
--- 657,663 ----
  Datum
  int8inc(PG_FUNCTION_ARGS)
  {
+ #ifndef HAVE_LONG_INT_64
  	if (fcinfo->context && IsA(fcinfo->context, AggState))
  	{
  		/*
*************** int8inc(PG_FUNCTION_ARGS)
*** 682,687 ****
--- 683,689 ----
  		PG_RETURN_POINTER(arg);
  	}
  	else
+ #endif
  	{
  		/* Not called by nodeAgg, so just do it the dumb way */
  		int64		arg = PG_GETARG_INT64(0);
diff -dcrpN pgsql-float4-float8-byval/src/backend/utils/adt/numeric.c pgsql-float4-float8-int64-byval/src/backend/utils/adt/numeric.c
*** pgsql-float4-float8-byval/src/backend/utils/adt/numeric.c	2008-01-01 20:45:52.000000000 +0100
--- pgsql-float4-float8-int64-byval/src/backend/utils/adt/numeric.c	2008-03-31 09:34:39.000000000 +0200
*************** int2_sum(PG_FUNCTION_ARGS)
*** 2550,2556 ****
--- 2550,2560 ----
  	 * If we're invoked by nodeAgg, we can cheat and modify out first
  	 * parameter in-place to avoid palloc overhead. If not, we need to return
  	 * the new value of the transition variable.
+ 	 * If we're on a 64-bit machine (HAVE_LONG_INT_64 == 1) then int64
+ 	 * is passed-by-value, there's no palloc overhead and the code below
+ 	 * becomes harmful.
  	 */
+ #ifndef HAVE_LONG_INT_64
  	if (fcinfo->context && IsA(fcinfo->context, AggState))
  	{
  		int64	   *oldsum = (int64 *) PG_GETARG_POINTER(0);
*************** int2_sum(PG_FUNCTION_ARGS)
*** 2562,2567 ****
--- 2566,2572 ----
  		PG_RETURN_POINTER(oldsum);
  	}
  	else
+ #endif
  	{
  		int64		oldsum = PG_GETARG_INT64(0);
  
*************** int4_sum(PG_FUNCTION_ARGS)
*** 2595,2601 ****
--- 2600,2610 ----
  	 * If we're invoked by nodeAgg, we can cheat and modify out first
  	 * parameter in-place to avoid palloc overhead. If not, we need to return
  	 * the new value of the transition variable.
+ 	 * If we're on a 64-bit machine (HAVE_LONG_INT_64 == 1) then int64
+ 	 * is passed-by-value, there's no palloc overhead and the code below
+ 	 * becomes harmful.
  	 */
+ #ifndef HAVE_LONG_INT_64
  	if (fcinfo->context && IsA(fcinfo->context, AggState))
  	{
  		int64	   *oldsum = (int64 *) PG_GETARG_POINTER(0);
*************** int4_sum(PG_FUNCTION_ARGS)
*** 2607,2612 ****
--- 2616,2622 ----
  		PG_RETURN_POINTER(oldsum);
  	}
  	else
+ #endif
  	{
  		int64		oldsum = PG_GETARG_INT64(0);
  
diff -dcrpN pgsql-float4-float8-byval/src/backend/utils/fmgr/fmgr.c pgsql-float4-float8-int64-byval/src/backend/utils/fmgr/fmgr.c
*** pgsql-float4-float8-byval/src/backend/utils/fmgr/fmgr.c	2008-03-31 09:34:21.000000000 +0200
--- pgsql-float4-float8-int64-byval/src/backend/utils/fmgr/fmgr.c	2008-03-31 09:34:39.000000000 +0200
*************** fmgr(Oid procedureId,...)
*** 2034,2039 ****
--- 2034,2040 ----
   *-------------------------------------------------------------------------
   */
  
+ #ifndef HAVE_LONG_INT_64
  Datum
  Int64GetDatum(int64 X)
  {
*************** Int64GetDatum(int64 X)
*** 2056,2061 ****
--- 2057,2063 ----
  	return PointerGetDatum(retval);
  #endif   /* INT64_IS_BUSTED */
  }
+ #endif
  
  Datum
  Float4GetDatum(float4 X)
diff -dcrpN pgsql-float4-float8-byval/src/include/catalog/pg_type.h pgsql-float4-float8-int64-byval/src/include/catalog/pg_type.h
*** pgsql-float4-float8-byval/src/include/catalog/pg_type.h	2008-03-31 09:34:21.000000000 +0200
--- pgsql-float4-float8-int64-byval/src/include/catalog/pg_type.h	2008-03-31 09:34:39.000000000 +0200
*************** DATA(insert OID = 19 (	name	   PGNSP PGU
*** 271,277 ****
  DESCR("63-character type for storing system identifiers");
  #define NAMEOID			19
  
! DATA(insert OID = 20 (	int8	   PGNSP PGUID	8 f b t \054 0	 0 1016 int8in int8out int8recv int8send - - - d p f 0 -1 0 _null_ _null_ ));
  DESCR("~18 digit integer, 8-byte storage");
  #define INT8OID			20
  
--- 271,277 ----
  DESCR("63-character type for storing system identifiers");
  #define NAMEOID			19
  
! DATA(insert OID = 20 (	int8	   PGNSP PGUID	8 INT64PASSBYVAL b t \054 0	 0 1016 int8in int8out int8recv int8send - - - d p f 0 -1 0 _null_ _null_ ));
  DESCR("~18 digit integer, 8-byte storage");
  #define INT8OID			20
  
diff -dcrpN pgsql-float4-float8-byval/src/include/postgres.h pgsql-float4-float8-int64-byval/src/include/postgres.h
*** pgsql-float4-float8-byval/src/include/postgres.h	2008-03-31 09:34:21.000000000 +0200
--- pgsql-float4-float8-int64-byval/src/include/postgres.h	2008-03-31 09:34:39.000000000 +0200
*************** typedef Datum *DatumPtr;
*** 314,322 ****
--- 314,332 ----
  #define GET_1_BYTE(datum)	(((Datum) (datum)) & 0x000000ff)
  #define GET_2_BYTES(datum)	(((Datum) (datum)) & 0x0000ffff)
  #define GET_4_BYTES(datum)	(((Datum) (datum)) & 0xffffffff)
+ #ifdef HAVE_LONG_INT_64
+ #define GET_8_BYTES(datum)	((Datum) (datum))
+ #else
+ #define GET_8_BYTES(datum)	(DatumGetInt64(datum))
+ #endif
  #define SET_1_BYTE(value)	(((Datum) (value)) & 0x000000ff)
  #define SET_2_BYTES(value)	(((Datum) (value)) & 0x0000ffff)
  #define SET_4_BYTES(value)	(((Datum) (value)) & 0xffffffff)
+ #ifdef HAVE_LONG_INT_64
+ #define SET_8_BYTES(value)	((Datum) (value))
+ #else
+ #define SET_8_BYTES(value)	(Int64GetDatum(value))
+ #endif
  
  /*
   * DatumGetBool
*************** typedef Datum *DatumPtr;
*** 528,547 ****
   *		Returns 64-bit integer value of a datum.
   *
   * Note: this macro hides the fact that int64 is currently a
!  * pass-by-reference type.	Someday it may be pass-by-value,
!  * at least on some platforms.
   */
  
  #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
  
  /*
   * Int64GetDatum
   *		Returns datum representation for a 64-bit integer.
   *
!  * Note: this routine returns a reference to palloc'd space.
   */
  
  extern Datum Int64GetDatum(int64 X);
  
  /*
   * DatumGetFloat4
--- 538,565 ----
   *		Returns 64-bit integer value of a datum.
   *
   * Note: this macro hides the fact that int64 is currently a
!  * pass-by-reference type. On 64-bit platforms it is pass-by-value.
   */
  
+ #ifndef HAVE_LONG_INT_64
  #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
+ #else
+ #define DatumGetInt64(X) ((int64) GET_8_BYTES(X))
+ #endif
  
  /*
   * Int64GetDatum
   *		Returns datum representation for a 64-bit integer.
   *
!  * Note: this routine returns a reference to palloc'd space
!  *       on non-native 64-bit machines.
   */
  
+ #ifndef HAVE_LONG_INT_64
  extern Datum Int64GetDatum(int64 X);
+ #else
+ #define Int64GetDatum(X) ((Datum) SET_8_BYTES(X))
+ #endif
  
  /*
   * DatumGetFloat4
*************** extern Datum Float4GetDatum(float4 X);
*** 562,569 ****
   *		Returns 8-byte floating point value of a datum.
   *
   * Note: this macro hides the fact that float8 is currently a
!  * pass-by-reference type.	Someday it may be pass-by-value,
!  * at least on some platforms.
   */
  
  #ifndef HAVE_LONG_INT_64
--- 580,586 ----
   *		Returns 8-byte floating point value of a datum.
   *
   * Note: this macro hides the fact that float8 is currently a
!  * pass-by-reference type. It is pass-by-value on 64-bit machines.
   */
  
  #ifndef HAVE_LONG_INT_64
*************** extern float8 DatumGetFloat8(Datum X);
*** 576,582 ****
   * Float8GetDatum
   *		Returns datum representation for an 8-byte floating point number.
   *
!  * Note: this routine returns a reference to palloc'd space.
   */
  
  extern Datum Float8GetDatum(float8 X);
--- 593,600 ----
   * Float8GetDatum
   *		Returns datum representation for an 8-byte floating point number.
   *
!  * Note: this routine returns a reference to palloc'd space
!  *       on non-native 64-bit platforms.
   */
  
  extern Datum Float8GetDatum(float8 X);
*************** extern Datum Float8GetDatum(float8 X);
*** 595,604 ****
   * macros.
   */
  
- #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
  #ifndef HAVE_LONG_INT_64
  #define Float8GetDatumFast(X) PointerGetDatum(&(X))
  #else
  #define Float8GetDatumFast(X) Float8GetDatum(X)
  #endif
  
--- 613,623 ----
   * macros.
   */
  
  #ifndef HAVE_LONG_INT_64
+ #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
  #define Float8GetDatumFast(X) PointerGetDatum(&(X))
  #else
+ #define Int64GetDatumFast(X)  Int64GetDatum(X)
  #define Float8GetDatumFast(X) Float8GetDatum(X)
  #endif
  
