diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-17 03:05:41 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-17 03:05:41 +0000 |
commit | bec98a31c55a4f799b398d01541e68d7c086bb81 (patch) | |
tree | 14924bb5da2bc0a0f9bfac1aa5b32256fd996b9c /src/include/utils | |
parent | 139f19c30221968e7d3bf64fe303cb41517e4601 (diff) | |
download | postgresql-bec98a31c55a4f799b398d01541e68d7c086bb81.tar.gz postgresql-bec98a31c55a4f799b398d01541e68d7c086bb81.zip |
Revise aggregate functions per earlier discussions in pghackers.
There's now only one transition value and transition function.
NULL handling in aggregates is a lot cleaner. Also, use Numeric
accumulators instead of integer accumulators for sum/avg on integer
datatypes --- this avoids overflow at the cost of being a little slower.
Implement VARIANCE() and STDDEV() aggregates in the standard backend.
Also, enable new LIKE selectivity estimators by default. Unrelated
change, but as long as I had to force initdb anyway...
Diffstat (limited to 'src/include/utils')
-rw-r--r-- | src/include/utils/array.h | 29 | ||||
-rw-r--r-- | src/include/utils/builtins.h | 27 | ||||
-rw-r--r-- | src/include/utils/numeric.h | 14 | ||||
-rw-r--r-- | src/include/utils/timestamp.h | 4 |
4 files changed, 52 insertions, 22 deletions
diff --git a/src/include/utils/array.h b/src/include/utils/array.h index 4fb296671d7..4d915e0665f 100644 --- a/src/include/utils/array.h +++ b/src/include/utils/array.h @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: array.h,v 1.25 2000/06/13 07:35:30 tgl Exp $ + * $Id: array.h,v 1.26 2000/07/17 03:05:32 tgl Exp $ * * NOTES * XXX the data array should be MAXALIGN'd -- notice that the array @@ -24,16 +24,28 @@ #define ARRAY_H #include "fmgr.h" -#include "utils/memutils.h" +/* + * Arrays are varlena objects, so must meet the varlena convention that + * the first int32 of the object contains the total object size in bytes. + */ typedef struct { - int size; /* total array size (in bytes) */ + int32 size; /* total array size (varlena requirement) */ int ndim; /* # of dimensions */ int flags; /* implementation flags */ } ArrayType; /* + * fmgr macros for array objects + */ +#define DatumGetArrayTypeP(X) ((ArrayType *) PG_DETOAST_DATUM(X)) +#define DatumGetArrayTypePCopy(X) ((ArrayType *) PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_ARRAYTYPE_P(n) DatumGetArrayTypeP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_ARRAYTYPE_P(x) PG_RETURN_POINTER(x) + +/* * bitmask of ArrayType flags field: * 1st bit - large object flag * 2nd bit - chunk flag (array is chunked if set) @@ -43,11 +55,9 @@ typedef struct #define ARR_CHK_FLAG (0x2) #define ARR_OBJ_MASK (0x1c) -#define ARR_FLAGS(a) ((ArrayType *) a)->flags #define ARR_SIZE(a) (((ArrayType *) a)->size) - #define ARR_NDIM(a) (((ArrayType *) a)->ndim) -#define ARR_NDIM_PTR(a) (&(((ArrayType *) a)->ndim)) +#define ARR_FLAGS(a) (((ArrayType *) a)->flags) #define ARR_IS_LO(a) \ (((ArrayType *) a)->flags & ARR_LOB_FLAG) @@ -102,7 +112,6 @@ typedef struct #define RETURN_NULL(type) do { *isNull = true; return (type) 0; } while (0) #define NAME_LEN 30 -#define MAX_BUFF_SIZE BLCKSZ typedef struct { @@ -134,6 +143,12 @@ extern ArrayType *array_assgn(ArrayType *array, int nSubscripts, bool elmbyval, int elmlen, bool *isNull); extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType); +extern ArrayType *construct_array(Datum *elems, int nelems, + bool elmbyval, int elmlen, char elmalign); +extern void deconstruct_array(ArrayType *array, + bool elmbyval, int elmlen, char elmalign, + Datum **elemsp, int *nelemsp); + extern int _LOtransfer(char **destfd, int size, int nitems, char **srcfd, int isSrcLO, int isDestLO); extern char *_array_newLO(int *fd, int flag); diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index 07e732f1e86..db772d6ecf2 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: builtins.h,v 1.123 2000/07/09 21:30:21 petere Exp $ + * $Id: builtins.h,v 1.124 2000/07/17 03:05:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -110,7 +110,6 @@ extern Datum int2mi(PG_FUNCTION_ARGS); extern Datum int2mul(PG_FUNCTION_ARGS); extern Datum int2div(PG_FUNCTION_ARGS); extern Datum int2abs(PG_FUNCTION_ARGS); -extern Datum int2inc(PG_FUNCTION_ARGS); extern Datum int24pl(PG_FUNCTION_ARGS); extern Datum int24mi(PG_FUNCTION_ARGS); extern Datum int24mul(PG_FUNCTION_ARGS); @@ -207,12 +206,10 @@ extern float32 float4pl(float32 arg1, float32 arg2); extern float32 float4mi(float32 arg1, float32 arg2); extern float32 float4mul(float32 arg1, float32 arg2); extern float32 float4div(float32 arg1, float32 arg2); -extern float32 float4inc(float32 arg1); extern float64 float8pl(float64 arg1, float64 arg2); extern float64 float8mi(float64 arg1, float64 arg2); extern float64 float8mul(float64 arg1, float64 arg2); extern float64 float8div(float64 arg1, float64 arg2); -extern float64 float8inc(float64 arg1); extern bool float4eq(float32 arg1, float32 arg2); extern bool float4ne(float32 arg1, float32 arg2); extern bool float4lt(float32 arg1, float32 arg2); @@ -261,6 +258,11 @@ extern float64 radians(float64 arg1); extern float64 dtan(float64 arg1); extern float64 drandom(void); extern int32 setseed(float64 seed); +extern Datum float8_accum(PG_FUNCTION_ARGS); +extern Datum float4_accum(PG_FUNCTION_ARGS); +extern Datum float8_avg(PG_FUNCTION_ARGS); +extern Datum float8_variance(PG_FUNCTION_ARGS); +extern Datum float8_stddev(PG_FUNCTION_ARGS); extern float64 float48pl(float32 arg1, float64 arg2); extern float64 float48mi(float32 arg1, float64 arg2); @@ -545,7 +547,6 @@ extern Numeric numeric_mul(Numeric num1, Numeric num2); extern Numeric numeric_div(Numeric num1, Numeric num2); extern Numeric numeric_mod(Numeric num1, Numeric num2); extern Numeric numeric_inc(Numeric num); -extern Numeric numeric_dec(Numeric num); extern Numeric numeric_smaller(Numeric num1, Numeric num2); extern Numeric numeric_larger(Numeric num1, Numeric num2); extern Numeric numeric_sqrt(Numeric num); @@ -555,14 +556,24 @@ extern Numeric numeric_log(Numeric num1, Numeric num2); extern Numeric numeric_power(Numeric num1, Numeric num2); extern Datum int4_numeric(PG_FUNCTION_ARGS); extern int32 numeric_int4(Numeric num); -extern Numeric int8_numeric(int64 *val); +extern Datum int8_numeric(PG_FUNCTION_ARGS); extern int64 *numeric_int8(Numeric num); extern Datum int2_numeric(PG_FUNCTION_ARGS); extern Datum numeric_int2(PG_FUNCTION_ARGS); -extern Numeric float4_numeric(float32 val); -extern float32 numeric_float4(Numeric num); extern Numeric float8_numeric(float64 val); extern float64 numeric_float8(Numeric num); +extern Numeric float4_numeric(float32 val); +extern float32 numeric_float4(Numeric num); +extern Datum numeric_accum(PG_FUNCTION_ARGS); +extern Datum int2_accum(PG_FUNCTION_ARGS); +extern Datum int4_accum(PG_FUNCTION_ARGS); +extern Datum int8_accum(PG_FUNCTION_ARGS); +extern Datum numeric_avg(PG_FUNCTION_ARGS); +extern Datum numeric_variance(PG_FUNCTION_ARGS); +extern Datum numeric_stddev(PG_FUNCTION_ARGS); +extern Datum int2_sum(PG_FUNCTION_ARGS); +extern Datum int4_sum(PG_FUNCTION_ARGS); +extern Datum int8_sum(PG_FUNCTION_ARGS); /* lztext.c */ extern lztext *lztextin(char *str); diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h index 1a0dd692dbd..8e6412eabee 100644 --- a/src/include/utils/numeric.h +++ b/src/include/utils/numeric.h @@ -5,7 +5,7 @@ * * 1998 Jan Wieck * - * $Header: /cvsroot/pgsql/src/include/utils/numeric.h,v 1.10 2000/06/13 07:35:31 tgl Exp $ + * $Header: /cvsroot/pgsql/src/include/utils/numeric.h,v 1.11 2000/07/17 03:05:32 tgl Exp $ * * ---------- */ @@ -55,7 +55,7 @@ * all leading and trailing zeroes (except there will be a trailing zero * in the last byte, if the number of digits is odd). In particular, * if the value is zero, there will be no digits at all! The weight is - * arbitrary in this case, but we normally set it to zero. + * arbitrary in that case, but we normally set it to zero. * ---------- */ typedef struct NumericData @@ -75,9 +75,11 @@ typedef NumericData *Numeric; * fmgr interface macros */ -#define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X)) -#define NumericGetDatum(X) PointerGetDatum(X) -#define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n)) -#define PG_RETURN_NUMERIC(x) return NumericGetDatum(x) +#define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X)) +#define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X)) +#define NumericGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n)) +#define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_NUMERIC(x) return NumericGetDatum(x) #endif /* _PG_NUMERIC_H_ */ diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index 61db8e7d206..b848c894a04 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: timestamp.h,v 1.8 2000/06/19 03:54:48 tgl Exp $ + * $Id: timestamp.h,v 1.9 2000/07/17 03:05:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -171,6 +171,8 @@ extern Datum interval_mi(PG_FUNCTION_ARGS); extern Datum interval_mul(PG_FUNCTION_ARGS); extern Datum mul_d_interval(PG_FUNCTION_ARGS); extern Datum interval_div(PG_FUNCTION_ARGS); +extern Datum interval_accum(PG_FUNCTION_ARGS); +extern Datum interval_avg(PG_FUNCTION_ARGS); extern Datum timestamp_mi(PG_FUNCTION_ARGS); extern Datum timestamp_pl_span(PG_FUNCTION_ARGS); |