Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Arthur Silva
On Sat, Oct 25, 2014 at 12:38 PM, Andreas Karlsson andr...@proxel.se wrote: Hi, There was recently talk about if we should start using 128-bit integers (where available) to speed up the aggregate functions over integers which uses numeric for their internal state. So I hacked together a

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Merlin Moncure
On Sat, Oct 25, 2014 at 9:38 AM, Andreas Karlsson andr...@proxel.se wrote: Hi, There was recently talk about if we should start using 128-bit integers (where available) to speed up the aggregate functions over integers which uses numeric for their internal state. So I hacked together a patch

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Andres Freund
On 2014-10-28 11:05:11 -0200, Arthur Silva wrote: On Sat, Oct 25, 2014 at 12:38 PM, Andreas Karlsson andr...@proxel.se As far as I'm aware int128 types are supported on every major compiler when compiling for 64bit platforms. Right? Depends on what you call major. IIRC some not that old msvc

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Andreas Karlsson
On 10/28/2014 02:05 PM, Arthur Silva wrote: As far as I'm aware int128 types are supported on every major compiler when compiling for 64bit platforms. Right? Both gcc and clang support __int128_t, but I do not know about other compilers like icc and MSVC. Andreas -- Sent via

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Heikki Linnakangas
On 10/28/2014 03:24 PM, Andres Freund wrote: On 2014-10-28 11:05:11 -0200, Arthur Silva wrote: On Sat, Oct 25, 2014 at 12:38 PM, Andreas Karlsson andr...@proxel.se As far as I'm aware int128 types are supported on every major compiler when compiling for 64bit platforms. Right? Depends on what

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Andres Freund
On 2014-10-28 15:54:30 +0200, Heikki Linnakangas wrote: On 10/28/2014 03:24 PM, Andres Freund wrote: On 2014-10-28 11:05:11 -0200, Arthur Silva wrote: On Sat, Oct 25, 2014 at 12:38 PM, Andreas Karlsson andr...@proxel.se As far as I'm aware int128 types are supported on every major compiler

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Tom Lane
Heikki Linnakangas hlinnakan...@vmware.com writes: It wouldn't be too hard to just do: struct { int64 high_bits; uint64 low_bits; } pg_int128; and some macros for the + - etc. operators. It might be less work than trying to deal with the portability issues of a native C

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Heikki Linnakangas
On 10/28/2014 04:06 PM, Tom Lane wrote: Heikki Linnakangas hlinnakan...@vmware.com writes: It wouldn't be too hard to just do: struct { int64 high_bits; uint64 low_bits; } pg_int128; and some macros for the + - etc. operators. It might be less work than trying to deal with the

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Andreas Karlsson
On 10/28/2014 03:40 PM, Heikki Linnakangas wrote: The patch doesn't do division with the 128-bit integers. It only does addition and multiplication. Those are pretty straightforward to implement. The patch uses division when converting from __int128_t to Numeric. - Andreas -- Sent via

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Heikki Linnakangas
On 10/28/2014 04:47 PM, Andreas Karlsson wrote: On 10/28/2014 03:40 PM, Heikki Linnakangas wrote: The patch doesn't do division with the 128-bit integers. It only does addition and multiplication. Those are pretty straightforward to implement. The patch uses division when converting from

Re: [HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-28 Thread Andreas Karlsson
On 10/28/2014 04:01 PM, Heikki Linnakangas wrote: Moving on to other issues, isn't 128 bits too small to store the squares of the processed numbers? That could overflow.. Yeah, which is why stddev_*(int8) and var_*(int8) still have to use Numeric in the aggregate state. For the int2 and int4

[HACKERS] [WIP Patch] Using 128-bit integers for sum, avg and statistics aggregates

2014-10-25 Thread Andreas Karlsson
Hi, There was recently talk about if we should start using 128-bit integers (where available) to speed up the aggregate functions over integers which uses numeric for their internal state. So I hacked together a patch for this to see what the performance gain would be. Previous thread: