Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 79AE59FC392 for ; Thu, 18 Oct 2007 17:05:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 77999-01-2 for ; Thu, 18 Oct 2007 17:05:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from cbio.mskcc.org (cbio.mskcc.org [140.163.254.35]) by postgresql.org (Postfix) with ESMTP id 99DD89FC379 for ; Thu, 18 Oct 2007 17:05:12 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by cbio.mskcc.org (Postfix) with ESMTP id 8096C61AB3; Thu, 18 Oct 2007 16:04:57 -0400 (EDT) Received: from cbio.mskcc.org ([127.0.0.1]) by localhost (cbio [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17556-06; Thu, 18 Oct 2007 16:04:57 -0400 (EDT) Received: from mrchips.local (mrchips.mskcc.org [172.21.218.242]) by cbio.mskcc.org (Postfix) with ESMTP id 6500861AB0; Thu, 18 Oct 2007 16:04:57 -0400 (EDT) Message-ID: <4717BC69.2010809@cbio.mskcc.org> Date: Thu, 18 Oct 2007 16:04:57 -0400 From: John Major User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Heikki Linnakangas CC: pgsql-performance@postgresql.org Subject: Re: How to improve speed of 3 table join &group (HUGE tables) References: <4717914D.1050704@cbio.mskcc.org> <4717AEA3.7030507@enterprisedb.com> In-Reply-To: <4717AEA3.7030507@enterprisedb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at cbio.mskcc.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.352 tagged_above=0 required=5 tests=AWL=0.351, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200710/223 X-Sequence-Number: 27245 Hi Hekki- When I turn seq_scan off for the new query: explain select sf.library_id, fio.clip_type , count(sf.sequence_id) from sequence_fragment sf, fragment_external_info fio where sf.seq_frag_id = fio.sequence_frag_id and sf.sequence_id IN (SELECT sequence_id from sequence_alignment) group by sf.library_id, fio.clip_type The index is used... but the cost gets worse! it goes from: 11831119 -TO- 53654888 Actually... The new query executes in ~ 15 minutes... which is good enough for me for now. Thanks Nis! john Heikki Linnakangas wrote: > John Major wrote: > >> ~there are indexes on all of the fields being joined (but not on >> library_id or clip_type ). ~Everything has been re-analyzed post index >> creation >> ~I've tried "set enable_seqscan=off" and set (join_table_order or >> something) = 1 >> > > Seqscanning and sorting a table is generally faster than a full scan of > the table using an index scan, unless the heap is roughly in the index > order. You probably need to CLUSTER the tables to use the indexes > effectively. > > Are you sure you have an index on sequence_alignment.sequence_id? The > planner seems to choose a seqscan + sort, even though you've set > enable_seqscan=false. > >