MySQL Forums
Forum List  »  Optimizer & Parser

Re: Optimizing a UNION Query
Posted by: Toa Sty
Date: August 25, 2006 06:14AM

Hi Charles,

So it's still not running well, so let's try to simplify the problem a little.
Start by manually looking-up the termids for the words you're using and run the query without referencing the glossary tables.

So something like:

SELECT DISTINCT d1.docid FROM docref d1, docref d2, docIndex di
WHERE
AND d1.termid IN (1,2,3)
AND
d2.termid IN (4,5,6)
AND
d1.docid = di.docid AND d2.docid = di.docid;

but with your real termids, obviously ;)

(or, if you prefer INNER JOIN to , use something like:
SELECT DISTINCT d1.docid
FROM docref d1 INNER JOIN docIndex di USING (docid) INNER JOIN docref d2 USING (docid)
WHERE
AND d1.termid IN (1,2,3)
AND
d2.termid IN (4,5,6);
)


and see how fast that is.

My suspicion is that it'll execute in about the same amount time as with the glossary tables.


Try adding an multicol index on the docref table on: (termid, docid) This should make a big improvement I think

Other things - you probably know some of these but worth checking:

Run optimize/analyze on your tables to make sure index stats are up to date.
Make sure your key_buffer is large enough to fit your indexes in.


If the query is now running fast enough, add the glossary tables back in, and it should run at about the same (fast) speed.

If not, post explain plans for both and we'll see what to do next :)

HTH,
Toasty

Options: Reply• Quote


Subject
Views
Written By
Posted
6587
August 23, 2006 08:16PM
2851
August 24, 2006 04:59AM
2865
August 24, 2006 05:28AM
2915
August 24, 2006 12:12PM
Re: Optimizing a UNION Query
5630
August 25, 2006 06:14AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.