Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5517E1335B36 for ; Mon, 29 Nov 2010 12:53:30 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 44378-06 for ; Mon, 29 Nov 2010 16:53:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 69.mail-out.ovh.net (69.mail-out.ovh.net [91.121.185.62]) by mail.postgresql.org (Postfix) with SMTP id 93B811337B54 for ; Mon, 29 Nov 2010 12:53:22 -0400 (AST) Received: (qmail 26306 invoked by uid 503); 29 Nov 2010 15:59:27 -0000 Received: from 64.mail-out.ovh.net (91.121.185.65) by 69.mail-out.ovh.net with SMTP; 29 Nov 2010 15:59:27 -0000 Received: (qmail 21061 invoked by uid 503); 29 Nov 2010 16:38:53 -0000 Received: from b9.ovh.net (HELO mail32.ha.ovh.net) (213.186.33.59) by 64.mail-out.ovh.net with SMTP; 29 Nov 2010 16:38:53 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 29 Nov 2010 18:53:21 +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; 29 Nov 2010 18:53:20 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: mark.kirkwood@catalyst.net.nz, "Mario Splivalo" Cc: pgsql-performance@postgresql.org Subject: Re: SELECT INTO large FKyed table is slow References: <4CF24103.8030209@megafon.hr> <4CF3522B.2050203@catalyst.net.nz> <4CF39CF4.2050506@megafon.hr> Date: Mon, 29 Nov 2010 17:53:19 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: <4CF39CF4.2050506@megafon.hr> User-Agent: Opera Mail/10.62 (Linux) X-Ovh-Tracer-Id: 15744302823055623924 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-Ovh-Tracer-Id: 14834575699304973873 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201011/403 X-Sequence-Number: 41427 > Yes, since (sample_id, drone_id) is primary key, postgres created > composite index on those columns. Are you suggesting I add two more > indexes, one for drone_id and one for sample_id? (sample_id,drone_id) covers sample_id but if you make searches on drone_id alone it is likely to be very slow since you got a large number of sample_ids. Postgres can use any column of a multicolumn index but it is only interesting performance-wise if the cardinality of the first (ignored) columns is low. If you often make searches on drone_id, create an index. But this isn't what is slowing your foreign key checks. >> Also it would be worthwhile for you to post the output of: >> >> EXPLAIN ANALYZE INSERT INTO drones_history (sample_id, drone_id, >> drone_log_notice, drone_temperature, drone_pressure) >> SELECT * FROM tmpUpdate; >> >> to the list, so we can see what is taking the time. > > Is there a way to do so inside plpgsql function? > > I can recreate the whole process within psql and then post the explain > analyze, it would just take me some time to do so. I'll post as soon as > I'm done. Yes, this would be interesting.