Re: Smaller data types use same disk space

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Smaller data types use same disk space
Дата
Msg-id 9603.1343181617@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Smaller data types use same disk space  (Adrian Klaver <adrian.klaver@gmail.com>)
Ответы Re: Smaller data types use same disk space  ("McGehee, Robert" <Robert.McGehee@geodecapital.com>)
Список pgsql-general
Adrian Klaver <adrian.klaver@gmail.com> writes:
> On 07/24/2012 03:21 PM, McGehee, Robert wrote:
>> I've created two tables labeled "Big" and "Small" that both store the same 10 million rows of data using 493MB and
487MBof disk space respectively. The difference is that the "Big" table uses data types that take up more space
(integerrather than smallint, float rather than real, etc). The "Big" table should need about 27 bytes/row versus 16
bytes/rowfor the "Small" table, indicating to me that the "Big" table should be 70% bigger in actual disk size. In
reality,it's only 1% bigger or 6MB (after clustering, vacuuming and analyzing). Why is this? Shouldn't the "Small"
tablebe about 110MB smaller (11 bytes for 10 million rows)? I'm estimating table size with \d+ 

> See here for the gory details:
> http://www.postgresql.org/docs/9.1/interactive/storage-page-layout.html

> See in particular:
> Table 55-4. HeapTupleHeaderData Layout
>  From the text:
> ""All table rows are structured in the same way. There is a fixed-size
> header (occupying 23 bytes on most machines.." which breaks you
> assumption of the Big/Small row size comparison.

Aside from the tuple header, there are alignment considerations that you
have to allow for.  So for instance, if your columns are int, smallint,
int, that will take the same amount of space as 3 ints, because the
savings disappears into alignment of the third int.  You need two
adjacent smallints to get any benefit.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: jtkells
Дата:
Сообщение: Re: insert binary data into a table column with psql
Следующее
От: Tom Lane
Дата:
Сообщение: Re: insert binary data into a table column with psql