简体   繁体   English

查询需要优化还是只需要更高的最大连接数?

[英]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. 您需要在usersstatus表之间提供正确的连接。 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.

相关问题 匹配表列时是否需要在Wordpress中运行准备好的查询? - Do I need to run a prepared query in Wordpress when I'm just matching table columns? 需要帮助优化复杂的MySQL查询 - Need Help optimizing a complex MySQL query 需要帮助优化wordpress meta_query - need help optimizing wordpress meta_query 我是否需要php-fpm来提供MongoDB持久连接 - Do I need php-fpm to serve MongoDB persistent connections PHPMotion - 如果我只上传 in.flv,是否需要 ffmpeg 等? - PHPMotion - Do I need ffmpeg etc if I just upload in .flv? 每个查询都需要准备好的语句吗? - Do I need prepared statement on each query? 如果我需要检查 max strlen 是否只是包含逗号和点的字符串中的数字,我需要 laravel 验证的哪个条件 - Which condition i need for laravel validation if i need to check max strlen just for numbers from a string which contains comma and dot 套接字连接只需要一个线程吗? - Do socket connections only need one thread? 如果需要,我需要添加其他查询以限制用户输入的数量大于库存的数量 - if else query that I need to add to restrict users from inputting quantities higher than the stock 我该怎么办才能摆脱“最大用户连接数”错误? - What do I need to do to get rid of “maximum user connections” error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM