Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 9966A64FCE8 for ; Mon, 11 Aug 2008 13:04:06 -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 74608-10 for ; Mon, 11 Aug 2008 13:04:02 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay-2.mail.nethere.net (relay-2.mail.nethere.net [66.63.128.162]) by postgresql.org (Postfix) with ESMTP id C80A164FCC0 for ; Mon, 11 Aug 2008 13:04:02 -0300 (ADT) Received: from scan-1.mail.nethere.net (scan-1.mail.nethere.net [66.63.128.132]) by relay-2.mail.nethere.net (Postfix) with ESMTP id 0506212B26F; Mon, 11 Aug 2008 09:04:01 -0700 (PDT) Received: from mta-1.mail.nethere.net by scan-1.mail.nethere.net with LMTP id ruwH5KSC8crf; Mon, 11 Aug 2008 09:04:00 -0700 (PDT) Received: from lisa-james-computer.local (wsip-68-224-174-233.sd.sd.cox.net [68.224.174.233]) by mta-1.mail.nethere.net (Postfix) with ESMTP id C0B74F1829; Mon, 11 Aug 2008 09:04:00 -0700 (PDT) Message-ID: <48A062EE.5050408@emolecules.com> Date: Mon, 11 Aug 2008 09:03:58 -0700 From: Craig James User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) MIME-Version: 1.0 To: valiouk@yahoo.co.uk CC: Jay , pgsql-performance@postgresql.org Subject: Re: Using PK value as a String References: <18986.60888.qm@web25807.mail.ukl.yahoo.com> In-Reply-To: <18986.60888.qm@web25807.mail.ukl.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/112 X-Sequence-Number: 30993 Valentin Bogdanov wrote: > --- On Mon, 11/8/08, Gregory Stark wrote: > >> From: Gregory Stark >> Subject: Re: [PERFORM] Using PK value as a String >> To: "Jay" >> Cc: pgsql-performance@postgresql.org >> Date: Monday, 11 August, 2008, 10:30 AM >> "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... >>> ); >>> ... >> 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... >> > > I don't understand Gregory's suggestion about the design. I thought > using natural primary keys as opposed to surrogate ones is a better > design strategy, even when it comes to performance considerations > and even more so if there are complex relationships within the database. No, exactly the opposite. Data about users (such as name, email address, etc.) are rarely a good choice as a foreign key, and shouldn't be considered "keys" in most circumstances. As Gregory points out, you're spreading the user's name across the database, effectively denormalizing it. Instead, you should have a user record, with an arbitrary key, an integer or OID, that you use as the foreign key for all other tables. That way, when the username changes, only one table will be affected. And it's much more efficient to use an integer as the key than a long string. Craig