Re: Patch for units in postgresql.conf
От | Zdenek Kotala |
---|---|
Тема | Re: Patch for units in postgresql.conf |
Дата | |
Msg-id | 44C750E3.5090205@sun.com обсуждение исходный текст |
Ответ на | Patch for units in postgresql.conf (Peter Eisentraut <peter_e@gmx.net>) |
Список | 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 по дате отправления: