Re: Weird function behavior from Sept 11 snapshot - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: Weird function behavior from Sept 11 snapshot
Date
Msg-id 39BE393B.38CA2E71@alumni.caltech.edu
Whole thread Raw
In response to Weird function behavior from Sept 11 snapshot  (Mike Mascari <mascarm@mascari.com>)
Responses Re: Weird function behavior from Sept 11 snapshot
List pgsql-hackers
> Is this correct behavior? All of the regression tests pass on the
> snapshot version, BTW.

This is the expected behavior, and is "correct". There was a change
recently to the aggregate functions to make them more robust. So
sum(int4) now calculates and returns a numeric result rather than an
int4.

The problem is that numeric is extremely slow compared to an int4
calculation, and I'd like us to consider doing the calculation in int4
(downside: silent overflow when dealing with non-trivial data), int8
(downside: no support on a few platforms), or float8 (downside: silent
truncation on non-trivial data).

Tom, do you recall measuring the performance difference on aggregate
functions between int4 and numeric for small-value cases? We probably
don't want to take order-of-magnitude performance hits to get this more
correct behavior, but I'm not sure what the performance actually is.

btw, Mike's function works when defined as

create function c(int4) returns int4 as 'select cast(sum(key) as int4) from test' language 'sql';
                     - Thomas


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Weird function behavior from Sept 11 snapshot
Next
From: Tom Lane
Date:
Subject: Re: strange behaviour (bug)