Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 9F612633868 for ; Wed, 8 Apr 2009 14:09:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 83759-10 for ; Wed, 8 Apr 2009 14:09:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from megafon.hr (megafon.hr [213.202.104.5]) by mail.postgresql.org (Postfix) with ESMTP id A78166337EE for ; Wed, 8 Apr 2009 14:09:05 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by megafon.hr (Postfix) with ESMTP id CFF7325009C for ; Wed, 8 Apr 2009 19:09:02 +0200 (CEST) X-Virus-Scanned: ClamAV at megafon.hr Received: from megafon.hr ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5PRSv2Y+PgGJ for ; Wed, 8 Apr 2009 19:08:54 +0200 (CEST) Received: from [192.168.1.94] (unknown [212.92.194.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: mike) by megafon.hr (Postfix) with ESMTP id 6DCED25009B for ; Wed, 8 Apr 2009 19:08:54 +0200 (CEST) Message-ID: <49DCDA27.4090901@megafon.hr> Date: Wed, 08 Apr 2009 19:08:55 +0200 From: Mario Splivalo User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: ENUM vs DOMAIN vs FKyed loookup table Content-Type: text/plain; charset=UTF-8; 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: 200904/44 X-Sequence-Number: 32390 When you need to choose between enum types, domain types or lookup tables with foreign keys, what do you usualy choose? Only recently I started using domains, but that seems to be painful, as Joshua Drake explains here: http://www.commandprompt.com/blogs/joshua_drake/2009/01/fk_check_enum_or_domain_that_is_the_question/ For instance, I have an application that tracks codes. I have table that looks like this: CREATE TABLE codes ( code_id integer, code_value integer, code_type enum_code_type ) CREATE TYPE enum_code_type AS ENUM ('Unapproved', 'ApprovedByEmail', 'ApprovedByAdmin'); Now, let's say I have around 5.000.000 codes in my table. If I want to add new code type, i'm in deep pain. I can't do ALTER TYPE to change enum definition, I need to do hocus-pocus to achieve what I want. If I used domain, I can do ALTER DOMAIN DROP CONSTRAINT, ALTER DOMAIN ADD... Takes a bit of time, but it is more flexible than ENUMs. Joshua made some benchmarking of the enum/domain types, and it turns out that domain type is slowest one. I'll be posting some of my benchmarks soon. I abandoned the lookup tables because of the JOINining. What are your practices, when do you use ENUMs and when Domains? Mike