X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 191C73A3AEE for ; Tue, 23 Nov 2004 01:05:34 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49732-03 for ; Tue, 23 Nov 2004 01:05:29 +0000 (GMT) Received: from tht.net (vista.tht.net [216.126.88.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5B4263A3B0E for ; Tue, 23 Nov 2004 01:05:31 +0000 (GMT) Received: from dyn-70-236.tor.dsl.tht.net (dyn-70-236.tor.dsl.tht.net [134.22.70.236]) by tht.net (Postfix) with ESMTP id DC6EE76AB7; Mon, 22 Nov 2004 20:05:35 -0500 (EST) Subject: Re: Data type to use for primary key From: Rod Taylor To: josh@agliodbs.com Cc: Postgresql Performance , Alexandre Leclerc In-Reply-To: <200411221654.56673.josh@agliodbs.com> References: <1dc7f0e30411221232603c4617@mail.gmail.com> <200411221654.56673.josh@agliodbs.com> Content-Type: text/plain Date: Mon, 22 Nov 2004 20:03:11 -0500 Message-Id: <1101171791.44437.7.camel@home> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/344 X-Sequence-Number: 9298 On Mon, 2004-11-22 at 16:54 -0800, Josh Berkus wrote: > Alexandre, > > > What is the common approach? Should I use directly the product_code as > > my ID, or use a sequantial number for speed? (I did the same for the > > company_id, this is a 'serial' and not the shor name of the customer. > > I just don't know what is usually done. > > Don't use SERIAL just because it's there. Ideally, you *want* to use the > product_code if you can. It's your natural key and a natural key is always > superior to a surrogate key all other things being equal. It would be nice if PostgreSQL had some form of transparent surrogate keying in the background which would automatically run around and replace your real data with SERIAL integers. It could use a lookup table for conversions between the surrogate and real values so the user never knows that it's done, a bit like ENUM. Then we could all use the real values with no performance issues for 1) because it's an integer in the background, and 2) because a cascade only touches a single tuple in the lookup table. --