Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 0DD351337B4E for ; Fri, 25 Mar 2011 03:44:44 -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 22286-05 for ; Fri, 25 Mar 2011 06:44:34 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout01.ims-firmen.de (mailout01.ims-firmen.de [213.174.32.96]) by mail.postgresql.org (Postfix) with ESMTP id 172C51337B43 for ; Fri, 25 Mar 2011 03:44:32 -0300 (ADT) Received: from [192.168.1.113] (helo=mi4) by mailout01.ims-firmen.de with esmtp (Exim 4.72) (envelope-from ) id 1Q30l3-0004fr-Hr for pgsql-performance@postgresql.org; Fri, 25 Mar 2011 07:44:29 +0100 Received: from [87.170.215.73] (helo=a-kretschmer.de) by mi4 with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1Q30l3-0006V2-Ah for pgsql-performance@postgresql.org; Fri, 25 Mar 2011 07:44:29 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1Q30l1-0004x9-Bd for pgsql-performance@postgresql.org; Fri, 25 Mar 2011 07:44:27 +0100 Date: Fri, 25 Mar 2011 07:44:27 +0100 From: Andreas Kretschmer To: pgsql-performance@postgresql.org Subject: Re: Why Index is not used Message-ID: <20110325064427.GA18517@tux> References: <4D8C37CA.3090601@orkash.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4D8C37CA.3090601@orkash.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) 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/319 X-Sequence-Number: 42998 Adarsh Sharma wrote: > Dear all, > > Today I got to run a query internally from my application by more than > 10 connections. > > But The query performed very badly. A the data size of tables are as : > > pdc_uima=# select pg_size_pretty(pg_total_relation_size('clause2')); > pg_size_pretty > ---------------- > 5858 MB > (1 row) > > pdc_uima=# select pg_size_pretty(pg_total_relation_size('svo2')); > pg_size_pretty > ---------------- > 4719 MB > (1 row) > > > I explain the query as after making the indexes as : > > pdc_uima=# explain select c.clause, s.* from clause2 c, svo2 s where > c.clause_id=s.clause_id and s.doc_id=c.source_id and c. > pdc_uima-# sentence_id=s.sentence_id ; > QUERY PLAN > > -------------------------------------------------------------------------------------------------------------- > 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) > > > > Indexes are : > > CREATE INDEX idx_clause ON clause2 USING btree (clause_id, source_id, > sentence_id); > CREATE INDEX idx_svo2 ON svo2 USING btree (clause_id, doc_id, > sentence_id); > > I don't know why it not uses the index scan for clause2 table. How many rows contains clause2? The planner expected 167324179 returning rows, can you run the same explain with ANALYSE to see the real amount of returning rows? Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°