簡體   English   中英

查詢需要優化還是只需要更高的最大連接數?

[英]Query need optimizing or do I just need higher max connections?

我有一個mysql數據庫。 我的網站上出現了很多max_user_connections錯誤,並且由於無法再增加幾天的限制,我想知道你們是否可以幫助我優化此查詢,該查詢需要1-4秒才能完成。 “狀態”表是具有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

感謝您的任何幫助。

您需要在usersstatus表之間提供正確的連接。 現在,您正在返回size(用戶表)* size(狀態表)行數。

根據您的評論,讓我假設您知道當前用戶的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM