Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C7FEA1337B6E for ; Fri, 25 Mar 2011 06:30:25 -0300 (ADT) 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 65155-01 for ; Fri, 25 Mar 2011 09:30:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from elizabeth.gransy.com (elizabeth.gransy.com [89.187.132.199]) by mail.postgresql.org (Postfix) with ESMTP id 4183813364DE for ; Fri, 25 Mar 2011 06:30:14 -0300 (ADT) Received: from sq.gransy.com (localhost [127.0.0.1]) by elizabeth.gransy.com (Postfix) with ESMTP id DE34015E4123; Fri, 25 Mar 2011 10:30:13 +0100 (CET) Received: from 85.162.49.88 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Fri, 25 Mar 2011 10:30:13 +0100 Message-ID: In-Reply-To: <4D8C3FAB.7070001@orkash.com> References: <4D8C37CA.3090601@orkash.com> <4D8C3FAB.7070001@orkash.com> Date: Fri, 25 Mar 2011 10:30:13 +0100 Subject: Re: Why Index is not used From: tv@fuzzy.cz To: "Adarsh Sharma" Cc: "Chetan Suttraway" , pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal 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 X-Spam-Level: X-Archive-Number: 201103/328 X-Sequence-Number: 43007 >> Merge Join (cost=5673831.05..34033959.87 rows=167324179 width=2053) >> Merge Cond: ((s.clause_id = c.clause_id) AND (s.doc_id = >> c.source_id) AND (s.sentence_id = c.sentence_id)) >> -> Index Scan using idx_svo2 on svo2 s (cost=0.00..24489343.65 >> rows=27471560 width=1993) >> -> Materialize (cost=5673828.74..6071992.29 rows=31853084 >> width=72) >> -> Sort (cost=5673828.74..5753461.45 rows=31853084 >> width=72) >> Sort Key: c.clause_id, c.source_id, c.sentence_id >> -> Seq Scan on clause2 c (cost=0.00..770951.84 >> rows=31853084 width=72) >> > > As per the size consideration and the number of rows, I think index scan > on clause2 is better. I really doubt that - using index usually involves a lot of random I/O and that makes slow with a lot of rows. And that's exactly this case, as there are 27471560 rows in the first table. You can force the planner to use different plan by disabling merge join, just set set enable_mergejoin = false and see what happens. There are other similar options: http://www.postgresql.org/docs/8.4/static/runtime-config-query.html And yet another option - you can try to mangle with the cost constants, namely seq_page_cost and random_page_cost. Decreasing random_page_cost (default is 4) makes index scans cheaper, so it's more likely the planner will choose them. Tomas