Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DC96664FF6F for ; Mon, 11 Aug 2008 06:30:39 -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 79146-06 for ; Mon, 11 Aug 2008 06:30:31 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from oxford.xeocode.com (unknown [82.16.16.210]) by postgresql.org (Postfix) with ESMTP id F1F1664FEDD for ; Mon, 11 Aug 2008 06:30:34 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.69) (envelope-from ) id 1KSTjT-0001Ax-K0; Mon, 11 Aug 2008 10:30:31 +0100 To: "Jay" Cc: Subject: Re: Using PK value as a String In-Reply-To: <9e3be050-8b96-45d9-9bf3-b333bdee0405@i24g2000prf.googlegroups.com> (Jay's message of "Mon\, 11 Aug 2008 00\:34\:36 -0700 \(PDT\)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.performance" 6461) References: <9e3be050-8b96-45d9-9bf3-b333bdee0405@i24g2000prf.googlegroups.com> From: Gregory Stark Organization: EnterpriseDB Date: Mon, 11 Aug 2008 10:30:31 +0100 Message-ID: <874p5ruceg.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.1 tagged_above=0 required=5 tests=RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200808/99 X-Sequence-Number: 30980 "Jay" writes: > I have a table named table_Users: > > CREATE TABLE table_Users ( > UserID character(40) NOT NULL default '', > Username varchar(256) NOT NULL default '', > Email varchar(256) NOT NULL default '' > etc... > ); > > The UserID is a character(40) and is generated using UUID function. We > started making making other tables and ended up not really using > UserID, but instead using Username as the unique identifier for the > other tables. Now, we pass and insert the Username to for discussions, > wikis, etc, for all the modules we have developed. I was wondering if > it would be a performance improvement to use the 40 Character UserID > instead of Username when querying the other tables, or if we should > change the UserID to a serial value and use that to query the other > tables. Or just keep the way things are because it doesn't really make > much a difference. Username would not be any slower than UserID unless you have a lot of usernames longer than 40 characters. However making UserID an integer would be quite a bit more efficient. It would take 4 bytes instead of as the length of the Username which adds up when it's in all your other tables... Also internationalized text collations are quite a bit more expensive than a simple integer comparison. But the real question here is what's the better design. If you use Username you'll be cursing if you ever want to provide a facility to allow people to change their usernames. You may not want such a facility now but one day... -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's On-Demand Production Tuning