Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id D60812E005A for ; Wed, 21 May 2008 05:02:44 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 15661-02 for ; Wed, 21 May 2008 05:02:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by developer.postgresql.org (Postfix) with ESMTP id C4F222E005D for ; Wed, 21 May 2008 05:00:52 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id D393C5C0CA for ; Wed, 21 May 2008 16:00:47 +0800 (WST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id B9A231E0436 for ; Wed, 21 May 2008 16:00:47 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 076RKmjlHHcR for ; Wed, 21 May 2008 16:00:46 +0800 (WST) Received: from [10.0.0.125] (dhcp-125.localnet [10.0.0.125]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTP id C345C1E0435 for ; Wed, 21 May 2008 16:00:46 +0800 (WST) Message-ID: <4833D6AE.6060809@postnewspapers.com.au> Date: Wed, 21 May 2008 16:00:46 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Cc: pgsql-performance@postgresql.org Subject: Re: Varchar pkey instead of integer References: <36af4bed0805202240v5fbdd6bcv75643a6488cd1daf@mail.gmail.com> <4833C285.5000603@postnewspapers.com.au> <4833D04E.8060403@Sheeky.Biz> In-Reply-To: <4833D04E.8060403@Sheeky.Biz> X-Enigmail-Version: 0.95.6 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.442 tagged_above=0 required=5 tests=AWL=-1.454, MISSING_HEADERS=1.581, SARE_MILLIONSOF=0.315 X-Spam-Level: X-Archive-Number: 200805/283 X-Sequence-Number: 30251 Shane Ambler wrote: > Size can affect performance as much as anything else. In your case of > limited rows it will make little difference, though the larger table > with millions of rows will have this key entered for each row and be > indexed as the foreign key. > > The real question is how you want to use the column, if you wish to > query for rows of a certain currency then you will notice the difference. > > You could use a smallint of 2 bytes each (or a varchar(1) with an int > value instead of a real char) or an integer of 4 bytes, compared to your > varchar(10) ... and if there are only a few records in the currency column, it rarely changes, and you put a trigger in place to prevent the re-use of previously assigned keys you may be able to cache that data in your application. That way you avoid a join or subquery on your lookup table to get the text description of the currency AND get the storage/performance of a small integer key. It's something I'm doing in other places in my current DB where I have essentially static lookup tables. You do have to watch out for lookup table changes, though. It's worth noting that my database is rather puny (the largest table has 500,000 records) and I'm very, very far from an expert on any of this, so there might be some hidden downside to doing things this way that I just haven't hit yet. -- Craig Ringer