Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 028872E0035 for ; Thu, 5 Jun 2008 10:25:02 -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 73771-06 for ; Thu, 5 Jun 2008 10:24:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail136010.authsmtp.co.uk (outmail136010.authsmtp.co.uk [62.13.136.10]) by developer.postgresql.org (Postfix) with ESMTP id 9EBCA2E0031 for ; Thu, 5 Jun 2008 10:24:54 -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 m55DOlku022094; Thu, 5 Jun 2008 14:24:47 +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 m55DOjs8075934; Thu, 5 Jun 2008 14:24:46 +0100 (BST) Subject: Re: pg_dump restore time and Foreign Keys From: Simon Riggs To: Heikki Linnakangas Cc: pgsql-hackers In-Reply-To: <4847E3A6.6000505@enterprisedb.com> References: <1212647003.19964.19.camel@ebony.site> <48479381.6020006@enterprisedb.com> <1212651938.19964.34.camel@ebony.site> <4847E3A6.6000505@enterprisedb.com> Content-Type: text/plain Date: Thu, 05 Jun 2008 14:27:50 +0100 Message-Id: <1212672470.19964.71.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: c4165c60-3302-11dd-aecc-001871e930f4 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaABbZ0xf HGQLW1xEUVl7W2d/ bwwfZQBDYEtPQQNv TkFLXVBXFgB3AVJc AxtqLUMxfwVBfXdz YQhgWHNcEhd+dEB4 EUhUCG4FZWV9aWFL 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/230 X-Sequence-Number: 119343 On Thu, 2008-06-05 at 16:01 +0300, Heikki Linnakangas wrote: > Simon Riggs wrote: > > On Thu, 2008-06-05 at 10:19 +0300, Heikki Linnakangas wrote: > >> Simon Riggs wrote: > >>> I'm guessing that the WITHOUT CHECK option would not be acceptable as an > >>> unprotected trap for our lazy and wicked users. :-) > >> Yes, that sounds scary. > >> > >> Instead, I'd suggest finding ways to speed up the ALTER TABLE ADD > >> FOREIGN KEY. > > > > I managed a suggestion for improving it for integers only, but if > > anybody has any other ideas, I'm all ears. > > Well, one idea would be to allow adding multiple foreign keys in one > command, and checking them all at once with one SQL query instead of one > per foreign key. Right now we need one seq scan over the table per > foreign key, by checking all references at once we would only need one > seq scan to check them all. No need. Just parallelise the restore with concurrent psql. Which would speed up the index creation also. Does Greg have plans for further work? > >> Or speeding up COPY into a table with foreign keys already > >> defined. For example, you might want to build an in-memory hash table of > >> the keys in the target table, instead of issuing a query on each INSERT, > >> if the target table isn't huge. > > > > No, that's not the problem, but I agree that is a problem also. > > It is related, because if we can make COPY into a table with foreign > keys fast enough, we could rearrange dumps so that foreign keys are > created before loading data. That would save the seqscan over the table > altogether. True. > Thinking about this idea a bit more, instead of loading the whole target > table into memory, it would probably make more sense to keep a hash > table as just a cache of the most recent keys that have been referenced. If you can think of a way of improving hash joins generally, then it will work for this specific case also. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support