X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F36B8D7015; Sat, 10 Sep 2005 00:49:17 -0300 (ADT) 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 51903-03; Sat, 10 Sep 2005 03:49:14 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 470CAD6F3C; Sat, 10 Sep 2005 00:49:13 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j8A3n8it039580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 9 Sep 2005 21:49:11 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j8A3n76R040482; Fri, 9 Sep 2005 21:49:07 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j8A3n7lc040481; Fri, 9 Sep 2005 21:49:07 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 9 Sep 2005 21:49:07 -0600 From: Michael Fuhr To: "Marc G. Fournier" Cc: pgsql-performance@postgresql.org Subject: Re: CHECK vs REFERENCES Message-ID: <20050910034907.GA40382@winnie.fuhr.org> References: <20050910001821.E1170@ganymede.hub.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050910001821.E1170@ganymede.hub.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.109 required=5 tests=[AWL=-0.098, UPPERCASE_25_50=0.207] X-Spam-Level: X-Archive-Number: 200509/120 X-Sequence-Number: 14428 On Sat, Sep 10, 2005 at 12:23:19AM -0300, Marc G. Fournier wrote: > Which is faster, where the list involved is fixed? My thought is that > since it doesn't have to check a seperate table, the CHECK itself should > be the faster of the two, but I can't find anything that seems to validate > that theory ... Why not just benchmark each method as you intend to use them? Here's a simplistic example: CREATE TABLE test_none ( val integer NOT NULL ); CREATE TABLE test_check ( val integer NOT NULL CHECK (val IN (1, 2, 3, 4, 5)) ); CREATE TABLE test_vals ( id integer PRIMARY KEY ); INSERT INTO test_vals SELECT * FROM generate_series(1, 5); CREATE TABLE test_fk ( val integer NOT NULL REFERENCES test_vals ); \timing INSERT INTO test_none SELECT 1 FROM generate_series(1, 100000); INSERT 0 100000 Time: 3109.089 ms INSERT INTO test_check SELECT 1 FROM generate_series(1, 100000); INSERT 0 100000 Time: 3492.344 ms INSERT INTO test_fk SELECT 1 FROM generate_series(1, 100000); INSERT 0 100000 Time: 23578.853 ms -- Michael Fuhr