On 15/12/2021, at 11:51 AM, Tom Lane <t...@sss.pgh.pa.us> wrote:
> Hmm, I think you're abusing the ArrayBuildState API.  In particular,
> what guarantees that the astate->dvalues and astate->dnulls arrays
> are long enough for what you're stuffing into them?

The length is defined in the aggregate transition function (i.e. the length of 
the first input array) and enforced there [1] so I can stuff away here.

> You should
> probably palloc temp arrays right here and then use construct_md_array
> directly instead of dealing with an ArrayBuildState.

OK, I can try that out. I did have another branch where I create the 
ArrayBuildState in this final function [2] but I still got the same result. 
I’ll try using construct_md_array instead as you suggest, thank you.

> Also, I wonder what happens when state->vec_counts[i] is zero.
> That's seemingly not your problem right now, since the ereport(NOTICE)
> is being reached; but it sure looks like trouble waiting to happen.

It can happen, but the ArrayBuildState is initialised with all 
astate->dnulls[i] as true at the start [3], so the 

if (state->vec_counts[i]) {
}

test just skips those elements and leaves them as NULL.

— m@

[1] 
https://github.com/SolarNetwork/aggs_for_vecs/blob/9e742cdc32a113268fd3c1f928c8ac724acec9f5/vec_stat_accum.c#L47-L49
 
<https://github.com/SolarNetwork/aggs_for_vecs/blob/9e742cdc32a113268fd3c1f928c8ac724acec9f5/vec_stat_accum.c#L47-L49>

[2] 
https://github.com/SolarNetwork/aggs_for_vecs/blob/ab5bea1039f865c26b899f99de866f172d125dc2/vec_agg_mean.c#L23
 
<https://github.com/SolarNetwork/aggs_for_vecs/blob/ab5bea1039f865c26b899f99de866f172d125dc2/vec_agg_mean.c#L23>

[3] 
https://github.com/SolarNetwork/aggs_for_vecs/blob/ab5bea1039f865c26b899f99de866f172d125dc2/util.c#L94-L96
 
<https://github.com/SolarNetwork/aggs_for_vecs/blob/ab5bea1039f865c26b899f99de866f172d125dc2/util.c#L94-L96>

Reply via email to