Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 215241337B43 for ; Sun, 28 Nov 2010 15:03:22 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 30429-07 for ; Sun, 28 Nov 2010 19:03:14 +0000 (UTC) X-Greylist: delayed 00:06:38.649392 by SQLgrey-1.7.6 Received: from 64.mail-out.ovh.net (64.mail-out.ovh.net [91.121.185.65]) by mail.postgresql.org (Postfix) with SMTP id 3E46C1335B36 for ; Sun, 28 Nov 2010 15:03:14 -0400 (AST) Received: (qmail 30301 invoked by uid 503); 28 Nov 2010 18:42:10 -0000 Received: from b9.ovh.net (HELO mail32.ha.ovh.net) (213.186.33.59) by 64.mail-out.ovh.net with SMTP; 28 Nov 2010 18:42:09 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 28 Nov 2010 20:56:31 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 28 Nov 2010 20:56:30 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: pgsql-performance@postgresql.org, "Mario Splivalo" Subject: Re: SELECT INTO large FKyed table is slow References: <4CF24103.8030209@megafon.hr> Date: Sun, 28 Nov 2010 19:56:17 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: <4CF24103.8030209@megafon.hr> User-Agent: Opera Mail/10.62 (Linux) X-Ovh-Tracer-Id: 11951990461839771185 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201011/389 X-Sequence-Number: 41413 > When I remove foreign constraints (drones_history_fk__samples and > drones_history_fk__drones) (I leave the primary key on drones_history) > than that INSERT, even for 50k rows, takes no more than a second. > > So, my question is - is there anything I can do to make INSERTS with PK > faster? Or, since all the reference checking is done inside the > procedure for loading data, shall I abandon those constraints entirely? > > Mario Maybe... or not. Can you post details about : - the foreign keys - the tables that are referred to (including indexes) CREATE TABLE foo (x INTEGER PRIMARY KEY); INSERT INTO foo SELECT * FROM generate_series( 1,100000 ); Temps : 766,182 ms test=> VACUUM ANALYZE foo; Temps : 71,938 ms test=> CREATE TABLE bar ( x INTEGER REFERENCES foo(x) ); CREATE TABLE test=> INSERT INTO bar SELECT * FROM generate_series( 1,100000 ); Temps : 2834,430 ms As you can see, 100.000 FK checks take less than 3 seconds on this very simple example. There is probably something that needs fixing.