X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 98509D1B1BE for ; Tue, 15 Jun 2004 21:58:28 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80794-04 for ; Wed, 16 Jun 2004 00:58:29 +0000 (GMT) Received: from fusion.bennyvision.com (fusion.bennyvision.com [216.161.119.28]) by svr1.postgresql.org (Postfix) with SMTP id BDC3DD1B1B4 for ; Tue, 15 Jun 2004 21:58:21 -0300 (ADT) Received: (qmail 6944 invoked from network); 16 Jun 2004 00:58:24 -0000 Received: from localhost (HELO webmail.stinkweasel.net) (127.0.0.1) by fusion.bennyvision.com with SMTP; 16 Jun 2004 00:58:24 -0000 Received: from 63.227.74.41 (SquirrelMail authenticated user benny) by webmail.stinkweasel.net with HTTP; Tue, 15 Jun 2004 19:58:02 -0500 (CDT) Message-ID: <51429.63.227.74.41.1087347504.squirrel@webmail.stinkweasel.net> Date: Tue, 15 Jun 2004 19:58:02 -0500 (CDT) Subject: VARCHAR -vs- CHAR: huge performance difference? From: "C. Bensend" To: pgsql-admin@postgresql.org User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=PRIORITY_NO_NAME X-Spam-Level: X-Archive-Number: 200406/187 X-Sequence-Number: 13847 Hey folks, I am working on a rather small, simple database. I'm running 7.3.5 on an OpenBSD 3.5-STABLE machine (1.3GHz, 512M RAM, IDE drive using UDMA-5). I am parsing and storing emails, so I have a lot of character string data to worry about. In one particular table, I have 26 columns of type varchar, with widths of 24-8192 characters. This is the table that is giving me some pretty severe performance problems. For example, many of the statistics I run against these emails is a simple count(), whether it be on a column or *. Right now, counting the rows takes in excess of 3.5 seconds. OK, that's pretty slow. However, there are only --> 24,000 <-- rows in this table! I could see it taking a long time if I had 500,000 rows, or a million, but 24,000? Now, I am not an expert with database design whatsoever, so I fully admit that having a table with 26 varchar columns (along with a handful of other fixed-width columns) probably isn't the brightest design. :) So, I went ahead and created an exact copy of this table, with the exception of creating all character columns as type char(), not varchar(). I was pondering if making PostgreSQL worry about the varying lengths by using varchar was the problem... And sure enough, counting the rows on the new table takes around 148ms. That's a pretty big difference from 3600ms. And no, 3.6 seconds doesn't sound like much, until you have several operations on the same table to draw a single web page, and suddenly the page takes 20s to load. :( So, my question for the gurus: is using varchars THAT detrimental? Or am I just going way way overboard by having so _many_ in a single table? Or am I an idiot? (honest question - I'm armpit-deep in learning mode here) I'm also curious to know if I've crossed some invisible line with the number of columns/width of rows that makes performance degrade rapidly. If further info is needed, please ask - I just didn't want to spam the list with further table definitions and explain analyze output if it wasn't needed. Benny -- "Oh, the Jedis are going to feel this one!" -- Professor Farnsworth, "Futurama"