2009/8/26 Tom Lane <tgl@sss.pgh.pa.us>:
>> How does a float ("REAL") compare in terms of SUM()s ?
>
> Casting to float or float8 is certainly a useful alternative if you
> don't mind the potential for roundoff error. On any non-ancient
> platform those will be considerably faster than numeric. BTW,
> I think that 8.4 might be noticeably faster than 8.3 for summing
> floats, because of the switch to pass-by-value for them.
It occurs to me we could build a special case state variable which
contains a bigint or a numeric only if it actually overflows. This
would be like my other suggestion with dates only it would never be
exposed. The final function would always convert to a numeric.
Alternatively we could change the numeric data type as was proposed
aeons ago but make it more general so it stores integers that fit in a
bigint as a 64-bit integer internally. That would be more work but be
more generally useful. I'm not sure it would be possible to avoid
generating palloc garbage for sum() that way though.
--
greg
http://mit.edu/~gsstark/resume.pdf