Well I have a videos website and a few of its tables are:
tags
id ~ int(11), auto-increment [PRIMARY KEY]
tag_name ~ varchar(255)
videotags
tag_id ~ int(11) [PRIMARY KEY]
video_id ~ int(11) [PRIMARY KEY]
videos
id ~ int(11), auto-increment [PRIMARY KEY]
video_name ~ varchar(255)
Now at this point the tags table has >1000 rows and the videotags table has >32000 rows. So when I run a query to display all tags from most common to least common it takes >15 seconds to execute.
I am using PHP and my code (watered down for simplicity) is as follows:
foreach ($database->query("SELECT tag_name,COUNT(tag_id) AS 'tag_count' FROM tags LEFT OUTER JOIN videotags ON tags.id=videotags.tag_id GROUP BY tags.id ORDER BY tag_count DESC") as $tags)
{
echo $tags["tag_name"] . ', ';
}
Now keeping in mind that this being 100% accurate isn't as important to me as it being fast. So even if the query was executed once a day and its results were used for the remainder of the day, I wouldn't care.
I know absolutely nothing about MySQL/PHP caching so please help!