[英]Query need optimizing or do I just need higher max connections?
I have a mysql database. 我有一个mysql数据库。 My site has been getting a lot of max_user_connections errors, and since I can't increase the limit for a few more days, I was wondering if you guys could help me optimize this query that's taking between 1 and 4 seconds to complete. 我的网站上出现了很多max_user_connections错误,并且由于无法再增加几天的限制,我想知道你们是否可以帮助我优化此查询,该查询需要1-4秒才能完成。 The 'status' table is InnoDB with 230,221 rows, and there are indexes already on it, but is it just a poorly written query? “状态”表是具有230,221行的InnoDB,并且上面已经有索引,但这只是写得不好的查询吗?
SELECT status.id,users.id
FROM users, status
WHERE clan='someClan'
AND status.author!='loggedInUser'
AND status.anonymous!='someUser'
AND users.username='someUser'
AND status.data!=''
AND status.postdate > users.news_read
GROUP BY postdate LIMIT 2
Thank you for any help. 感谢您的任何帮助。
You need to provide the proper connection between the users
and the status
table. 您需要在users
和status
表之间提供正确的连接。 Right now you are returning size(users table) * size(status table) number of rows. 现在,您正在返回size(用户表)* size(状态表)行数。
From your comments, let me assume that you know the current user's users.id. 根据您的评论,让我假设您知道当前用户的users.id。
SELECT status.id
FROM status
WHERE status.clan='someClan' \\ assuming clan is in status table
AND status.author!='someUser'
AND status.anonymous!='someUser'
AND status.data!=''
AND status.postdate > (Select users.news_read
from users
where users.username='someUser'
)
GROUP BY postdate LIMIT 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.