Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VGXXV-000065-30 for pgsql-performance@arkaria.postgresql.org; Mon, 02 Sep 2013 17:03:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VGXXU-0003ut-JE for pgsql-performance@arkaria.postgresql.org; Mon, 02 Sep 2013 17:03:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VGXXT-0003ul-RI for pgsql-performance@postgresql.org; Mon, 02 Sep 2013 17:03:43 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VGXXM-00037n-JA for pgsql-performance@postgresql.org; Mon, 02 Sep 2013 17:03:43 +0000 Received: from mfilter18-d.gandi.net (mfilter18-d.gandi.net [217.70.178.146]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 85C9B1720A4; Mon, 2 Sep 2013 19:03:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter18-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter18-d.gandi.net (mfilter18-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id xhKIqdefwNWd; Mon, 2 Sep 2013 19:02:58 +0200 (CEST) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 304F31720B1; Mon, 2 Sep 2013 19:02:57 +0200 (CEST) Message-ID: <5224C4C0.2020702@dunslane.net> Date: Mon, 02 Sep 2013 13:02:56 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: =?ISO-8859-2?Q?=A3ukasz_Walkowski?= CC: Vitalii Tymchyshyn , "pgsql-performance@postgresql.org" Subject: Re: Varchar vs foreign key vs enumerator - table and index size References: <3AAC8AFE-E908-4AF7-ACDE-F9461B4A62D1@homplex.pl> <9F6FD605-91FC-4633-B393-75503463C7E7@homplex.pl> In-Reply-To: <9F6FD605-91FC-4633-B393-75503463C7E7@homplex.pl> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 09/02/2013 05:53 AM, =A3ukasz Walkowski wrote: > On 1 wrz 2013, at 05:10, Vitalii Tymchyshyn wrote: >> >> Well, there are some more options: >> a) Store int keys and do mapping in the application (e.g. with java enum= s). This can save you a join, that is especially useful if you are going to= do paged output with limit/offset scenario. Optimizer sometimes produce su= boptimal plans for join in offset/limit queries. >> b) Store small varchar values as keys (up to "char" type if you really w= ant to save space) and do user display mapping in application. It's differe= nt from (a) since it's harder to mess with the mapping and values are still= more or less readable with simple select. But it can be less efficient tha= n (a). >> c) Do mixed approach with mapping table, loaded on start into applicatio= n memory. This would be an optimization in case you get into optimizer trou= bles. >> >> Best regards, Vitalii Tymchyshyn > I'd like to leave database in readable form because before I add some new= queries and rest endpoints to the application, I test them as ad-hoc queri= es using command line. So variant a) isn't good for me. Variant b) is worth= trying and c) is easy to code, but I still prefer having all this data in = database independent of application logic. > I think the possible use of Postgres enums has been too easily written=20 off in this thread. Looking at the original problem description they=20 look like quite a good fit, despite the OP's skepticism. What exactly is=20 wanted that can't be done with database enums? You can add new values to=20 the type very simply. You can change the values of existing labels in=20 the type slightly less simply, but still without any great difficulty.=20 Things that are hard to do include removing labels in the set and=20 changing the sort order, because those things would require processing=20 tables where the type is used, unlike the simple things. But neither of=20 these is required for typical use cases. For most uses of this kind they=20 are very efficient both in storage and processing. cheers andrew --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance