-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvec_stat.c
28 lines (24 loc) · 1.35 KB
/
vec_stat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
typedef struct VecAggAccumState {
Oid elementType; // input element type
int nelems; // number of elements
uint32 *vec_counts; // Element non-null count.
Datum *vec_states; // Element aggregate state.
Datum *vec_mins; // Element min value seen.
Datum *vec_maxes; // Element max value seen.
FunctionCallInfo transfn_fcinfo; // Cached function call for invoking aggregate function.
FunctionCallInfo cmp_fcinfo; // Cached function call for invoking comparison function.
} VecAggAccumState;
VecAggAccumState *
initVecAggAccumState(Oid element_type, MemoryContext rcontext, int nelems);
VecAggAccumState *
initVecAggAccumState(Oid element_type, MemoryContext rcontext, int nelems) {
VecAggAccumState *astate;
astate = (VecAggAccumState *)MemoryContextAlloc(rcontext, sizeof(VecAggAccumState));
astate->nelems = nelems;
astate->elementType = element_type;
astate->vec_counts = (uint32 *)MemoryContextAllocZero(rcontext, nelems * sizeof(uint32)); // set counts to 0 with AllocZero
astate->vec_states = (Datum *)MemoryContextAlloc(rcontext, nelems * sizeof(Datum));
astate->vec_mins = (Datum *)MemoryContextAlloc(rcontext, nelems * sizeof(Datum));
astate->vec_maxes = (Datum *)MemoryContextAlloc(rcontext, nelems * sizeof(Datum));
return astate;
}