Bluehost.com Web Hosting $6.95

Optimize this!

This is a discussion on Optimize this! within the MySQL Database forums, part of the Database Forums category; Please help me optimize this: I have a table with columns: headlineid, keyword. headlineid+keyword combination is unique. Relationship between ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-19-2006
rajeshkapadi@gmail.com
 
Posts: n/a
Default Optimize this!

Please help me optimize this:

I have a table with columns: headlineid, keyword.
headlineid+keyword combination is unique.

Relationship between headline and keyword is many-to-many. i.e.,
headlines can have many keywords. keywords can be associated with many
headlines.

Keywords in the same headline are considered "related".

Here's the query to find out which keywords 'hello' is related to and
sort desc on number of occurrences of the related keywords:

select keyword, count(keyword) as keywordcount from tags where
headlineid in (select distinct(headlineid) from tags where keyword =
'hello') AND keyword <> 'hello' group by keyword order by keywordcount
desc limit 0, 5;

This query takes a lot of time. Need help with optimization. All help
is appreciated.

Reply With Quote
  #2 (permalink)  
Old 12-19-2006
Captain Paralytic
 
Posts: n/a
Default Re: Optimize this!


rajeshkapadi@gmail.com wrote:
> Please help me optimize this:
>
> I have a table with columns: headlineid, keyword.
> headlineid+keyword combination is unique.
>
> Relationship between headline and keyword is many-to-many. i.e.,
> headlines can have many keywords. keywords can be associated with many
> headlines.
>
> Keywords in the same headline are considered "related".
>
> Here's the query to find out which keywords 'hello' is related to and
> sort desc on number of occurrences of the related keywords:
>
> select keyword, count(keyword) as keywordcount from tags where
> headlineid in (select distinct(headlineid) from tags where keyword =
> 'hello') AND keyword <> 'hello' group by keyword order by keywordcount
> desc limit 0, 5;
>
> This query takes a lot of time. Need help with optimization. All help
> is appreciated.

Try turning it into a join (example below), this usually helps speed up
this sort of thing.
Also build 2 indexes, one beginning with keyword the other beginning
with headlineid.

SELECT t2.keyword, count( t2.keyword ) AS keywordcount
FROM tags t1
JOIN tags t2 ON t1.headlineid = t2.headlineid AND t2.keyword <> 'hello'
WHERE t1.keyword = 'hello'
GROUP BY keyword
ORDER BY keywordcount DESC
LIMIT 0 , 5;

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:04 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0