From: tv@fuzzy.cz
To: Adarsh Sharma <adarsh.sharma@orkash.com>
Cc: Chetan Suttraway <chetan.suttraway@enterprisedb.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Why Index is not used
Date: Fri, 25 Mar 2011 10:30:13 +0100
Message-ID: <cb82fb23a38b24354e0acff7237a9ee1.squirrel@sq.gransy.com> (raw)
In-Reply-To: <4D8C3FAB.7070001@orkash.com>
References: <4D8C37CA.3090601@orkash.com>
<AANLkTinqGxRkVHuvcYLRtajrWhFWpDDjpTHuNV9_at9A@mail.gmail.com>
<4D8C3FAB.7070001@orkash.com>
>> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tv@fuzzy.cz, adarsh.sharma@orkash.com, chetan.suttraway@enterprisedb.com
Subject: Re: Why Index is not used
In-Reply-To: <cb82fb23a38b24354e0acff7237a9ee1.squirrel@sq.gransy.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox