Re: [PATCH] Negative Transition Aggregate Functions (WIP)

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, Florian Pflug <fgp(at)phlo(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Kevin Grittner <kgrittn(at)ymail(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Greg Stark <stark(at)mit(dot)edu>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Negative Transition Aggregate Functions (WIP)
Date: 2014-01-16 19:07:33
Message-ID: 52D82DF5.6050907@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 01/16/2014 08:59 PM, Tom Lane wrote:
> Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> writes:
>> I propose that we reimplement sum(bigint) in a more efficient way: For
>> the internal state, let's use an int8 and a numeric overflow field. The
>> transition function adds to the int8 variable, and checks for overflow.
>> On overflow, increment the numeric field by one. In the final function,
>> multiply the numeric by 2^64, and add the residual int8 value.
>
> It'd probably be sufficient to handle it as two int64 fields (handmade
> 128-bit arithmetic, or maybe even not so handmade if that ever gets
> reasonably common among C compilers).

True. That would be sufficient for summing 2^64 int8s of INT64_MAX. That
sounds like enough, especially considering that that count() will
overflow after that too.

> You're assuming the final output is still numeric, right?

Yep.

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-01-16 19:13:00 Re: [PATCH] Negative Transition Aggregate Functions (WIP)
Previous Message Andres Freund 2014-01-16 19:05:33 Re: Patch for fail-back without fresh backup