View Single Post
  #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
  Webmaster Forums - View Single Post - optimizing a structure?
View Single Post
  #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