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 6756C53676 for ; Thu, 14 Apr 2005 12:08:33 -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 01753-03 for ; Thu, 14 Apr 2005 15:08:28 +0000 (GMT) Received: from localhost.net (cust.89.121.adsl.cistron.nl [195.64.89.121]) by svr1.postgresql.org (Postfix) with ESMTP id 04CE653F8D for ; Thu, 14 Apr 2005 12:08:27 -0300 (ADT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost.net (Postfix) with ESMTP id 0A40819B3C0; Thu, 14 Apr 2005 17:08:24 +0200 (CEST) Message-ID: <425E8766.8070901@trust-factory.com> Date: Thu, 14 Apr 2005 17:08:22 +0200 From: Richard van den Berg Organization: Trust Factory User-Agent: Debian Thunderbird 1.0 (X11/20050116) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Christopher Kings-Lynne Cc: pgsql-performance@postgresql.org Subject: Re: Foreign key slows down copy/insert References: <425E6045.4060201@trust-factory.com> <425E792B.4020500@familyhealth.com.au> <425E7D96.6020201@trust-factory.com> <425E7F94.4080602@familyhealth.com.au> In-Reply-To: <425E7F94.4080602@familyhealth.com.au> X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/286 X-Sequence-Number: 11683 Christopher Kings-Lynne wrote: >> But why then is the speed acceptable if I copy and then manually add >> the FK? Is the check done by the FK so much different from when it is >> done automatically using an active deffered FK? > > Yeah I think it uses a different query formulation... Actually I only > assume that deferred fk's don't use that - I guess your experiment > proves that. In my tests deferred or not deferred makes no difference in speed. I am still quite surprised by how huge the difference is.. this makes FKs quite unusable when added a lot of data to a table. > Actually, you can just "disable" them if you want to be really dirty :) Thanks for the pointer. I got this from the archives: ------------------------ update pg_class set reltriggers=0 where relname = 'YOUR_TABLE_NAME'; to enable them after you are done, do update pg_class set reltriggers = count(*) from pg_trigger where pg_class.oid=tgrelid and relname='YOUR_TABLE_NAME'; ------------------------ I assume the re-enabling will cause an error when the copy/insert added data that does not satisfy the FK. In that case I'll indeed end up with invalid data, but at least I will know about it. Thanks, -- Richard van den Berg, CISSP ------------------------------------------- Trust Factory B.V. | www.dna-portal.net Bazarstraat 44a | www.trust-factory.com 2518AK The Hague | Phone: +31 70 3620684 The Netherlands | Fax : +31 70 3603009 -------------------------------------------