From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Andrus <kobruleht2(at)hot(dot)ee> |
Cc: | Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to find greatest record before known values fast |
Date: | 2014-10-03 20:45:23 |
Message-ID: | CAHyXU0yUA+r18KA1d3Lu6Eopr47V2S1N1u5zUmBA9r4TTsW3gg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Oct 3, 2014 at 3:28 PM, Andrus <kobruleht2(at)hot(dot)ee> wrote:
> Hi!
>
> Thank you for explanations.
>
>> the char type pads out the fields on disk.
>
>
> It looks like you wrote that char takes more disk space.
>
> from
>
> http://www.pgcon.org/2013/schedule/attachments/269_tour-of-postgresql-data-types.pdf
>
> page 28:
>
> Unlike many
> databases, char(n) is NOT stored as afixed-sizedfield in
> Postgres. It is treated exactly the sameas
> varchar(n)except for being padded
>
> So char type does not take more space than varchar.
I beg to differ:
postgres=# create table t1(v char(100));
CREATE TABLE
postgres=# create table t2(v varchar(100));
CREATE TABLE
postgres=# insert into t1 select '' from generate_series(1,1000000);
INSERT 0 1000000
Time: 5951.023 ms
postgres=# insert into t2 select '' from generate_series(1,1000000);
INSERT 0 1000000
Time: 2083.323 ms
postgres=# select pg_size_pretty(pg_relation_size(oid)) from pg_class
where relname = 't1';
pg_size_pretty
────────────────
128 MB
(1 row)
postgres=# select pg_size_pretty(pg_relation_size(oid)) from pg_class
where relname = 't2';
pg_size_pretty
────────────────
35 MB
(1 row)
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Alan Hodgson | 2014-10-03 21:40:19 | Re: Processor usage/tuning question |
Previous Message | Andrus | 2014-10-03 20:28:27 | Re: How to find greatest record before known values fast |