MySQL服务器5.6
innodb_buffer_pool_size = 6GB
key_buffer_size = 20M
这是我的架构:
TBL_1 TBL_2 TBL_3 TBL_4 TBL_5 TBL_6
id id id id id id (int, primary key, auto increment)
uid uid uid uid uid uid (varchar 100, key index)
dev dev dev dev dev dev (varchar 80)
intf intf intf intf intf intf (varchar 100)
stat1 stat2 stat3 stat4 stat5 stat6 (float, 11)
uid字段提供跨表行的唯一关系。 所有表中的count(*)是~52K
我希望的观点:
VIEW_1
dev intf stat1 stat2 stat3 stat4 stat5 stat6
这是我迄今为止尝试过的视图选择sql的一个例子:
select a.dev, a.intf, a.stat1, b.stat2, c.stat3, d.stat4, e.stat_5, f.stat_6
from TBL_1 a
inner join TBL_2 b on b.uid = a.uid
inner join TBL_3 c on c.uid = a.uid
inner join TBL_4 d on d.uid = a.uid
inner join TBL_5 e on e.uid = a.uid
inner join TBL_6 f on f.uid = a.uid
一旦我超过2个连接,查询就会变得无法响应。对于上面的查询说明return
|| *id* || *select_type* || *table* || *type* || *possible_keys* || *key* || *key_len* || *ref* || *rows* || *Extra* ||
|| 1 || SIMPLE || e || ALL || uid || || || || 51391 || ||
|| 1 || SIMPLE || c || ref || uid || uid || 102 || db.e.uid || 1 || Using index condition ||
|| 1 || SIMPLE || a || ref || uid || uid || 102 || db.c.uid || 1 || ||
|| 1 || SIMPLE || b || ref || uid || uid || 257 || db.c.uid || 1 || Using index condition ||
|| 1 || SIMPLE || f || ref || uid || uid || 257 || db.c.uid || 1 || Using index condition ||
|| 1 || SIMPLE || d || ref || uid || uid || 102 || db.e.uid || 1 || Using index condition ||
有关如何改进的建议吗?
答案 0 :(得分:0)
检查查询的解释计划
EXPLAIN SELECT * from ABC;
选中此Understanding the Query Execution Plan
根据解释输出,请考虑添加indexes
或使用其他Optimizing techniques
如果这无法帮助您解释您的解释计划,请继续关注。
干杯!!