Re: Patch for units in postgresql.conf - Mailing list pgsql-patches

From Zdenek Kotala
Subject Re: Patch for units in postgresql.conf
Date
Msg-id 44C750E3.5090205@sun.com
Whole thread Raw
In response to Patch for units in postgresql.conf  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-patches
Peter Eisentraut wrote:
> Here is a preliminary patch for units in postgresql.conf (and SET and so on,
> of course).  It currently supports memory units only.  Time units would be
> similar.  Let me know if you have comments.

The concept is good. However, parse should generate overflow. You
multiply first time and convert value to bytes and after you divide it.
  By my opinion, better solution is compute number and
direction(multiply/divide) of shift bits and do it in one step.

There is small concept:

------------
    int shift_tab[][] = { { 0 , -10, -20, -30 },
             { 10,  0 , -10, -20 },
             { 20,  10,  0 , -10 },
             { 30,  20,  10,  0  },
             { shift for block   } };

if (strcmp(endptr, "kB") == 0)
        {
            shift = shift_tab[1][ flags & ..... ];
            used = true;
            endptr += 2;
        }

if( shift < 0 )
   val >> = shift;
else
{
   int mask = ~0;
   mask << = shift;
   if( val & mask == 0 )
     val << = shift;
   else
     ....!!! Overflow
}

--------------------


I am not sure but I expect that values are stored in native format
(native unit). I think, there is not reason to divide/multiply it?


> @@ -5082,8 +5124,34 @@
>                      val = (*conf->show_hook) ();
>                  else
>                  {
> -                    snprintf(buffer, sizeof(buffer), "%d",
> -                             *conf->variable);
> +                    char unit[3];
> +                    int result = *conf->variable;
> +
> +                    if (record->flags & (GUC_UNIT_KB|GUC_UNIT_BLOCKS))
> +                    {
> +                        if (record->flags & GUC_UNIT_BLOCKS)
> +                            result *= BLCKSZ/1024;
> +


        Zdenek

pgsql-patches by date:

Previous
From: Joachim Wieland
Date:
Subject: Re: Time zone definitions to config files
Next
From: Gregory Stark
Date:
Subject: Re: patch implementing the multi-argument aggregates (SOC project)