Re: Refactoring the Type System - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Refactoring the Type System
Date
Msg-id AANLkTinCrEKtjWX5g2SPf3DHW52rayEzDw+-KFr27+6b@mail.gmail.com
Whole thread Raw
In response to Re: Refactoring the Type System  (Daniel Farina <drfarina@acm.org>)
Responses Re: Refactoring the Type System
Re: Refactoring the Type System
List pgsql-hackers
On Sun, Nov 14, 2010 at 11:15 AM, Daniel Farina <drfarina@acm.org> wrote:
> SUM(int2) => int4
> SUM(int4) => int8
> SUM(int8) => numeric
>
> Some weaknesses:
>
> SUM, of any precision, assumes that the precision being accumulated
> into (which is also the return-precision) is enough to avoid overflow.
> This is generally the case, but there's no reason why it *must* be
> true. I'm especially looking at the int2 to int4 conversion. One could
> imagine a more interesting scenario where overflow behavior could
> occur much more easily.

Fwiw I think he's right that sum(int2) should perhaps be redefined to
return int8. As it stands all it would take is a 64k rows to
potentially overflow. It's not super likely but it is plausible and
the performance penalty to use int8 wouldn't be super big either.

int4 doesn't seem like as realistic a problem since it would take 4
billion rows and the performance penalty for using numeric would be
much higher.

-- 
greg


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Comparison with "true" in source code
Next
From: Itagaki Takahiro
Date:
Subject: Re: Comparison with "true" in source code