首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MySQL查询优化[join]

MySQL查询优化[join]
EN

Stack Overflow用户
提问于 2012-12-07 21:37:47
回答 1查看 62关注 0票数 2

我有下一个问题

代码语言:javascript
运行
复制
SELECT 
i.*,
gu.*
vs.*
FROM 
common.global_users gu
LEFT JOIN common.global_users_perms gup ON (gu.global_user_id=gup.global_user_id)
LEFT JOIN p.individuals i ON (gup.parent_id = i.member_id)
LEFT JOIN p.vs ON (i.member_id=vs.member_id AND vs.status IN (1,4))
WHERE gup.region = 'us'
AND gu.user_type=2
AND ((gu.email='specific@email.com') OR (i.email='specific@email.com') OR (gu.username='specific@email.com'))
ORDER BY i.status, vs.member_id;

和下一步计划

代码语言:javascript
运行
复制
+----+-------------+-------+--------+------------------------------------------+------------------+---------+-----------------------------+--------+----------+---------------------------------+
| id | select_type | table | type   | possible_keys                            | key              | key_len | ref                         | rows   | filtered | Extra                           |
+----+-------------+-------+--------+------------------------------------------+------------------+---------+-----------------------------+--------+----------+---------------------------------+
|  1 | SIMPLE      | gu    | ref    | PRIMARY,username,idx_user_type,idx_email | idx_user_type    | 1       | const                       | 524243 |   100.00 | Using temporary; Using filesort |
|  1 | SIMPLE      | gup   | ref    | global_user_id_2                         | global_user_id_2 | 4       | common.gu.global_user_id    |      1 |   100.00 | Using where                     |
|  1 | SIMPLE      | i     | eq_ref | PRIMARY                                  | PRIMARY          | 4       | common.gup.parent_id        |      1 |   100.00 | Using where                     |
|  1 | SIMPLE      |  vs   | ref    | member_id,status                         | member_id        | 4       | p.i.member_id               |      1 |   100.00 |                                 |
+----+-------------+-------+--------+------------------------------------------+------------------+---------+-----------------------------+--------+----------+---------------------------------+

有没有可能让它更快一些?现在大概需要12秒

gu表中只有两个唯一的type值。并且该表中的所有recird数都大于1M。

EN

回答 1

Stack Overflow用户

发布于 2012-12-07 21:46:48

你的计划结果可能会指出这个问题‘使用临时的;使用文件排序’意味着排序是在磁盘上完成的,可能是因为它太大而无法放入内存。如果可能的话,你可能想增加你的内存限制。

这也可能与排序所依据的列有关。如果删除ORDER BY,查询的执行速度会更快吗?如果是这样的话,您可能需要查看ORDER BY Optimization

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13764215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档