Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>, Gene Sokolov <hook(at)aktrad(dot)ru>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )
Date: 1999-06-16 16:08:02
Message-ID: 25387.929549282@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu> writes:
> For int2/int4, we could bump the accumulator to int8 (certainly faster
> than our numeric implementation?), but there are a very few platforms
> which don't support int8 and we shouldn't break the aggregates for
> them.

Right, that's why I preferred the idea of using float8.

Note that any reasonable floating-point implementation will deliver an
exact result for the sum of integer inputs, up to the point at which the
sum exceeds the number of mantissa bits in a float (2^52 or so in IEEE
float8). After that you start to lose accuracy. Using int8 would give
an exact sum up to 2^63, but if we want to start delivering a fractional
average then float still looks like a better deal...

> Tom, do you think that a hack in the aggregate support code which
> compares the pointer returned to the pointer input, then pfree'ing the
> input area if they differ, would fix the major leakage?

Yeah, that would probably work OK, although you'd have to be careful of
the initial condition --- is the initial value always safely pfreeable?

> We could even have a backend global variable which enables/disables
> the feature to allow performance tuning.

Seems unnecessary.

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message José Soares 1999-06-16 16:12:11 Re: [HACKERS] 6.5.0 - Overflow bug in AVG( )
Previous Message Bruce Momjian 1999-06-16 15:58:57 Re: [HACKERS] SET QUERY_LIMIT bug report