Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 0A629650044 for ; Sat, 5 Jul 2008 12:10:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 93520-04 for ; Sat, 5 Jul 2008 12:10:11 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by postgresql.org (Postfix) with ESMTP id 3FAB764FD34 for ; Sat, 5 Jul 2008 12:10:11 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.1/8.14.1) with ESMTP id m65FAAW8095069 for ; Sat, 5 Jul 2008 12:10:10 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.1/8.14.1/Submit) id m65F4swp090736 for pgsql-admin@postgresql.org; Sat, 5 Jul 2008 12:04:54 -0300 (ADT) (envelope-from news) Date: Sat, 05 Jul 2008 11:04:53 -0400 From: Lew User-Agent: Thunderbird 2.0.0.14 (X11/20080505) MIME-Version: 1.0 X-Newsgroups: pgsql.admin Subject: Re: performance cost for varchar(20), varchar(255), and text References: <801541.60585.qm@web56406.mail.re3.yahoo.com> In-Reply-To: <801541.60585.qm@web56406.mail.re3.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 36 X-Usenet-Provider: http://www.giganews.com X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 To: pgsql-admin@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/77 X-Sequence-Number: 29687 Jessica Richard wrote: > I am tuning a database created by someone else. > > I noticed that some column lengths were defined longer than needed. > > For example, an Id column is holding a stand length of 20 characters but > was defined as varchar(255). > > On some other columns, for example, a Description column is supposed to > hold less than 100 characters but defined as text. > > I am trying to understand the performance impact if a column is over > defined in the following cases: > > 1. char(20) vs varchar(20) > > 2. varchar(20) vs varchar(255) > > 3. varchar(255) vs text Interestingly, the Postgres documentation has the answer: > Tip: There are no performance differences between these three types, apart > from increased storage size when using the blank-padded type, and a few extra > cycles to check the length when storing into a length-constrained column. > While character(n) has performance advantages in some other database systems, > it has no such advantages in PostgreSQL. In most situations text or character > varying should be used instead. Performance is not the only issue. The semantics of CHAR and VARCHAR differ. You cannot use them equivalently. I recommend searching the docs as a first approach to finding such answers. -- Lew