» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2007, 05:10 AM
Zoice Zoice is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Zoice is on a distinguished road
Default optimizing a structure?

Hello there,
I am trying to optimize a bad and outdated structure but my new big query takes a long time to run because the bnn_headlines has 7 million rows. Is there any way to optimize this query a bit more?

SELECT
`a`.`headline_id`,
`a`.`name`,
`a`.`title`,
`a`.`url`,
`a`.`text`,
`a`.`htimej`,
`b`.`sgid`
FROM
`news`.`bnn_headlines` AS `a`
INNER JOIN
`news`.`headline_category` AS `b`
ON
`a`.`headline_id` = `b`.`headline_id`
INNER JOIN
`news`.`categories_index` AS `c`
ON
`b`.`category_id` = `c`.`category_id`
WHERE
`c`.`cat_id` = '$cat_id'
AND
`a`.`htimej` > $time
ORDER BY
`a`.`htimej` DESC
LIMIT
0, $limit

Here's the structure of the 2 tables:

mysql> explain bnn_headlines;
+-------------+------------------+------+-----+---------+----------------+
-- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 02-16-2007, 08:52 AM
inder inder is offline
Senior Member
 
Join Date: Sep 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 17
inder is on a distinguished road
Default

In your select statement, there are three tables, but categories_index is only used to find category_id by cat_id. My advice for you is to try to do that in a separate step:
SELECT category_id
FROM news.categories_index
WHERE cat_id = '$cat_id'

and then simplify step two:

SELECT a.headline_id,a.name,a.title,a.url,
a.text, a.htimej, b.sgid
FROM news.bnn_headlines AS a
INNER JOIN news.headline_category AS b
ON a.headline_id = b.headline_id
WHERE b.category_id = '$category_id'
AND a.htimej > $time
ORDER BY a.htimej DESC
LIMIT 0, $limit

This will work if there is only one match in news.categories_index.
An index starting with headline_category.category_id would probably help. -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
optimizing table! JGavish MySQL Forums 1 02-21-2007 07:16 AM
table structure minster MySQL Forums 1 08-19-2006 03:12 PM


All times are GMT. The time now is 11:04 PM.