Re: reducing NUMERIC size for 9.1

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: reducing NUMERIC size for 9.1
Date: 2010-08-03 23:52:18
Message-ID: AANLkTim5iZanHc6AKc7MUg52Cz92wSdX5LW+by4KVNXJ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 30, 2010 at 9:55 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Fri, Jul 30, 2010 at 2:08 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>>> ....  Maybe something like this,
>>> obviously with a suitable comment which I haven't written yet:
>>
>>>     numeric_digits = (precision + 6) / 4;
>>>     return (numeric_digits * sizeof(int16)) + NUMERIC_HDRSZ;
>>
>> This is OK for the base-10K case, but there's still code in there
>> for the base-10 and base-100 cases.  Can you express this logic in
>> terms of DEC_DIGITS and sizeof(NumericDigit) ?  I think you might
>> find it was actually clearer that way, cf Polya.
>
> It appears to work out to:
>
>    numeric_digits = (precision + 2 * (DEC_DIGITS - 1)) / DEC_DIGITS
>    return (numeric_digits * sizeof(NumericDigits)) + NUMERIC_HDRSZ;
>
> The smallest value for precision which requires 2 numeric_digits is
> always 2; and the required number of numeric_digits increases by 1
> each time the number of base-10 digits increases by DEC_DIGITS.

And here is a patch implementing that.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

Attachment Content-Type Size
numeric_maximum_size.patch application/octet-stream 1.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Smith 2010-08-04 00:10:57 Re: Postgres as Historian
Previous Message Robert Haas 2010-08-03 23:33:23 Re: [COMMITTERS] pgsql: Stamp HEAD as 9.1devel.