【发布时间】:2014-02-28 01:35:03
【问题描述】:
我有以下复杂的查询,我注意到它使我的网站变得如此缓慢,我想找到一种优化它的方法:
SELECT tahminler.result,
tahminler.tahmin,
tahminler.match_id,
tahminler.timestamp,
tahminler.tahmin_text,
users.username,
matches_of_comments.tournament_id,
matches_of_comments.match_status,
matches_of_comments.match_date,
matches_of_comments.localteam_name,
matches_of_comments.visitorteam_name,
matches_of_comments.localteam_id,
matches_of_comments.visitorteam_id,
matches_of_comments.localteam_goals,
matches_of_comments.visitorteam_goals,
new_iddaa.iddaa_code,
tahminler_results.ms1,
tahminler_results.ms2,
tahminler_results.ms0,
tahminler_results.alt,
tahminler_results.ust,
tahminler_results.tg_0_1,
tahminler_results.tg_2_3,
tahminler_results.tg_4_6,
tahminler_results.tg_7,
tahminler_results.kg_var,
tahminler_results.kg_yok,
tahmins.tahmin as text_tahmin
FROM tahminler
INNER JOIN users on users.id = tahminler.user_id
INNER JOIN matches_of_comments on tahminler.match_id = matches_of_comments.match_id
Left JOIN new_iddaa on new_iddaa.match_id = matches_of_comments.match_id
INNER JOIN tahmins on tahminler.tahmin = tahmins.id
LEFT JOIN tahminler_results on tahminler.match_id = tahminler_results.match_id
Where tahminler.user_id = $user_id
order by tahminler.timestamp DESC
我在数据库或优化方面没有太多经验,所以我对这个查询做了一个解释,我得到了这个表:
我认为行中的问题告诉“使用连接缓冲区”,但这意味着什么? 你能帮我理解这一点并优化查询吗?
【问题讨论】:
-
Using join buffer: 来自早期连接的表被部分读入连接缓冲区,然后从缓冲区中使用它们的行来执行与当前表的连接。阅读Top 20 mysql best practices
-
以及如何在我的查询中做一个连接缓冲区?
-
@Damodaran,那篇“mysql 最佳实践”文章已经过时了,其中的一些建议即使在编写时也是错误的。
标签: mysql sql query-optimization