Hi everyone!
I need to know if there's a best way to optimize this kind of DB model :
Here's my tables :
[category]
idCategory
name
[postCategory] (a post can be in more than 1 category)
idCategory
idPost
[post]
idPost
post
[comment]
idComment
idPost
inputDate
comment
I'm going to have to display all the posts, from a specific category, within a specific time range (the time is from "comments"). The time range is fixed (1 day, 1 week, 1 month, 1 year). Here's what I came with :
SELECT DISTINCT(post.idPost), post.post
from post
INNER JOIN comment ON post.idPost = comment.idPost
INNER JOIN postCategory ON postCategory.idPost = post.idPost
WHERE postCategory.idCategory = <myCategoryId>
AND comment.inputDate >= <today - time range>
Let say that I wish to support 10k posts and 500k comments... Is there a way to optimize this (besides using indexes)? Would you use a stored proc, a query with temp tables, add "precalculated" fields somewhere... ?
Thanks a lot! :)