From: Justin Long <justinlong@strategicnetwork.org>
To: pgsql-sql@postgresql.org
Subject: Optimizing Query
Date: Mon, 05 Mar 2001 15:56:26 -0500
Message-ID: <5.0.2.1.0.20010305155556.00afb120@mail.strategicnetwork.org> (raw)
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.
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: justinlong@strategicnetwork.org
Subject: Re: Optimizing Query
In-Reply-To: <5.0.2.1.0.20010305155556.00afb120@mail.strategicnetwork.org>
References: <5.0.2.1.0.20010305155556.00afb120@mail.strategicnetwork.org>
* 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