Re: Sum aggregate calculation for single precsion real

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Sum aggregate calculation for single precsion real
Date: 2017-02-14 13:59:00
Message-ID: 18f1a3f9-d00e-7a3d-94cc-00ae31a59416@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2017-02-14 14:13:16 Re: Should we cacheline align PGXACT?
Previous Message Robert Haas 2017-02-14 13:55:14 Re: pg_waldump's inclusion of backend headers is a mess