pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Justin Long <justinlong@strategicnetwork.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: Optimizing Query
Date: Mon, 5 Mar 2001 16:07:57 -0500 (EST)
Message-ID: <200103052107.QAA02196@candle.pha.pa.us> (raw)
In-Reply-To: <5.0.2.1.0.20010305155556.00afb120@mail.strategicnetwork.org>

Have you tried VACUUM ANALYZE and CLUSTER?


> Any suggestions welcome!
> 
> Here is my query:
> 
> select k.*, c.category from knowledge k, kb_categories c , kbwords w0 , 
> kbwords w1 WHERE k.catid=c.catid AND ((k.kbid=w0.kbid and w0.wordid=42743) 
> AND (k.kbid=w1.kbid and w1.wordid=85369)) ORDER BY k.kbid DESC LIMIT 25;
> 
> Now for the details
> knowledge k = 3,150 records
> kbwords = 2-field database (kbid, wordid), 825,748 records
> 
> Each word in the knowledge base is stored in a database called wordindex, 
> which has 50,000 records or so. The system first explodes the query string 
> and pulls the word #s from this database, which is where we get 42743 and 
> 85369 above, "ASIA" and "CHILDREN" respectively.) The idea is then to pull 
> all the articles in the knowledge base which contain both of these words.
> 
> Here is the EXPLAIN for the query:
> 
> NOTICE:  QUERY PLAN:
> 
> Nested Loop  (cost=0.00..527690060.67 rows=2878549 width=308)
>    ->  Nested Loop  (cost=0.00..9472443.40 rows=52582 width=304)
>          ->  Nested Loop  (cost=0.00..6278.63 rows=960 width=300)
>                ->  Index Scan Backward using knowledge_kbid_key on 
> knowledge k  (cost=0.00..1292.51 rows=2825 width=284)
>                ->  Seq Scan on kb_categories c  (cost=0.00..1.34 rows=34 
> width=16)
>          ->  Seq Scan on kbwords w0  (cost=0.00..9787.02 rows=5474 width=4)
>    ->  Seq Scan on kbwords w1  (cost=0.00..9787.02 rows=5474 width=4)
> 
> This takes quite a while to return results... prohibitively long. There are 
> indexes on k.catid, c.catid, k.kbid, w0.kbid, w0.wordid. Any suggestions 
> for further optimization would be very welcome. We get about 3,000 searches 
> on our database daily...
> 
> Blessings,
> Justin Long
> 
> 
> 
> ____________________________________________________________________
> Justin Long                                     Network for Strategic Missions
> justinlong@strategicnetwork.org 1732 South Park Court
> http://www.strategicnetwork.org Chesapeake, VA 23320, USA
> Reality Check e-zine: reality-check-subscribe@yahoogroups.com
> ____________________________________________________________________
> Law: Never retreat. Never surrender. Never cut a deal with a dragon.
> Corollary: No armor? Unclean life? Then do not mess in the affairs
> of dragons, for you are crunchy and taste good with ketchup.
> 
> 
> ____________________________________________________________________
> Justin Long                                     Network for Strategic Missions
> justinlong@strategicnetwork.org 1732 South Park Court
> http://www.strategicnetwork.org Chesapeake, VA 23320, USA
> Reality Check e-zine: reality-check-subscribe@yahoogroups.com
> ____________________________________________________________________
> Law: Never retreat. Never surrender. Never cut a deal with a dragon.
> Corollary: No armor? Unclean life? Then do not mess in the affairs
> of dragons, for you are crunchy and taste good with ketchup.


-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



view thread (12+ messages)  latest in thread

Message-ID: <200103052107.QAA02196@candle.pha.pa.us>
Permalink:  ../200103052107.QAA02196@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200103052107.QAA02196@candle.pha.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pgman@candle.pha.pa.us, justinlong@strategicnetwork.org
  Subject: Re: Optimizing Query
  In-Reply-To: <200103052107.QAA02196@candle.pha.pa.us>
  References: <5.0.2.1.0.20010305155556.00afb120@mail.strategicnetwork.org> <200103052107.QAA02196@candle.pha.pa.us>

* 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