aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/numeric.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-02-08 20:39:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-02-08 20:39:52 +0000
commitd5768dce10576c2fb1254c03fb29475d4fac6bb4 (patch)
tree7b971cb06b6671d66df26027909e1d9355d65d14 /src/backend/utils/adt/numeric.c
parent4d3d2e2b0325e3d6d524c6801b7439d3aaea4520 (diff)
downloadpostgresql-d5768dce10576c2fb1254c03fb29475d4fac6bb4.tar.gz
postgresql-d5768dce10576c2fb1254c03fb29475d4fac6bb4.zip
Create an official API function for C functions to use to check if they are
being called as aggregates, and to get the aggregate transition state memory context if needed. Use it instead of poking directly into AggState and WindowAggState in places that shouldn't know so much. We should have done this in 8.4, probably, but better late than never. Revised version of a patch by Hitoshi Harada.
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r--src/backend/utils/adt/numeric.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 2892b5d2fbf..1b9f7944959 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -14,7 +14,7 @@
* Copyright (c) 1998-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.121 2010/01/07 04:53:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.122 2010/02/08 20:39:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2679,16 +2679,14 @@ int2_sum(PG_FUNCTION_ARGS)
}
/*
- * If we're invoked by nodeAgg, we can cheat and modify our first
+ * If we're invoked as an aggregate, we can cheat and modify our first
* parameter in-place to avoid palloc overhead. If not, we need to return
* the new value of the transition variable. (If int8 is pass-by-value,
* then of course this is useless as well as incorrect, so just ifdef it
* out.)
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
- if (fcinfo->context &&
- (IsA(fcinfo->context, AggState) ||
- IsA(fcinfo->context, WindowAggState)))
+ if (AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
@@ -2730,16 +2728,14 @@ int4_sum(PG_FUNCTION_ARGS)
}
/*
- * If we're invoked by nodeAgg, we can cheat and modify our first
+ * If we're invoked as an aggregate, we can cheat and modify our first
* parameter in-place to avoid palloc overhead. If not, we need to return
* the new value of the transition variable. (If int8 is pass-by-value,
* then of course this is useless as well as incorrect, so just ifdef it
* out.)
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
- if (fcinfo->context &&
- (IsA(fcinfo->context, AggState) ||
- IsA(fcinfo->context, WindowAggState)))
+ if (AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
@@ -2782,7 +2778,7 @@ int8_sum(PG_FUNCTION_ARGS)
}
/*
- * Note that we cannot special-case the nodeAgg case here, as we do for
+ * Note that we cannot special-case the aggregate case here, as we do for
* int2_sum and int4_sum: numeric is of variable size, so we cannot modify
* our first parameter in-place.
*/
@@ -2820,13 +2816,11 @@ int2_avg_accum(PG_FUNCTION_ARGS)
Int8TransTypeData *transdata;
/*
- * If we're invoked by nodeAgg, we can cheat and modify our first
+ * If we're invoked as an aggregate, we can cheat and modify our first
* parameter in-place to reduce palloc overhead. Otherwise we need to make
* a copy of it before scribbling on it.
*/
- if (fcinfo->context &&
- (IsA(fcinfo->context, AggState) ||
- IsA(fcinfo->context, WindowAggState)))
+ if (AggCheckCallContext(fcinfo, NULL))
transarray = PG_GETARG_ARRAYTYPE_P(0);
else
transarray = PG_GETARG_ARRAYTYPE_P_COPY(0);
@@ -2850,13 +2844,11 @@ int4_avg_accum(PG_FUNCTION_ARGS)
Int8TransTypeData *transdata;
/*
- * If we're invoked by nodeAgg, we can cheat and modify our first
+ * If we're invoked as an aggregate, we can cheat and modify our first
* parameter in-place to reduce palloc overhead. Otherwise we need to make
* a copy of it before scribbling on it.
*/
- if (fcinfo->context &&
- (IsA(fcinfo->context, AggState) ||
- IsA(fcinfo->context, WindowAggState)))
+ if (AggCheckCallContext(fcinfo, NULL))
transarray = PG_GETARG_ARRAYTYPE_P(0);
else
transarray = PG_GETARG_ARRAYTYPE_P_COPY(0);