Re: [HACKERS] Sum aggregate calculation for single precsion real - Mailing list pgsql-hackers

From Jim Nasby
Subject Re: [HACKERS] Sum aggregate calculation for single precsion real
Date
Msg-id 18f1a3f9-d00e-7a3d-94cc-00ae31a59416@BlueTreble.com
Whole thread Raw
In response to Re: [HACKERS] Sum aggregate calculation for single precsion real  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
Responses Re: [HACKERS] Sum aggregate calculation for single precsion real
Re: [HACKERS] Sum aggregate calculation for single precsion real
List pgsql-hackers
On 2/13/17 10:45 AM, Konstantin Knizhnik wrote:
> It is not true - please notice query execution time of this two queries:

I bet you'd get even less difference if you simply cast to float8 
instead of adding 0.0. Same result, no floating point addition.

>> The expectation for SUM(float4) is that you want speed and are
>> prepared to cope with the consequences.  It's easy enough to cast your
>> input to float8 if you want a wider accumulator, or to numeric if
>> you'd like more stable (not necessarily more accurate :-() results.
>> I do not think it's the database's job to make those choices for you.
>
> From my point of your it is strange and wrong expectation.
> I am choosing "float4" type for a column just because it is enough to
> represent range of data I have and I need to minimize size of record.

In other words, you've decided to trade accuracy for performance...

> But when I am calculating sum, I expect to receive more or less precise
> result. Certainly I realize that even in case of using double it is

... but now you want to trade performance for accuracy? Why would you 
expect the database to magically come to that conclusion?
-- 
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] pg_waldump's inclusion of backend headers is a mess
Next
From: Alvaro Herrera
Date:
Subject: Re: [HACKERS] Should we cacheline align PGXACT?