Skip to content

Commit

Permalink
Switch to uint32 for veccounts so we have a platform-independent know…
Browse files Browse the repository at this point in the history
…n size and can handle more input rows than an int32 could.
  • Loading branch information
msqr committed Nov 26, 2021
1 parent 2e997c1 commit e52e6b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hist_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ hist_2d_finalfn(PG_FUNCTION_ARGS)
if (state == NULL) PG_RETURN_NULL();

for (i = 0; i < state->state.nelems; i++) {
state->state.dvalues[i] = Int32GetDatum((int32)state->veccounts[i]);
state->state.dvalues[i] = UInt32GetDatum(state->veccounts[i]);
}

dims[0] = state->vecvalues[0].i32;
Expand Down
2 changes: 1 addition & 1 deletion hist_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ hist_md_finalfn(PG_FUNCTION_ARGS)
if (state == NULL) PG_RETURN_NULL();

for (i = 0; i < state->state.nelems; i++) {
state->state.dvalues[i] = Int32GetDatum((int32)state->veccounts[i]);
state->state.dvalues[i] = UInt32GetDatum(state->veccounts[i]);
}

dims = MemoryContextAlloc(aggContext, HIST_MD_DIMENSIONS(state) * sizeof(int));
Expand Down
8 changes: 4 additions & 4 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct VecArrayBuildState {
ArrayBuildState state;
Oid inputElementType;
pgnum *vecvalues; // The current aggregate result for each position.
int *veccounts; // How many values in this position are not null.
uint32 *veccounts; // How many values in this position are not null.
pgnum *vectmpvalues; // Intermediate results if we need them.
} VecArrayBuildState;

Expand Down Expand Up @@ -57,9 +57,9 @@ initVecArrayResultWithNulls(Oid input_element_type, Oid state_element_type, Memo
astate->inputElementType = input_element_type;
astate->vecvalues = (pgnum *)
MemoryContextAlloc(rcontext, astate->state.alen * sizeof(pgnum));
astate->veccounts = (int *)
MemoryContextAlloc(rcontext, astate->state.alen * sizeof(int));
memset(astate->veccounts, 0, astate->state.alen * sizeof(int));
astate->veccounts = (uint32 *)
MemoryContextAlloc(rcontext, astate->state.alen * sizeof(uint32));
memset(astate->veccounts, 0, astate->state.alen * sizeof(uint32));
astate->vectmpvalues = (pgnum *)
MemoryContextAlloc(rcontext, astate->state.alen * sizeof(pgnum));

Expand Down

0 comments on commit e52e6b1

Please sign in to comment.