Re: BUG #12675: BIGINT Datatype performance - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject Re: BUG #12675: BIGINT Datatype performance
Date
Msg-id 54C778BF.3000205@vmware.com
Whole thread Raw
In response to BUG #12675: BIGINT Datatype performance  (derek.anderson@mspmac.org)
List pgsql-bugs
On 01/26/2015 11:04 PM, derek.anderson@mspmac.org wrote:
> The following bug has been logged on the website:
>
> Bug reference:      12675
> Logged by:          Derek Anderson
> Email address:      derek.anderson@mspmac.org
> PostgreSQL version: 9.4.0
> Operating system:   Linux
> Description:
>
> I did some testing on bigint vs double precision datatype performance for a
> project we have going on here.
>
> To my surprise, I found the double precision (floating) was well over 200%
> faster than bigint in aggregate functions.  I don't know if this qualifies
> as a bug, but it sure seems odd considering non-floating type datatypes
> usually perform much faster than floating.
>
> Please contact me if you wish to discuss.

The built-in aggregates on bigint, like sum and avg, use numeric
internally because the sum of bigints can easily be too large to fit in
a bigint. Their return type is also numeric for the same reason.
Arithmetic on numeric is much slower than on double.

There is a patch being discussed that would help with that, for 9.5. See
http://www.postgresql.org/message-id/544BB5F1.50709@proxel.se. With the
patch, the aggregates would use a 128-bit integer type for the internal
calculations, making them much faster.

- Heikki

pgsql-bugs by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: BUG #12679: temprary table not exists when close session and reconnect
Next
From: ousema2003@yahoo.fr
Date:
Subject: BUG #12681: Cannot Read Refcursor from JAVA