column size and storage efficiency

Поиск
Список
Период
Сортировка
Искать

column size and storage efficiency

От:
Bruce Hyatt <brucejhyatt@yahoo.com>
Дата:
My inclination when creating tables is to create columns using varchar-sizes in increments of 10 or 5 but I suspect there must be more-efficient sizes, specifically, values like 16, 32, 64 minus header-bits.

- Is this true? Does it really have much impact on storage?
- How many bits are the headers?
- How does TOAST factor in?

Thanks,
Bruce Hyatt


      

Re: column size and storage efficiency

От:
"Sean Davis" <sdavis2@mail.nih.gov>
Дата:


On Tue, Nov 25, 2008 at 8:51 PM, Bruce Hyatt <brucejhyatt@yahoo.com> wrote:
My inclination when creating tables is to create columns using varchar-sizes in increments of 10 or 5 but I suspect there must be more-efficient sizes, specifically, values like 16, 32, 64 minus header-bits.

- Is this true? Does it really have much impact on storage?
- How many bits are the headers?
- How does TOAST factor in?

Believe it or not, specifying the varchar size has no impact on storage size.  So, a varchar and a varchar(2) if both have two characters take the same storage space. 

Toast is described pretty well in the documentation (better than I can describe it).


Sean

Re: column size and storage efficiency

От:
Bruce Hyatt <brucejhyatt@yahoo.com>
Дата:
--- On Tue, 11/25/08, Sean Davis  wrote:

> > My inclination when creating tables is to create
> columns using
> > varchar-sizes in increments of 10 or 5 but I suspect
> there must be
> > more-efficient sizes, specifically, values like 16,
> 32, 64 minus
> > header-bits.
> >
> > - Is this true? Does it really have much impact on
> storage?
> > - How many bits are the headers?
> > - How does TOAST factor in?
> 
> 
> Believe it or not, specifying the varchar size has no
> impact on storage
> size.  So, a varchar and a varchar(2) if both have two
> characters take the
> same storage space.

After thinking about it more, there can't be a direct relationship between number-of-characters and number-of-bits but what I meant was, if varchar(14) fills a block of storage, does varchar(15) use 2 blocks? Does it use twice the storage?

Bruce


      

Re: column size and storage efficiency

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Bruce Hyatt  writes:
> After thinking about it more, there can't be a direct relationship between number-of-characters and number-of-bits but what I meant was, if varchar(14) fills a block of storage, does varchar(15) use 2 blocks? Does it use twice the storage?

I think you still missed the point.  The *declared* size of a varchar
column isn't what determines storage usage, it's the *actual* size of
any particular value.  IOW, if all your strings are less than 15
characters, it makes no difference whether you declare the column
varchar(14), varchar(15), or varchar(6666).

			regards, tom lane
FAQ