Speed & Memory Management

Lists: pgsql-admin
From: "Kris" <kkiger(at)depauw(dot)edu>
To: pgsql-admin(at)postgresql(dot)org
Subject: Speed & Memory Management
Date: 2003-03-31 22:08:26
Message-ID: b6ae8p$30p7$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hello all. I am designing a database that will could potentially grow to
have millions of tuples associated with it. My thought is that because I
will likely have many updates/inserts/deletes occurring I should set each
column that requires text to a static ammount (ie using char(30) instead of
text). However, this looks to be a double edged sword, since selecting from
the db is my largest concern (with updates a very close second). When I
pull these values back out of the db, it seems I am going to have to trim
each returned value (when I pull a ten character string out of this field,
it returns the 10 char string as well as 20 whitespaces.). I am trying to
assign a weight to each of these scenarios and figure out which is the
lesser of the two evils. If anyone has a suggestion of how I may circumvent
this issue or which possibility may work best, it would be greatly
appreciated. Thanks

Kris


From: GB <GB(at)nirvana(dot)nil>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Speed & Memory Management
Date: 2003-04-01 07:02:16
Message-ID: 1049180536.836564@tux2.hamburg.gft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

How about using varchar(30)?

GB


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Kris <kkiger(at)depauw(dot)edu>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Speed & Memory Management
Date: 2003-04-01 18:41:27
Message-ID: 1049222487.13853.2110.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Unless your application requires a 30 character limit at the logical
level, use text.

Robert Treat

On Mon, 2003-03-31 at 17:08, Kris wrote:
> Hello all. I am designing a database that will could potentially grow to
> have millions of tuples associated with it. My thought is that because I
> will likely have many updates/inserts/deletes occurring I should set each
> column that requires text to a static ammount (ie using char(30) instead of
> text). However, this looks to be a double edged sword, since selecting from
> the db is my largest concern (with updates a very close second). When I
> pull these values back out of the db, it seems I am going to have to trim
> each returned value (when I pull a ten character string out of this field,
> it returns the 10 char string as well as 20 whitespaces.). I am trying to
> assign a weight to each of these scenarios and figure out which is the
> lesser of the two evils. If anyone has a suggestion of how I may circumvent
> this issue or which possibility may work best, it would be greatly
> appreciated. Thanks
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: Kris <kkiger(at)depauw(dot)edu>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Speed & Memory Management
Date: 2003-04-01 19:07:57
Message-ID: 2296.1049224077@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> Unless your application requires a 30 character limit at the logical
> level, use text.

And if it does, use varchar(30). I will bet a very good lunch that
char(30) will be a complete dead loss on *every* measure: speed, disk
space, and convenience.

char(N) is not really fixed-width in Postgres, because N is measured
in characters not bytes (which are not the same thing if you use a
multibyte character encoding). Therefore, there are no optimizations
that could allow it to outperform varchar(N). When you consider the
extra cost of performing the padding step, the extra storage and I/O
incurred for all those pad blanks, and the client-side headaches of
having to trim the unwanted blanks again, it's just guaranteed to be
a loser.

The only case in which I could recommend char(N) is where you have
application semantics that constrain a field to exactly N characters
(postal codes are one common example). If the semantics are "at
most N characters", use varchar(N). If you are picking N out of the
air, don't bother: use text.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Kris <kkiger(at)depauw(dot)edu>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Speed & Memory Management
Date: 2003-04-01 21:42:11
Message-ID: Pine.LNX.4.44.0304012112490.2216-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Kris writes:

> My thought is that because I will likely have many
> updates/inserts/deletes occurring I should set each column that requires
> text to a static ammount (ie using char(30) instead of text).

That would buy you absolutely nothing. char() is not faster than text.
Instead you would make everything slower because the system would
constantly have to pad and trim your values and it would bloat the storage
with the extra spaces.

--
Peter Eisentraut peter_e(at)gmx(dot)net


From: Kris Kiger <kris(at)musicrebellion(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Need some info on an error
Date: 2004-02-02 21:05:47
Message-ID: 401EBBAB.2070704@musicrebellion.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

I added a column to a table of type boolean and then set its default to
false. Next, I ran an update on the table that was very similar to this
one:

update tablename SET bool_field_name = false;

This error is returned:

ERROR: unrecognized replace flag: 88

Has anyone seen this before?

Thanks for the input

Kris


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kris Kiger <kris(at)musicrebellion(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Need some info on an error
Date: 2004-02-03 03:01:44
Message-ID: 10565.1075777304@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Kris Kiger <kris(at)musicrebellion(dot)com> writes:
> I added a column to a table of type boolean and then set its default to
> false. Next, I ran an update on the table that was very similar to this
> one:

> update tablename SET bool_field_name = false;

> This error is returned:

> ERROR: unrecognized replace flag: 88

This sounds to me like you've uncovered a bug. What PG version is this?
Can you reproduce the error starting from an empty database, and if so how?

regards, tom lane