![](/img/trans.png)
[英]Do I need to run a prepared query in Wordpress when I'm just matching table columns?
[英]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
感謝您的任何幫助。
您需要在users
和status
表之間提供正確的連接。 現在,您正在返回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.