Using a pointer as statetype for an aggregate

Started by Florian Pflugalmost 20 years ago3 messagesgeneral
Jump to latest
#1Florian Pflug
fgp@phlo.org

Hi

I've now completed my implementation of a collect_distinct aggregate, and
it seems to work. My statetype is basically a pointer to a hashtable (allocated
from the aggcontext). Since using internal as statetype is unsupported,
I use int8, and just cast my pointer back and forth from int8.

It appears to work on both my dev (32bit) and my production (64bit) machine,
and it doesn't crash even when used heavily. Is there some drawback to my
approach? If not - why doesn't postgres allow "internal" as statetype?

greetings, Florian Pflug

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Florian Pflug (#1)
Re: Using a pointer as statetype for an aggregate

"Florian G. Pflug" <fgp@phlo.org> writes:

why doesn't postgres allow "internal" as statetype?

Because it's not a type. If it were, it certainly wouldn't have the
semantics you seem to hope for (ie, "pass by reference type but don't
actually try to copy the bits")

regards, tom lane

#3Florian Pflug
fgp@phlo.org
In reply to: Tom Lane (#2)
Re: Using a pointer as statetype for an aggregate

Tom Lane wrote:

"Florian G. Pflug" <fgp@phlo.org> writes:

why doesn't postgres allow "internal" as statetype?

Because it's not a type. If it were, it certainly wouldn't have the
semantics you seem to hope for (ie, "pass by reference type but don't
actually try to copy the bits")

Could I somehow define a type that would fit my needs. Ideally,
it would be
1) pass-by-value
2) 4byte long on 32bit machines
3) 8byte long on 64bit machines
4) Only "0" can be castet to my type, resulting in an all-zero representation
5) Impossible to use as a column type
6) Provide no output function, because the value is meaningless to the user.

I'd think I'd manage to get 4, 6 and maybe 5 working by playing with "create type".
But I can't see how I could make 1,2 and 3 work. Is an 8byte pass-by-value type
even possible?

I'd realy like to get rid of that ugly casting to int8.. It just seems soooo wrong ;-)

greetings, Florian Pflug