MySQL Forums
Forum List  »  Optimizer & Parser

Re: Executing same query in 1 moment
Posted by: Brano Gerzo
Date: November 20, 2011 10:31PM

Thanks for answer Rick.

The queries are statistic queries, so it is normal, they executes longer. Here are some examples:

SELECT SQL_CACHE COUNT(UserID) as cnt, UserID, UserNickName, max(a.SubAddDate) as Latest, max(IDSubtitle) as IDSubtitle
FROM search_cache a
WHERE UserID > 0
AND SubLanguageID in ('eng', 'pol')
AND SubEnabled = 1
AND DATE_SUB(CURDATE(),INTERVAL 1 month) <= SubAddDate
GROUP BY UserID
ORDER BY cnt DESC
LIMIT 5

I got few queries like this, I got indexes right, everything should be ok. This query takes around 5 seconds, which is not so bad. Problem is when I got 20 users in the same time and wants results for this query. I can see mysql is executing 20 times this query (query cache doesnt help here in this case), so my db box is loaded.

Anyway, I was thinking to avoid situations like this in a way:, I am caching results in memcache...

- check the memcache, if it is going to expire soon or id doesnt exists, make a lock in memcache, so other query will not go to mysql, execute this query in sql, cache it into memcache, release the lock.

I think this should work.

Options: ReplyQuote


Subject
Views
Written By
Posted
2427
November 19, 2011 09:27AM
1087
November 20, 2011 04:42PM
Re: Executing same query in 1 moment
1119
November 20, 2011 10:31PM
997
November 22, 2011 12:05AM
1083
November 21, 2011 12:42AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.