Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 552082E0041 for ; Thu, 5 Jun 2008 09:53:48 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 42759-07 for ; Thu, 5 Jun 2008 09:53:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail128145.authsmtp.net (outmail128145.authsmtp.net [62.13.128.145]) by developer.postgresql.org (Postfix) with ESMTP id F3DEA2E0030 for ; Thu, 5 Jun 2008 09:53:37 -0300 (ADT) Received: from mail-c188.authsmtp.com (mail-c188.authsmtp.com [62.13.128.25]) by punt3.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m55CrWru006483; Thu, 5 Jun 2008 13:53:32 +0100 (BST) Received: from [192.168.0.3] (85-211-65-92.dyn.gotadsl.co.uk [85.211.65.92]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m55CrVMY058645; Thu, 5 Jun 2008 13:53:31 +0100 (BST) Subject: Re: pg_dump restore time and Foreign Keys From: Simon Riggs To: Andrew Dunstan Cc: pgsql-hackers In-Reply-To: <4847D4A7.70309@dunslane.net> References: <1212647003.19964.19.camel@ebony.site> <4847D4A7.70309@dunslane.net> Content-Type: text/plain Date: Thu, 05 Jun 2008 13:56:35 +0100 Message-Id: <1212670595.19964.55.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: 6687098e-32fe-11dd-aecc-001871e930f4 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaABbZ0xf HGQLW1xEUV57XGB/ aAsfZQBDYEtPQQNv TkFLXVBXFgB3AVJc AxttEH8PHgVDcHh0 YAhgXXhcEkJ8fUF9 S0YBCG4EMzJ9aWFL BF0JIlAHbQNKfxdC awV2V3NbZStlM3Bw LC8aFBMcBw5qYDxa dQ0QKEpaW0sQAjkm SlgeHDAiVUQDS20d KAYrK1EaVGUcI15a X-Authentic-SMTP: 61633235383639.cat.dmpriest.net.uk:1045/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/228 X-Sequence-Number: 119341 On Thu, 2008-06-05 at 07:57 -0400, Andrew Dunstan wrote: > > Simon Riggs wrote: > > pg_dump restore times can be high when they include many ALTER TABLE ADD > > FORIEGN KEY statements, since each statement checks the data to see if > > it is fully valid in all cases. > > > > I've been asked "why we run that at all?", since if we dumped the tables > > together, we already know they match. > > > > If we had a way of pg_dump passing on the information that the test > > already passes, we would be able to skip the checks. > > > > Proposal: > > > > * Introduce a new mode for ALTER TABLE ADD FOREIGN KEY [WITHOUT CHECK]; > > When we run WITHOUT CHECK, iff both the source and target table are > > newly created in this transaction, then we skip the check. If the check > > is skipped we mark the constraint as being unchecked, so we can tell > > later if this has been used. > > > > * Have pg_dump write the new syntax into its dumps, when both the source > > and target table are dumped in same run > > > > I'm guessing that the WITHOUT CHECK option would not be acceptable as an > > unprotected trap for our lazy and wicked users. :-) > > > > This whole proposal would be a major footgun which would definitely be > abused, IMNSHO. OK, understood. Two negatives is enough to sink it. > I think Heikki's idea of speeding up the check using a hash table of the > foreign keys possibly has merit. The query is sent through SPI, so if there was a way to speed this up, we would already be using it implicitly. If we find a way to speed up joins it will improve the FK check also. The typical join plan for the check query is already a hash join, assuming the target table is small enough. If not, its a huge sort/merge join. So in a way, we already follow the suggestion. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support