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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to