Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id B10212E0056 for ; Thu, 5 Jun 2008 08:58:59 -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 88387-06 for ; Thu, 5 Jun 2008 08:58:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from alexis.jtlnet.com (alexis.jtlnet.com [69.36.9.81]) by developer.postgresql.org (Postfix) with ESMTP id 62FC82E004C for ; Thu, 5 Jun 2008 08:58:56 -0300 (ADT) Received: from [192.168.10.103] (cpe-075-177-177-228.nc.res.rr.com [::ffff:75.177.177.228]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by alexis.jtlnet.com with esmtp; Thu, 05 Jun 2008 07:57:58 -0400 id 00097B57.4847D4C6.00003A7C Message-ID: <4847D4A7.70309@dunslane.net> Date: Thu, 05 Jun 2008 07:57:27 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.0.12) Gecko/20071019 Fedora/1.0.9-3.fc6 pango-text SeaMonkey/1.0.9 MIME-Version: 1.0 To: Simon Riggs CC: pgsql-hackers Subject: Re: pg_dump restore time and Foreign Keys References: <1212647003.19964.19.camel@ebony.site> In-Reply-To: <1212647003.19964.19.camel@ebony.site> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/226 X-Sequence-Number: 119339 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. I think Heikki's idea of speeding up the check using a hash table of the foreign keys possibly has merit. cheers andrew