Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 98BEE2E0035 for ; Thu, 5 Jun 2008 10:36:28 -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 84268-06-2 for ; Thu, 5 Jun 2008 10:35:27 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail01.enterprisedb.com (mail01.enterprisedb.com [63.246.7.168]) by developer.postgresql.org (Postfix) with ESMTP id 5B4B22E0062 for ; Thu, 5 Jun 2008 10:35:23 -0300 (ADT) thread-index: AcjHERklR/l0swWlTOm5QPs96nEs5A== Received: from [192.168.1.105] ([82.181.212.226]) by mail01.enterprisedb.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 5 Jun 2008 09:36:02 -0400 Content-Class: urn:content-classes:message Importance: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 Message-ID: <4847EB8E.20600@enterprisedb.com> Date: Thu, 05 Jun 2008 16:35:10 +0300 From: "Heikki Linnakangas" Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.12 (X11/20080420) MIME-Version: 1.0 To: "Simon Riggs" Cc: "pgsql-hackers" , "Greg Stark" Subject: Re: pg_dump restore time and Foreign Keys References: <1212647003.19964.19.camel@ebony.site> <48479381.6020006@enterprisedb.com> <1212651938.19964.34.camel@ebony.site> <4847E3A6.6000505@enterprisedb.com> <1212672470.19964.71.camel@ebony.site> In-Reply-To: <1212672470.19964.71.camel@ebony.site> Content-Type: text/plain; format=flowed; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 05 Jun 2008 13:36:02.0671 (UTC) FILETIME=[18EE6FF0:01C8C711] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/231 X-Sequence-Number: 119344 Simon Riggs wrote: > On Thu, 2008-06-05 at 16:01 +0300, Heikki Linnakangas wrote: >> 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. True, you could do that. > Does Greg have plans for further work? I believe he's busy with other stuff at the moment. >> 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. Individual RI checks performed on inserts/COPY don't do a hash join. The bulk check done by ALTER TABLE ADD FOREIGN KEY does, but that's different issue. This hash table would be a specific trick to speed up RI checks. If you're anyway I/O bound, it wouldn't help, and you'd already be better off creating the foreign key first and loading the data after that. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com