Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DFAB81337B6D for ; Tue, 30 Nov 2010 19:50:40 -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 02678-01 for ; Tue, 30 Nov 2010 23:50:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.catalyst.net.nz (bertrand.catalyst.net.nz [202.78.240.40]) by mail.postgresql.org (Postfix) with ESMTP id 9E1B81336971 for ; Tue, 30 Nov 2010 19:50:33 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 0C5C3320C7 for ; Wed, 1 Dec 2010 12:50:31 +1300 (NZDT) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5S0eBRdibbGC for ; Wed, 1 Dec 2010 12:50:30 +1300 (NZDT) Received: from [IPv6:2404:130:0:1000:222:15ff:fe5c:2471] (unknown [IPv6:2404:130:0:1000:222:15ff:fe5c:2471]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 63C9931E8F for ; Wed, 1 Dec 2010 12:50:30 +1300 (NZDT) Message-ID: <4CF58DC5.5040101@catalyst.net.nz> Date: Wed, 01 Dec 2010 12:50:29 +1300 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Lightning/1.0b1 Thunderbird/3.0.10 MIME-Version: 1.0 To: 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> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/421 X-Sequence-Number: 41445 On 30/11/10 05:53, Pierre C wrote: > >> 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. Exactly, sorry - I was having a brain fade moment about which way your foreign key checks were going when I suggested adding those indexes... :-(