pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shaun Thomas <sthomas@peak6.com>
To: Chetan Suttraway <chetan.suttraway@enterprisedb.com>
Cc: Adarsh Sharma <adarsh.sharma@orkash.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Why Index is not used
Date: Fri, 25 Mar 2011 08:24:55 -0500
Message-ID: <4D8C97A7.8030403@peak6.com> (raw)
In-Reply-To: <AANLkTimoW2Gfe+mNQQ9bmCkJ772AoB+vBd9iWai=SdRh@mail.gmail.com>
References: <4D8C37CA.3090601@orkash.com>
	<AANLkTinqGxRkVHuvcYLRtajrWhFWpDDjpTHuNV9_at9A@mail.gmail.com>
	<4D8C3FAB.7070001@orkash.com>
	<AANLkTin7m2cjph=ijKXWZR8_EwKq9Zg1C5Sh73SqRqWX@mail.gmail.com>
	<4D8C5881.4090806@orkash.com>
	<AANLkTimoW2Gfe+mNQQ9bmCkJ772AoB+vBd9iWai=SdRh@mail.gmail.com>

On 03/25/2011 04:07 AM, Chetan Suttraway wrote:

> The ideas is to have maximum filtering occuring on leading column of index.
> the first plan with only the predicates on clause_id is returning
> 379772050555842 rows whereas
> in the second plan with doc_id predicates is returning only 20954686217.
>
> So maybe you should consider re-ordering of the index on clause2.

That won't really help him. He's joining a 27M row table against a 31M 
row table with basically no WHERE clause. We can see that because he's 
getting 30M rows back in the EXPLAIN ANALYZE. At that point, it doesn't 
really matter which table gets index scanned. This query will *always* 
take several minutes to execute.

It would be completely different if he only wanted to get the results 
for *one* source. Or *one* sentence. But getting all of them ever stored 
will just take forever.

> I am sorry but I am not able to got your points completely.

He just means that indexes work better if they're placed in order of 
selectivity. In your case, it seems sentence_id restricts the result set 
better than clause_id. So Chetan suggested remaking your indexes to be 
this instead:

CREATE INDEX idx_clause ON clause2
  USING btree (sentence_id, clause_id, source_id);

CREATE INDEX idx_svo2 ON svo2
  USING btree (sentence_id, clause_id, doc_id);

This *might* help. But your fundamental problem is that you're joining 
two giant tables with no clause to limit the result set. If you were 
only getting back 10,000 rows, or even a million rows, your query could 
execute in a fraction of the time. But joining every row in both tables 
and returning a 30-million row result set isn't going to be fun for 
anyone. Are you actually processing all 30-million rows you get back? 
Storing them somewhere?

-- 
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@peak6.com

______________________________________________

See  http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email



view thread (14+ messages)  latest in thread

Message-ID: <4D8C97A7.8030403@peak6.com>
Permalink:  ../4D8C97A7.8030403@peak6.com/
Also on:    postgresql.org/message-id/4D8C97A7.8030403@peak6.com

 · 

reply

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: sthomas@peak6.com, chetan.suttraway@enterprisedb.com, adarsh.sharma@orkash.com
  Subject: Re: Why Index is not used
  In-Reply-To: <4D8C97A7.8030403@peak6.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